From nobody Fri Apr 10 12:34:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 964D1C32774 for ; Tue, 23 Aug 2022 07:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241268AbiHWHuk (ORCPT ); Tue, 23 Aug 2022 03:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241305AbiHWHuX (ORCPT ); Tue, 23 Aug 2022 03:50:23 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A824C6556A for ; Tue, 23 Aug 2022 00:50:20 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VN0jApx_1661241015; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VN0jApx_1661241015) by smtp.aliyun-inc.com; Tue, 23 Aug 2022 15:50:16 +0800 From: Baolin Wang To: akpm@linux-foundation.org, songmuchun@bytedance.com, mike.kravetz@oracle.com Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] mm/hugetlb: use PMD page lock to protect CONT-PTE entries Date: Tue, 23 Aug 2022 15:50:04 +0800 Message-Id: <88c8a8c68d87429f0fc48e81100f19b71f6e664f.1661240170.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Considering the pmd entries of a CONT-PMD hugetlb can not span on multiple PMDs, we can change to use the PMD page lock, which can be much finer grain that lock in the mm. Signed-off-by: Baolin Wang --- include/linux/hugetlb.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 3a96f67..d4803a89 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -892,9 +892,17 @@ static inline gfp_t htlb_modify_alloc_mask(struct hsta= te *h, gfp_t gfp_mask) static inline spinlock_t *huge_pte_lockptr(struct hstate *h, struct mm_struct *mm, pte_t *pte) { - VM_BUG_ON(huge_page_size(h) =3D=3D PAGE_SIZE); + unsigned long hp_size =3D huge_page_size(h); =20 - if (huge_page_size(h) =3D=3D PMD_SIZE) { + VM_BUG_ON(hp_size =3D=3D PAGE_SIZE); + + /* + * Considering CONT-PMD size hugetlb, since the CONT-PMD entry + * can not span multiple PMDs, then we can use the fine grained + * PMD page lock. + */ + if (hp_size =3D=3D PMD_SIZE || + (hp_size > PMD_SIZE && hp_size < PUD_SIZE)) { return pmd_lockptr(mm, (pmd_t *) pte); } else if (huge_page_size(h) < PMD_SIZE) { unsigned long mask =3D ~(PTRS_PER_PTE * sizeof(pte_t) - 1); --=20 1.8.3.1