From patchwork Mon Sep 25 08:32:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13397486 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 795C1CE7A89 for ; Mon, 25 Sep 2023 08:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 187E78D0017; Mon, 25 Sep 2023 04:32:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 137868D0001; Mon, 25 Sep 2023 04:32:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 026578D0017; Mon, 25 Sep 2023 04:32:08 -0400 (EDT) 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 E8EF38D0001 for ; Mon, 25 Sep 2023 04:32:08 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A346EB3CB5 for ; Mon, 25 Sep 2023 08:32:08 +0000 (UTC) X-FDA: 81274452336.01.2CDDED1 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf09.hostedemail.com (Postfix) with ESMTP id C7A12140008 for ; Mon, 25 Sep 2023 08:32:06 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oDPuvRHV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 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=1695630726; 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=ESRqX1PlrIchswbjY6F5gY3I+wvwb2kVpQ+ph7N3oWo=; b=SlvbBX3YtgCCKQAndlQBD/YByJDU29XkkLq6F3atZfsHolIrlYZXiqbTaTUaJIXl0gzDaB E5qxSEZYHMY7DtkGcSqToqqTWYw5YX2lKfBOn0z1LM19L6K8DhOlqciSOUmyV5Ykso0IDs xbjb1EKyb0lalOQ+1Bvhghvva0Vv1bk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oDPuvRHV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695630726; a=rsa-sha256; cv=none; b=Usd1W5pk+aBbkERAyBq4SA1OzbYi2rxA1pu0dHGxlCrA9C8P+2It4+hBk7wQ+CqiQFmMlG yBG3W/tqY+gCRQnCYMwrtU7XMdKvdxJQOVBhxwIvgqKpzvgcqi1sIxJDMOavosB8e1mtKC OIijeFmibOeblvpnHwTsY8FPnuZhwmE= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-59f7cc71e2eso15151797b3.0 for ; Mon, 25 Sep 2023 01:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695630726; x=1696235526; 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=ESRqX1PlrIchswbjY6F5gY3I+wvwb2kVpQ+ph7N3oWo=; b=oDPuvRHVVuW5Eqn4Z3wZqhYNGABjxs/6oQp7mcjml1ly1ezZnPSYmmqxGIgmsUEIXN zRKKyHwDg2Ia1CIb7tW1zlWyAy75tZtRL9bEtxcNNZo2G2BgbZl78ju6JDAHgvgJpfct NDk+TBt9olfc6eObB4a6mtYR0ahUv+XaM0wK8176UxkoixplSWMu4U/HMtosFB45d751 4kjIBI7tmIMGX39O4ZRnbWHnK65RzaIqf5pgSO7GAwcdOSRLTe8cpXvHvndDMG8Icgn0 EHnsqtL2EbCcUW1pz36zrnt+LsKlbc9d3POv4YsZ80YEMFad/hO6QXsKLeYuCbRuao2r 7pEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695630726; x=1696235526; 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=ESRqX1PlrIchswbjY6F5gY3I+wvwb2kVpQ+ph7N3oWo=; b=eImcCoRKtW16OoA0C/QyPjDcEMiH80UNK50xyQk0+B3VkGN4av9oaJsiDG59ZucOo0 YgW10u+Rploru5y2iJuwpk0getOZC6RYzIfm3nK2UpbVewiAGvx7uav+Cfee22mrgasn yrvxAtdoV45eJXe3snnhn8dbcuwB8t30+wrDKKz1uDrYbblAM7vOSkAAovNp++FYxNUf /udufoWBzKdmwg56QYGQqKh0xbG8T+BlfDN5he7seBLGAv+glzrl2z4sTWwaJ89OiLW0 33GdSMfKVGJgP5e1YWgsi9wbj0xhZJk7fELfgYkPaWJwcojmHwnGtK52Gww87nXiwl9j 8GIQ== X-Gm-Message-State: AOJu0Yyk9AKmUqWYA8UFQ/Udk9CDzQD4B+kxS+jLvpGFxCiJXr+aYgI8 40MH8QArh9hThgw/Nocfj+A80g== X-Google-Smtp-Source: AGHT+IFI7sWdT9SaX/WaLFmLycQV1E3ZHD2waCsU6dSHFKECPifOP+qkTIKONo5XkYDTZbJNeNdwNw== X-Received: by 2002:a25:744b:0:b0:d84:da24:96de with SMTP id p72-20020a25744b000000b00d84da2496demr5304926ybc.33.1695630725781; Mon, 25 Sep 2023 01:32:05 -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 t3-20020a056902018300b00d1b86efc0ffsm2024884ybh.6.2023.09.25.01.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:32:05 -0700 (PDT) Date: Mon, 25 Sep 2023 01:32:02 -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 , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/12] mm: add page_rmappable_folio() wrapper In-Reply-To: <2d872cef-7787-a7ca-10e-9d45a64c80b4@google.com> Message-ID: References: <2d872cef-7787-a7ca-10e-9d45a64c80b4@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C7A12140008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4397qdns587rpqodramuto4wd7k7zq5e X-HE-Tag: 1695630726-680514 X-HE-Meta: U2FsdGVkX18da0zDZMQSYnjQyjYBJZaEM2w4BwX5yMPK7S8GkM6WL80DNtl1dI8PW/NGcILxEtpLhIJrIfcN7+zsm/UZEeYduyOCKTX1U7xIk5XWLK1LhcbsJH27FMmVEIJf94W+jyizle6yNe9Mbj55wnQyyE+ZaoZM1TlIpRTEDBGTsix1BXOVlsIaMw7frhDtDK5RyJpIDJYe4bhuNsNIfra9mWcDG3pBRgGztvmPLdChG/gbaizhLcyKI86/I9UCAx2wGsAaEsiVrdfoIJLxI+19Nx9wlEnqsYC5ggvAhhwZ12xXYb9dqjkQA+WR6WaNoHv7YZ9twSchexpfyl5np5lxy/i5kk8STsvcntRx4sc2jkxoF34Wk83PIb+Sy5Vcv4h38MM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L4pYAz+55xzSW1XSaZURpu9YSUo6ebT0WM+lGkWK0 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 --- include/linux/huge_mm.h | 13 +++++++++++++ mm/mempolicy.c | 17 +++-------------- mm/page_alloc.c | 8 ++------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index fa0350b0812a..58e7662a8a62 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -141,6 +141,15 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); void folio_prep_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; +} + bool can_split_folio(struct folio *folio, int *pextra_pins); int split_huge_page_to_list(struct page *page, struct list_head *list); static inline int split_huge_page(struct page *page) @@ -281,6 +290,10 @@ static inline bool hugepage_vma_check(struct vm_area_struct *vma, } static inline void folio_prep_large_rmappable(struct folio *folio) {} +static inline struct folio *page_rmappable_folio(struct page *page) +{ + return (struct folio *)page; +} #define transparent_hugepage_flags 0UL diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 7ab6102d7da4..4c3b3f535630 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2137,10 +2137,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) { @@ -2150,10 +2147,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)) { @@ -2247,12 +2241,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 95546f376302..5b1707d9025a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4456,12 +4456,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);