From patchwork Tue Aug 23 07:50:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 12951828 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68573C32789 for ; Tue, 23 Aug 2022 07:50:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5856B6B0075; Tue, 23 Aug 2022 03:50:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 510D16B007B; Tue, 23 Aug 2022 03:50:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D5E68D0001; Tue, 23 Aug 2022 03:50:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2C37A6B0075 for ; Tue, 23 Aug 2022 03:50:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 06E6A1414CB for ; Tue, 23 Aug 2022 07:50:20 +0000 (UTC) X-FDA: 79830084600.18.E9D76DC Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by imf30.hostedemail.com (Postfix) with ESMTP id 4BC0180030 for ; Tue, 23 Aug 2022 07:50:18 +0000 (UTC) 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=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VN0jAoy_1661241014; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VN0jAoy_1661241014) by smtp.aliyun-inc.com; Tue, 23 Aug 2022 15:50:14 +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 2/5] mm/hugetlb: use PTE page lock to protect CONT-PTE entries Date: Tue, 23 Aug 2022 15:50:02 +0800 Message-Id: <064489292e6e224ef4406af990c7cdc3c054ca77.1661240170.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.45 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661241019; a=rsa-sha256; cv=none; b=yFstALDXBPou89VhRQcDhT3lekd1IWFr4u8spFc/0fNsTd9C5yjvK+3pgvawEF6+kWfqqN 2lrdJg+BTNJUD3CZddxoZrjWLD+YkjRVw0mLGL/ZKtzAKJK3amKi7AmJu7kbQTyktnP7GH BSkfZR6Igua9CJnteuCmloUrzhVcLGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661241019; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to:in-reply-to: references:references:references; bh=Vxq4jQjTVRmCFHX+ypx5+Q7BgjT32/Ki4HshQDYrp+U=; b=JEVkOEI5utphwiWUG1spOsbVW9yA5D7BSLB9x2i0hyu2UacSJvn/j8K+j8jl2OLxawGkL8 6Je+guVB1BujefBs6bw4oGCwB49XzHV8oAp+gU1rVSjFKnYIAxnMaQLZOF6EERuq03lBcL XGKEaZJ17+6l+OmMZxAEsZrvYliJouM= X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.45 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com X-Stat-Signature: dwk6csw5p3xxq9o8qzfz7n1wrm87ogoa X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4BC0180030 X-HE-Tag: 1661241018-103372 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Considering the pte entries of a CONT-PTE hugetlb can not span on multiple PTEs, we can change to use the PTE page lock, which can be much finer grain that lock in the mm. Signed-off-by: Baolin Wang --- include/linux/hugetlb.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index d491138..4b172a7 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -892,9 +892,23 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) static inline spinlock_t *huge_pte_lockptr(struct hstate *h, struct mm_struct *mm, pte_t *pte) { - if (huge_page_size(h) == PMD_SIZE) - return pmd_lockptr(mm, (pmd_t *) pte); VM_BUG_ON(huge_page_size(h) == PAGE_SIZE); + + if (huge_page_size(h) == PMD_SIZE) { + return pmd_lockptr(mm, (pmd_t *) pte); + } else if (huge_page_size(h) < PMD_SIZE) { + unsigned long mask = ~(PTRS_PER_PTE * sizeof(pte_t) - 1); + struct page *page = + virt_to_page((void *)((unsigned long)pte & mask)); + + /* + * Considering CONT-PTE size hugetlb, since the CONT-PTE + * entry can not span multiple PTEs, we can use the PTE + * page lock to get a fine grained lock. + */ + return ptlock_ptr(page); + } + return &mm->page_table_lock; }