From patchwork Wed Jan 3 09:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13509766 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 C514CC3DA6E for ; Wed, 3 Jan 2024 09:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E6A08D0051; Wed, 3 Jan 2024 04:15:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 594788D0035; Wed, 3 Jan 2024 04:15:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 435A48D0051; Wed, 3 Jan 2024 04:15:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2FB868D0035 for ; Wed, 3 Jan 2024 04:15:26 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F2A7CC01FB for ; Wed, 3 Jan 2024 09:15:25 +0000 (UTC) X-FDA: 81637441410.29.820B279 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 6034EC001A for ; Wed, 3 Jan 2024 09:15:24 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N1v0LuzP; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704273324; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fpxdFtXHPoqbi8Omg7z7HSYBdI7g84IQc8JywSZrzBY=; b=qy1OMBUUWW3gJm0kwymhgad+L+xbmVi5B4R9H6wY5NJ9gOGYXnLLJ0ncssHOJj6rr8mgzT VG3OCJofstbGcHQPysQtNdJN9iTf1Z06DbNCtYiig2OmxOdelYRbmCNjfYYyBJ5rTq2dQB +/gQmcZRBJYggLyGy3blkXgbnhBhfRk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704273324; a=rsa-sha256; cv=none; b=TPaH75M80nz1t5d+oWr+zkWMi+JtSGZ5GABluTJThQSFPvVx4V9Q6sJur5VYpGTYUR7enT Q946XfQrcsaWztOvp+3lNEYAfrTHQJzd7Q3mBGfoZrrk+l467GGgbt1K1aGItYt82bZZh9 BTGQGl39063McwdcsRSw2RckWBxt3CU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N1v0LuzP; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704273323; 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=fpxdFtXHPoqbi8Omg7z7HSYBdI7g84IQc8JywSZrzBY=; b=N1v0LuzPWpZJQS9PRXFJt/gRgyCdvzHYQwMU+H14wgftC6TD6Uwu3uVsJday7pGAFAG9uv /E/Yb47EcIZHr0giKXH3XnvhmblFwSIdFKmtifwSJjjXg99mc7GK/8YmOoYLsOEtWE7WOC Mmp70dG7DaJMgbYeOjtMKI6kXfbot7w= 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-479-b9n2pak4N8WkCJuJM8p50w-1; Wed, 03 Jan 2024 04:15:17 -0500 X-MC-Unique: b9n2pak4N8WkCJuJM8p50w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 806BE85A588; Wed, 3 Jan 2024 09:15:16 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08899492BE6; Wed, 3 Jan 2024 09:15:04 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , peterx@redhat.com, linux-riscv@lists.infradead.org, Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Christophe Leroy , Andrew Jones , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song , linux-arm-kernel@lists.infradead.org, Jason Gunthorpe , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox Subject: [PATCH v2 03/13] mm: Provide generic pmd_thp_or_huge() Date: Wed, 3 Jan 2024 17:14:13 +0800 Message-ID: <20240103091423.400294-4-peterx@redhat.com> In-Reply-To: <20240103091423.400294-1-peterx@redhat.com> References: <20240103091423.400294-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: 6034EC001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yhsoje4wq6qamegdu1g1b6tfubzmk4sf X-HE-Tag: 1704273324-167318 X-HE-Meta: U2FsdGVkX1/8+RzbVVvnxRYGjX3A3Cme6rrtAECNMOWiGd6+w605iO/IennzxIL/Ui4gpdZFKCLMOhnooaMjHCe9hHxbNZBXg1ausie/+CnvHA+tVWHZZic34DuRSlNI7kk3krbsVvw0yPCwuTFpa17MfRwV7Paxs2k4QPbKfGprZzpxdNjcPU1f2chc8jdXscWFWmG2qkgvgMqndkp/vEs6zW9+8lYWykm0lF4V8+R61bR9crkxUXJ+wmejvTPQVvgDy4ikye0QZHZQV0XxQc57dpgny7eThHGNK+XnswBzXRLAQ/9bZVrrjY9j2KKfHVOVQJdmXupn3QD/fmHCEWjVlsdOStpKKI57nWjvquM99wKR1S0EIO6FCGw5v19ah0xTVal/9j618Ilg20SmjwQ6ujADHcPGsm1gsii6kP97os/k4XAtEiUVQ269cr1PdVIO6BGVOVOL+baZgtOzZTi/0olcih1QbjDjScCYmorkBGgipQiLPh5Zu6gXuJiuCluALpyeYkDNptS83q1FNhKr0TX2r1RFsF0F0n8NFezmI2BGr8uk1A2GPmXNLdf0otQImdyO/F/0DJEa8iEQbDBPENgKXKuSKoAm3TxgsabU5VSzwKV2KqsjWOf0hNrxdu/kr+Ugn0HyaJ8+Mr4OE0yxFcBtGqAF0wULQJkyeIhs9W3+fwV3ZqaAPfDbH0r4usMtLuSurvVtiDCXkdrndpHNqqf9rj7DtVdBNtvW7u7e3Qk6x0gYfWE2oUHu37sT/8U+QmJx47RFGGVY9PEc/t9VT55eFfrA1TB3mHvu7w2mZyWoAAGwHEBgMsxgxHm/FS9YpyyzVdWonIWSSgbe1f1n82pIdDtiyL00pkavCA2857Phx7vzB+CDWROt2eEG5s+nJUzUxgROkGvTJIV/BZBXz6qy0oYd0g/wzesXENzWqrTwJnEDVL/2OpEQXIgb7JxJc6gtIZKEeQwtY4i gsmJOz+a BmaL8fvp8CKsSIUQlE0Tr9pWCkD6QznetTAUHHuJoN3l3XSyr6Q23pzvsq/TKuqsv0ASnOQXLCyTzR9jhDCzOlg8Ug+ODGNwfW0rmvuBWWSVtHFuFy/Vl+OMl6mn1EJxTZzkWKxo+zbX/Z+3MY+InEreft+H/foHz5kNrjOUo9KsCYrH8Ju0WfqavsoG7PwQGn+ryCFfn3QbbiS04yZFiX9KP6A== 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: List-Subscribe: List-Unsubscribe: From: Peter Xu 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 --- 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 466cf477551a..2b42e95a4e3a 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1362,6 +1362,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 df83182ec72d..eebae70d2465 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;