From patchwork Tue Oct 3 09:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13407343 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 14A84E75438 for ; Tue, 3 Oct 2023 09:25:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86E798D0066; Tue, 3 Oct 2023 05:25:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81DB28D0003; Tue, 3 Oct 2023 05:25:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E8C68D0066; Tue, 3 Oct 2023 05:25:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5F1C38D0003 for ; Tue, 3 Oct 2023 05:25:39 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3488B16021B for ; Tue, 3 Oct 2023 09:25:39 +0000 (UTC) X-FDA: 81303617598.22.3EA884E Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf28.hostedemail.com (Postfix) with ESMTP id 65F58C000C for ; Tue, 3 Oct 2023 09:25:37 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tDY/wBKO"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696325137; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nzmHY2Ka5cz6XnAsRZastGfanbfs6f5GjSGMfdpW808=; b=Sqn4dzDxr474uJX/UD24GPtqLo1pqPL7lN6PBFrJN0PPB6HjmgvoWCCRwPr0+T5k3RniS4 mbdCMWbg8kwqyz4AWwZAcKaIJrJr/eiBJg9+jZVKHw3om/JTqRbvB/nZ4/QzWVsF56uKXD G+e4nDQo0iXoqhDuV7t3BAc+sI7zszE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tDY/wBKO"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696325137; a=rsa-sha256; cv=none; b=s6WAEqD9xE3rlJeUvogqrv3bYp2Ty36pI06/anOBRjewHZK0AJ+H2fNqk95z7VEcwyUj/S SoDbR7aptq316HsIYOAvWMTNAxCrnLP0ojZr+D544RVfCTuvvqVIuzcloGkPD/b2Zb1iI3 P2/CJ89dwb02xWVUrHOUB052SrrnQi0= Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-59bf1dde73fso8538027b3.3 for ; Tue, 03 Oct 2023 02:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696325136; x=1696929936; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=nzmHY2Ka5cz6XnAsRZastGfanbfs6f5GjSGMfdpW808=; b=tDY/wBKON9gX8Uuj8KrGBteW4/OwHiPUo93bRbtNj6tmUbSi/0yoXYnTxIv0Q5ddvr bHobaTqE7Ad+vl6hGuey+gtmXWB9jTDqUcn2+IDxVWoyBXDOJtqSPaCEub+xA4h+iKfd gzPoi78za8Ca4c3TMqtnt3PXcNG2D3HfBv8+8SwvET4pQ4jm0p7bHlFDNcR8/0WWPe5w nr7wiESXkKnV6Gqr0HG0sBwjRXPGHXGTiIr3EVBm5yenuMV7QxaOqJtR7eiDIq9MxzSh FLzYcVD9K52R6FDv7wmz9KrambfiJCeLPCPAapEwOTt/dU9+vewBqsFAcmzOTO1QANjf 0gww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696325136; x=1696929936; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nzmHY2Ka5cz6XnAsRZastGfanbfs6f5GjSGMfdpW808=; b=D3auQHHHqLMnAfRXocGQHRwH0fmVCyO/av1HjYy+qSTl4sBmudxPDor6nT00tgFQF6 0nnusA1zUNSoZVZtIHPkX1C9zOXzRaDnayNkG1Q93csv/U3O/GVrAr/NVN81MZCwRKGK oKyxYmbdzOnPT7l/IcPPg1kiSxeL3wIJspbKqJ+Y8h/GJ/kc4oUSGfwJzQb2U1XrgwKx EMYEQKW4iCkbu+eKwLVmOFe0yJvCM3oz1Nz/bZFbGOinBOPw62bgo+XlIKBSSl7+gLRs uTpe4/VIyeajJzdsFUs+k7BQvmeS+v/kCSqskedCGKX34PeuFwyEa8t/pbGLE5PP4vKn v2sQ== X-Gm-Message-State: AOJu0YxTHB0pYGs94sbDq+Le6nBJa03R4vwg78vUYNHraoGAdy4rg3bT y8h4A8z3+KxB/lymvulygEFafA== X-Google-Smtp-Source: AGHT+IGmeBMAQui7nSclUIqDA2Y4gv+lO5peTi3URjoKJb2fITfIn+IGiCa25QjXZ2e92Ix5/drY/A== X-Received: by 2002:a81:4f52:0:b0:599:da80:e1eb with SMTP id d79-20020a814f52000000b00599da80e1ebmr14242966ywb.24.1696325136488; Tue, 03 Oct 2023 02:25:36 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id o19-20020a81de53000000b005925765aa30sm245713ywl.135.2023.10.03.02.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 02:25:35 -0700 (PDT) Date: Tue, 3 Oct 2023 02:25:33 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Andi Kleen , Christoph Lameter , Matthew Wilcox , Mike Kravetz , David Hildenbrand , Suren Baghdasaryan , Yang Shi , Sidhartha Kumar , Vishal Moola , Kefeng Wang , Greg Kroah-Hartman , Tejun Heo , Mel Gorman , Michal Hocko , "Huang, Ying" , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 09/12] mm: add page_rmappable_folio() wrapper In-Reply-To: Message-ID: <8d92c6cf-eebe-748-e29c-c8ab224c741@google.com> References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 65F58C000C X-Stat-Signature: 4p6ntcn5y1k1tri4geu16ufejhwrxd6b X-Rspam-User: X-HE-Tag: 1696325137-266751 X-HE-Meta: U2FsdGVkX1/TdbpiDTc2W3ecHgnvsHOcwYaECERe8xS4d9ureOdXigWxfkmL8Y4cm3HSpteiYOkszMFXxJy5c2H/zEMq1NMCZQrWRMHGw+OG/eQCS0qpKcLL7+TIiT/7y66c3T4WHYOt3ltL6CXBpAIloGHG/yLbR/W7z2PNe5d1+mkfKU5tsiLrV8ukCgVa6ROTLQLLTTLy5gfJYyfn4Ry1MBodq7aHz9sZAnDeRHr5GD+BYVTHRlekkcteCqoG6Ep/u8fdOv/BAPj1OYnGacWNyuUY0UIy/mURCTGR6c2gYJ/cIXvWi5ZlIFL6AVboZDhfBoXGueQzBO5apW8IzvNiI24p3sGAj0cJ0vKEKQ6JcDGh3fjW/c2wB6oVSMZF0/SYalhTBNDhzw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5iXIyLuHUV3cqrPYMM8JMmOMC3gtS5 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: folio_prep_large_rmappable() is being used repeatedly along with a conversion from page to folio, a check non-NULL, a check order > 1: wrap it all up into struct folio *page_rmappable_folio(struct page *). Signed-off-by: Hugh Dickins --- mm/internal.h | 9 +++++++++ mm/mempolicy.c | 17 +++-------------- mm/page_alloc.c | 8 ++------ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index d7916f1e9e98..b2b3716d1df6 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -415,6 +415,15 @@ static inline void folio_set_order(struct folio *folio, unsigned int order) void folio_undo_large_rmappable(struct folio *folio); +static inline struct folio *page_rmappable_folio(struct page *page) +{ + struct folio *folio = (struct folio *)page; + + if (folio && folio_order(folio) > 1) + folio_prep_large_rmappable(folio); + return folio; +} + static inline void prep_compound_head(struct page *page, unsigned int order) { struct folio *folio = (struct folio *)page; diff --git a/mm/mempolicy.c b/mm/mempolicy.c index f3224a8b0f6c..bfcc523a2860 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2142,10 +2142,7 @@ struct folio *vma_alloc_folio(gfp_t gfp, int order, struct vm_area_struct *vma, mpol_cond_put(pol); gfp |= __GFP_COMP; page = alloc_page_interleave(gfp, order, nid); - folio = (struct folio *)page; - if (folio && order > 1) - folio_prep_large_rmappable(folio); - goto out; + return page_rmappable_folio(page); } if (pol->mode == MPOL_PREFERRED_MANY) { @@ -2155,10 +2152,7 @@ struct folio *vma_alloc_folio(gfp_t gfp, int order, struct vm_area_struct *vma, gfp |= __GFP_COMP; page = alloc_pages_preferred_many(gfp, order, node, pol); mpol_cond_put(pol); - folio = (struct folio *)page; - if (folio && order > 1) - folio_prep_large_rmappable(folio); - goto out; + return page_rmappable_folio(page); } if (unlikely(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hugepage)) { @@ -2252,12 +2246,7 @@ EXPORT_SYMBOL(alloc_pages); struct folio *folio_alloc(gfp_t gfp, unsigned order) { - struct page *page = alloc_pages(gfp | __GFP_COMP, order); - struct folio *folio = (struct folio *)page; - - if (folio && order > 1) - folio_prep_large_rmappable(folio); - return folio; + return page_rmappable_folio(alloc_pages(gfp | __GFP_COMP, order)); } EXPORT_SYMBOL(folio_alloc); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7df77b58a961..00f94dd88355 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4619,12 +4619,8 @@ struct folio *__folio_alloc(gfp_t gfp, unsigned int order, int preferred_nid, nodemask_t *nodemask) { struct page *page = __alloc_pages(gfp | __GFP_COMP, order, - preferred_nid, nodemask); - struct folio *folio = (struct folio *)page; - - if (folio && order > 1) - folio_prep_large_rmappable(folio); - return folio; + preferred_nid, nodemask); + return page_rmappable_folio(page); } EXPORT_SYMBOL(__folio_alloc);