From patchwork Thu Nov 16 01:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13457477 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 0D74EC072A2 for ; Thu, 16 Nov 2023 01:29:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502826B03DF; Wed, 15 Nov 2023 20:29:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48B106B03E1; Wed, 15 Nov 2023 20:29:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DDBB6B03E2; Wed, 15 Nov 2023 20:29:20 -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 18E0D6B03DF for ; Wed, 15 Nov 2023 20:29:20 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EE530A0482 for ; Thu, 16 Nov 2023 01:29:19 +0000 (UTC) X-FDA: 81462084438.09.95D75EC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id D871940009 for ; Thu, 16 Nov 2023 01:29:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LvzUWBEI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700098157; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Rr9/qVNLgFGWDGzcAqjV00T9t0NzgxXDD6w387jcEYI=; b=3jGa/+cWeX7qtsnvn+xEXYIvcPJLw2QM3ORVUnWgps0ZGrsG0P4xyDfaRnXoDwndAkDajy di7VxKWNfBO9kRfaA+a5ZXOaUvDy+Bhnc1y6ekN2+Ep2/2u08FPddlpRSQzjDUNON1hr0c E3+peHRw1RY0sG+IYBfUhneT4c11lXw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LvzUWBEI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700098157; a=rsa-sha256; cv=none; b=ElO7cCCG7cghuYH+gDJvYCrLA2GswtPeCWo7kpUAGMHn4hWCy8n3rn3dVkAJ7RmT5ZUdgJ ZsP5wXV6vkI6L92L3y+tpAVD/WsFl0zh9Mw/7HMZEX0wIkPjCVVOdrJwwBCKUS3OItsmyo G7QARBEqB6tgon2oVYIhT149a4M7bTM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rr9/qVNLgFGWDGzcAqjV00T9t0NzgxXDD6w387jcEYI=; b=LvzUWBEIUIV+qlm7ECl/EkQelJFUv93LiT047th0Ogirsg5Hbh++Yn0WVMWSKlo266eDj/ 6A4MyNXP8ghbviPrXumA1sxN3sftCUqCcWym+xgg+HMFZ+9oPsuDxT3+mZ2o7E6g5ayjpt Rohg1g/XBtOXnppsKx1Gm/oezP3bT5w= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-j3q-Fc-8PEKNpXeinqKNCQ-1; Wed, 15 Nov 2023 20:29:15 -0500 X-MC-Unique: j3q-Fc-8PEKNpXeinqKNCQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-77a02ceef95so2901085a.0 for ; Wed, 15 Nov 2023 17:29:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700098154; x=1700702954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rr9/qVNLgFGWDGzcAqjV00T9t0NzgxXDD6w387jcEYI=; b=VeM+hc4beo7e0U2fgWPiG4u/eiy2cwVzKnNWU45PwWjAadepL1jQlNQJhxjwADVru/ xajUQG3xIFMg38LSjKKe/9YbWodsnhe+q0xyrMI6Qla+SAXn1oyJRHbBO4Lm8fhnB0g/ mLjuYFW/aoPV42wDRkEbPysKRE1Qs6Bgn3msnrgxftLAgbHWOZoDUgx68yEliH8AZxYl SAq/MDxGqTXilMslPmEPyaVF7HWQm0YWf6h4H4X/j+srlcPK0WR9tAX6tYB/jFBy5DiX zc3a/qcxJzNmW5w+TVXNrWsy21ZIuPRx7n9+4mOGx2VKZ5qUDFDutsUrgi08ljulM0/1 IxIg== X-Gm-Message-State: AOJu0Yyenq4Lm/JxZnDBNxTr+vxS3r3vSsyCN6mcpbKNWNHydnl182fQ 95M/ZMjxQW8aTNSgVCJKZ56JC29WcjsgXtLgDuvVoL+YcBmzU+JrYG6YcXaj61ycXWY3UPebZzN t1y3YuL0BKuY= X-Received: by 2002:ac8:5189:0:b0:421:c275:f917 with SMTP id c9-20020ac85189000000b00421c275f917mr7201788qtn.6.1700098154664; Wed, 15 Nov 2023 17:29:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFImkFHmltxmevzx1fu9EK+pMFz+bfHbyIeYa7FxbalfbUu9NzmbSIrMhaQwUJeT0EwTIDDnQ== X-Received: by 2002:ac8:5189:0:b0:421:c275:f917 with SMTP id c9-20020ac85189000000b00421c275f917mr7201781qtn.6.1700098154444; Wed, 15 Nov 2023 17:29:14 -0800 (PST) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id c24-20020ac85198000000b0041e383d527esm3922598qtn.66.2023.11.15.17.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:14 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , "Kirill A . Shutemov" , Lorenzo Stoakes , Axel Rasmussen , Matthew Wilcox , John Hubbard , Mike Rapoport , peterx@redhat.com, Hugh Dickins , David Hildenbrand , Andrea Arcangeli , Rik van Riel , James Houghton , Yang Shi , Jason Gunthorpe , Vlastimil Babka , Andrew Morton Subject: [PATCH RFC 02/12] mm: Provide generic pmd_thp_or_huge() Date: Wed, 15 Nov 2023 20:28:58 -0500 Message-ID: <20231116012908.392077-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116012908.392077-1-peterx@redhat.com> References: <20231116012908.392077-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: D871940009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: sotxjxzx7cm6ynw9osun8ztkph4o1ojs X-HE-Tag: 1700098157-50759 X-HE-Meta: U2FsdGVkX18glz/QwOnIXbQ8rIKjWXveWyV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LG8Sg5+W2XH7LNqcW+cwGDLlBm8rpniBNMvDzdgv3WH4oQ83HUHJgdtpWfmSTLzAwLasSiP9KJO/ccQWmfYerUochBfpi0ZSpYyuTrLuo6P2WCZXig7qZxHu5KTZp7aFDe6omuneIYI4njxZk32JZaUK90QD03abxB+t2AAotpCLBPBsEtMtbIBVeGQS5I1irSsf7UebiQXH89WLu7wkKC+dEOcePRdiudcNHoOrlNr+vf5DnOGuxdDCfQEY5pQRZHGlD8CX/I4zfwx/64VCJ2cJMpn6Vn5mav2IjLAHN/Sg7Tqb3iaQ9mBbaa9I9eutgJjYfL5Q== 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: 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. 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 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 231711efa390..a8b73a8289ad 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3002,8 +3002,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;