Message ID | 20231219075538.414708-4-peterx@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1778375dyi; Mon, 18 Dec 2023 23:57:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMXJXVGFNhgdy1hssLbzJx5mrrzMwQu/NqAGLlFqOiNv29wzSvzxj2Oef8w2BKkFbJZdM9 X-Received: by 2002:a05:6870:4215:b0:203:f926:5b6c with SMTP id u21-20020a056870421500b00203f9265b6cmr25008oac.39.1702972625104; Mon, 18 Dec 2023 23:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702972625; cv=none; d=google.com; s=arc-20160816; b=xhtTxgXJRdfYRQ/ApryUXIPstkeCni6clvvJHtdQG+ceC6lJPKU1qzM/q5511GI+ZN 1X3yHuquGgJcfb9p2mgQAwKZ9P+uyhoYd3qQr5110v90yXd5le84l888qbgsOzjYvaUp 9KNj3qCsJWd83/1t8N3+uiEfF77VHH0FfPPjDGETb4QGTIgqa7t6LVB98dNyLQuhi7tR jZS7pVLEHh88ydP6fivlzzraLgiKE38mvCCDQ73yMVkiD6kpcDKyKOrWMytn618fHUC/ 3v/9lQyJEnOYn6gPPNSuZdF8iWa0D+aR5B/qbX22itN+Rpdk5E2KNbWc6trwPeI2QQSt pqsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VdhTUt+FrTuSBSRKmaD9aOddOtS2xHAJn3bdMelwyoI=; fh=3mpu6Yyr5hMzDKtkQvzcApl7ZSQGU4G8QyIY2BAU7VY=; b=CxzMSZ8UjDuoj2X7DrLm3nNYlc+0ekoShjA+RT+AJhhSYYZD7TowbLZb31v9khyWUd Wpk0d6GhLXhwrtooWwA84MP+SLZYdsdV3vGL+cK+q4NedIEZoWchREcdXVBqvRz5khnw MOavzL9UyUfFErViaJryULbL4KK1B1xia3UWLzXuVaWA0QY/aqOEf4M7txouuvwBVZET lkqobcjmhVmvO1155FZYDVgxi3si/g3iutp39GcIPE0HN5fQwyauIhVrpjRQWT8KO7U/ Qu9FgvMJWBOD+BjE/90rVmVRLKrwyXsDUOjtDxRmoclCQhz4kmnI7d0krVDdQ7dyfdqc pQDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S5RPX8rj; spf=pass (google.com: domain of linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id v4-20020a63f204000000b005cd813c23besi5490597pgh.415.2023.12.18.23.57.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 23:57:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S5RPX8rj; spf=pass (google.com: domain of linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4836-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BBC9AB240A6 for <ouuuleilei@gmail.com>; Tue, 19 Dec 2023 07:57:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0998914F78; Tue, 19 Dec 2023 07:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S5RPX8rj" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86A7C14A87 for <linux-kernel@vger.kernel.org>; Tue, 19 Dec 2023 07:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VdhTUt+FrTuSBSRKmaD9aOddOtS2xHAJn3bdMelwyoI=; b=S5RPX8rjfwaWxduNP4ARumN1dF0Mc6P09VrcIRPJjancgkznbPEiRTsoawzYM77AqpIJtt iWo9fhCmrEbF/tqpDWhxN8SphxsgnjPZSE4vvLGjbP6kwpp3tuyAiQcRPyrzq8fAU3onrC 8MLmu0WS3xik1xWOaimbrrtWtcTaV0A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-zvB374S3NdqDENm7NImiSg-1; Tue, 19 Dec 2023 02:56:29 -0500 X-MC-Unique: zvB374S3NdqDENm7NImiSg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 298F1185A782; Tue, 19 Dec 2023 07:56:28 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B65A2026D6F; Tue, 19 Dec 2023 07:56:17 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox <willy@infradead.org>, Christophe Leroy <christophe.leroy@csgroup.eu>, Lorenzo Stoakes <lstoakes@gmail.com>, David Hildenbrand <david@redhat.com>, Vlastimil Babka <vbabka@suse.cz>, Mike Kravetz <mike.kravetz@oracle.com>, Mike Rapoport <rppt@kernel.org>, Christoph Hellwig <hch@infradead.org>, John Hubbard <jhubbard@nvidia.com>, Andrew Jones <andrew.jones@linux.dev>, linux-arm-kernel@lists.infradead.org, Michael Ellerman <mpe@ellerman.id.au>, "Kirill A . Shutemov" <kirill@shutemov.name>, linuxppc-dev@lists.ozlabs.org, Rik van Riel <riel@surriel.com>, linux-riscv@lists.infradead.org, Yang Shi <shy828301@gmail.com>, James Houghton <jthoughton@google.com>, "Aneesh Kumar K . V" <aneesh.kumar@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Jason Gunthorpe <jgg@nvidia.com>, Andrea Arcangeli <aarcange@redhat.com>, peterx@redhat.com, Axel Rasmussen <axelrasmussen@google.com> Subject: [PATCH 03/13] mm: Provide generic pmd_thp_or_huge() Date: Tue, 19 Dec 2023 15:55:28 +0800 Message-ID: <20231219075538.414708-4-peterx@redhat.com> In-Reply-To: <20231219075538.414708-1-peterx@redhat.com> References: <20231219075538.414708-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785696223615684149 X-GMAIL-MSGID: 1785696223615684149 |
Series |
mm/gup: Unify hugetlb, part 2
|
|
Commit Message
Peter Xu
Dec. 19, 2023, 7:55 a.m. UTC
From: Peter Xu <peterx@redhat.com> ARM defines pmd_thp_or_huge(), detecting either a THP or a huge PMD. It can be a helpful helper if we want to merge more THP and hugetlb code paths. Make it a generic default implementation, only exist when CONFIG_MMU. Arch can overwrite it by defining its own version. For example, ARM's pgtable-2level.h defines it to always return false. Keep the macro declared with all config, it should be optimized to a false anyway if !THP && !HUGETLB. Signed-off-by: Peter Xu <peterx@redhat.com> --- include/linux/pgtable.h | 4 ++++ mm/gup.c | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-)
Comments
On 2023/12/19 15:55, peterx@redhat.com wrote: > From: Peter Xu <peterx@redhat.com> > > ARM defines pmd_thp_or_huge(), detecting either a THP or a huge PMD. It > can be a helpful helper if we want to merge more THP and hugetlb code > paths. Make it a generic default implementation, only exist when > CONFIG_MMU. Arch can overwrite it by defining its own version. > > For example, ARM's pgtable-2level.h defines it to always return false. > > Keep the macro declared with all config, it should be optimized to a false > anyway if !THP && !HUGETLB. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > include/linux/pgtable.h | 4 ++++ > mm/gup.c | 3 +-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index af7639c3b0a3..6f2fa1977b8a 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -1355,6 +1355,10 @@ static inline int pmd_write(pmd_t pmd) > #endif /* pmd_write */ > #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > +#ifndef pmd_thp_or_huge I think it may be the time to rename to pmd_thp_or_hugetlb, the "huge" is really confusing. thp is not huge? Actually, it is huge. It is better to make it more specific from now on, like "hugetlb". BTW, please cc me via the new email (muchun.song@linux.dev) next edition. Thanks. > +#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) > +#endif > + > #ifndef pud_write > static inline int pud_write(pud_t pud) > { > diff --git a/mm/gup.c b/mm/gup.c > index 0a5f0e91bfec..efc9847e58fb 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -3004,8 +3004,7 @@ static int gup_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, unsigned lo > if (!pmd_present(pmd)) > return 0; > > - if (unlikely(pmd_trans_huge(pmd) || pmd_huge(pmd) || > - pmd_devmap(pmd))) { > + if (unlikely(pmd_thp_or_huge(pmd) || pmd_devmap(pmd))) { > /* See gup_pte_range() */ > if (pmd_protnone(pmd)) > return 0;
On Mon, Dec 25, 2023 at 02:29:53PM +0800, Muchun Song wrote: > > @@ -1355,6 +1355,10 @@ static inline int pmd_write(pmd_t pmd) > > #endif /* pmd_write */ > > #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > +#ifndef pmd_thp_or_huge > > I think it may be the time to rename to pmd_thp_or_hugetlb, > the "huge" is really confusing. thp is not huge? Actually, > it is huge. It is better to make it more specific from now on, like > "hugetlb". The rename will need to touch ARM code, which I wanted to avoid, see: arch/arm64/include/asm/pgtable.h:#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) So far this series only touches generic code. Would you mind I keep this patch as-is, and leave renaming to later? > > BTW, please cc me via the new email (muchun.song@linux.dev) next edition. Sure. Thanks for taking a look.
> On Jan 2, 2024, at 13:37, Peter Xu <peterx@redhat.com> wrote: > > On Mon, Dec 25, 2023 at 02:29:53PM +0800, Muchun Song wrote: >>> @@ -1355,6 +1355,10 @@ static inline int pmd_write(pmd_t pmd) >>> #endif /* pmd_write */ >>> #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ >>> +#ifndef pmd_thp_or_huge >> >> I think it may be the time to rename to pmd_thp_or_hugetlb, >> the "huge" is really confusing. thp is not huge? Actually, >> it is huge. It is better to make it more specific from now on, like >> "hugetlb". > > The rename will need to touch ARM code, which I wanted to avoid, see: I see. > > arch/arm64/include/asm/pgtable.h:#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) > > So far this series only touches generic code. Would you mind I keep this > patch as-is, and leave renaming to later? OK. THanks. > >> >> BTW, please cc me via the new email (muchun.song@linux.dev) next edition. > > Sure. Thanks for taking a look. > > -- > Peter Xu >
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index af7639c3b0a3..6f2fa1977b8a 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1355,6 +1355,10 @@ static inline int pmd_write(pmd_t pmd) #endif /* pmd_write */ #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +#ifndef pmd_thp_or_huge +#define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) +#endif + #ifndef pud_write static inline int pud_write(pud_t pud) { diff --git a/mm/gup.c b/mm/gup.c index 0a5f0e91bfec..efc9847e58fb 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3004,8 +3004,7 @@ static int gup_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, unsigned lo if (!pmd_present(pmd)) return 0; - if (unlikely(pmd_trans_huge(pmd) || pmd_huge(pmd) || - pmd_devmap(pmd))) { + if (unlikely(pmd_thp_or_huge(pmd) || pmd_devmap(pmd))) { /* See gup_pte_range() */ if (pmd_protnone(pmd)) return 0;