From patchwork Mon Nov 25 21:01:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13885274 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 7BB30D59D6B for ; Mon, 25 Nov 2024 21:02:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 338866B0099; Mon, 25 Nov 2024 16:01:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2251E6B009A; Mon, 25 Nov 2024 16:01:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029EC6B009B; Mon, 25 Nov 2024 16:01:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D1D826B0099 for ; Mon, 25 Nov 2024 16:01:57 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6E15A80D9D for ; Mon, 25 Nov 2024 21:01:57 +0000 (UTC) X-FDA: 82825839306.19.72C0344 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id A3DD1100008 for ; Mon, 25 Nov 2024 21:01:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Sme2uyeU; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732568514; 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=S4RU9x6aK+s9y5UC4asSHORm/FbRhVUFGtUW3BrWS7Y=; b=QMB4Em/QqDRVh+MnjeqW0JiAq61QfEW/oKG3/PxjBcs9yjpLnfSLIyMcfM9EI9dHKB+6l8 UA9LKMDlmPZglWwpBlA/Hz210co4JRVNpurDObfk/+K/+UQLOwvtogxaCSYnHNfOXwOJIc Mn7HhFOWoBjQoqmKTlCSFeqcZ2hFN6w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732568514; a=rsa-sha256; cv=none; b=0CCGdsGXbmDT6CF1QA+EvXGxIA1jAXs4Ar+xFElaKWVuiRThAU2Veuk0GYQrYlyn9FbhgA 59S3MO8ylRnoXCzIW3+Lvr3Td2FEKaeY2mtJBQ4kec5UhcK8w43RHjHlIibOdYkN1nOlXr ecYIzuz+kLthkWtr82CAXZX72UxzOB8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Sme2uyeU; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=S4RU9x6aK+s9y5UC4asSHORm/FbRhVUFGtUW3BrWS7Y=; b=Sme2uyeUwaOgKG2zR1UUn2qcBs K31S82iRe+oNcEeCOLSOFpzJAiTSN/MWN63cjh5eb3mu3UqlTIvliez1DDtUVqg48NHKXDQTxJ1M8 Oo7MmsnLCPsabnFyBGHyJx0FFJ3PO3vCdz4k7J4Vb+lTACSqnK+JDOyMCBFE3eljHRD1jubD5vJY9 mLImGmHxlh/SEbJ/rU/gSpfriW49KNTSr15I4+tZCpFOj/Vq/7QFKTNvloSemW1DLL7QtVE71sGCF 7d0Y5hYFADuRfSzPtLc4l+vSTQIwUmk2PpWwGrYaAumuKLJVuMm0rF+rLlD609Ukj/IFQxwX0ebuM 5SYGxWig==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tFgDP-0000000CUE3-1fUF; Mon, 25 Nov 2024 21:01:51 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand Subject: [PATCH v3 06/15] mm/page_alloc: Move set_page_refcounted() to callers of get_page_from_freelist() Date: Mon, 25 Nov 2024 21:01:38 +0000 Message-ID: <20241125210149.2976098-7-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125210149.2976098-1-willy@infradead.org> References: <20241125210149.2976098-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: mb5jckgju9r5hzsa8yqubax3uq5d1h9k X-Rspamd-Queue-Id: A3DD1100008 X-Rspam-User: X-HE-Tag: 1732568511-199503 X-HE-Meta: U2FsdGVkX19z+gdhbO1OchSbR3IJ1xEZ9Rz/u1/x1rbfILUi0xrolzDsfqaHpxTzu9Obgxa7S6i/PaxN8r9ZYJdlCz4CEERbPlkH+3bDB//xVex6zJWBt6LSI6RhU9iecQYwmmxvneJwoFo/DljAk870EsabUv2Xwz6ddHtDXcnGXPvNTXzIJuEhIAsLCLAFVVajfpqLcHztBcaChxhSHyyt9en5p/wWjJl08rq2iOysA3OjLvnWfrPx2dXU6p7Tk3E7RBdLMQfW8MHHbMb58yzG0bEWCqtYeLQE3jqi71VHsmpZQray59mQO/ivCo6DRmt11GmX/SEKIAQPDjGBt8XWlEmpsKlFJOux3Y0gds923V7SFYGORxC1HYqasZfHoHlZsWh6DnC7l8Ck4z3cPhiDUleKZHx+fv3VfFcltda51G3fUp+ESh13T2beW3DISqkQeLIRp24y0h8DukYu3cLQcLa4G/5YjNVvUI301W7OvAxa2CAXnXXjEMwsD8wwf2oTgAmz0cj4dYaA6Go536EgBB4m/c4tEgQD5B2bFPseYoyFjxcscBEUkiYsqJt1qDNWyo28Bkrz9cR2KHbs2Yow1nwJGuFgTAxF/6HRdz+unD/OktHJQQp96pg7XkQiY0tq/RQUjS+nJekiI5E5+Kf0Ftc5NgdmUhsxM9ThHPIiszvHhHOqopqmk2rPxoNQ3Ma2X+17fWfAM756lqZDY4/GQjDpEXTAjUgsg6YAwCy4/bfvGIbY6WJvcahdSGOsEIsXSdAwMeUyAR3zemQuWpq8Sds53fHWSJKd2oTQ6EPzqK2z0F3+fvl/2zis2PgC5ISmD3KXi57pBzNVmiHw9qiWz6HN99oh41iqoDYuwfWvk1VB/bcUGfC2bnK98+rXS7Pha5O9E92qzP1+jsDUzxDaB4Bl2Fx199g5twH7JftJ1TxuE8T1mqbFljFy3A23B/ObBbj2tvZK+ZIjFUG s0RU1ODP qMzVx2Iyw+8tf0XNK7pM7QR6epKkii/qhvarKSMOjVRr5F8yLpk4gouuquXxly6N3rTYHiag2au++ViNH9eot81AJhZaK9VRoKGq4NUoLKRhgktOxo91XZ7+dsEpMJFHlj9TLT5z/zGRx6sKEwFr21TWGjVKK+0w45mpk8juTy+trrOtJMefYRA2SJ11EHjlfdn9jnwbx5HIfAWJG1SbeUqGaHWWIQawX6g4FnKorh/OzCirizQFlYmz0a6Utg6R+7aMTvlF+l8IEh8r89cvrH2u7U9Lg4/LTf2M7 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: In preparation for allocating frozen pages, stop initialising the page refcount in get_page_from_freelist(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/page_alloc.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c2b46cdc7ffd..14fa6bf7578a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3507,7 +3507,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, gfp_mask, alloc_flags, ac->migratetype); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags); - set_page_refcounted(page); /* * If this is a high-order atomic allocation then check @@ -3602,6 +3601,8 @@ __alloc_pages_cpuset_fallback(gfp_t gfp_mask, unsigned int order, page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); + if (page) + set_page_refcounted(page); return page; } @@ -3640,8 +3641,10 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, page = get_page_from_freelist((gfp_mask | __GFP_HARDWALL) & ~__GFP_DIRECT_RECLAIM, order, ALLOC_WMARK_HIGH|ALLOC_CPUSET, ac); - if (page) + if (page) { + set_page_refcounted(page); goto out; + } /* Coredumps can quickly deplete all memory reserves */ if (current->flags & PF_DUMPCORE) @@ -3732,10 +3735,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, count_vm_event(COMPACTSTALL); /* Prep a captured page if available */ - if (page) { + if (page) prep_new_page(page, order, gfp_mask, alloc_flags); - set_page_refcounted(page); - } /* Try get a page from the freelist if available */ if (!page) @@ -3744,6 +3745,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, if (page) { struct zone *zone = page_zone(page); + set_page_refcounted(page); zone->compact_blockskip_flush = false; compaction_defer_reset(zone, order, true); count_vm_event(COMPACTSUCCESS); @@ -4002,6 +4004,7 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, drained = true; goto retry; } + set_page_refcounted(page); out: psi_memstall_leave(&pflags); @@ -4322,8 +4325,10 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * that first */ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); - if (page) + if (page) { + set_page_refcounted(page); goto got_pg; + } /* * For costly allocations, try direct compaction first, as it's likely @@ -4403,8 +4408,10 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, /* Attempt with potentially adjusted zonelist and alloc_flags */ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); - if (page) + if (page) { + set_page_refcounted(page); goto got_pg; + } /* Caller is not willing to reclaim, we can't balance anything */ if (!can_direct_reclaim) @@ -4788,8 +4795,10 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, /* First allocation attempt */ page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); - if (likely(page)) + if (likely(page)) { + set_page_refcounted(page); goto out; + } alloc_gfp = gfp; ac.spread_dirty_pages = false;