From patchwork Mon Nov 25 21:01:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13885271 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 45474D59D72 for ; Mon, 25 Nov 2024 21:02:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49BB36B0089; Mon, 25 Nov 2024 16:01:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AFAA6B009A; Mon, 25 Nov 2024 16:01:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD2146B0088; Mon, 25 Nov 2024 16:01:55 -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 5A38C6B0088 for ; Mon, 25 Nov 2024 16:01:55 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1870CA0992 for ; Mon, 25 Nov 2024 21:01:55 +0000 (UTC) X-FDA: 82825839096.17.747CBEB Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id BDEBC40005 for ; Mon, 25 Nov 2024 21:01:48 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=X3clOrNc; dmarc=none; spf=none (imf11.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732568511; a=rsa-sha256; cv=none; b=6D8nJL5tI9hRCxwiuIB4VVoF/d+KSYSb2I5W5Z6yjFDdRwFjMkRsy7SY9623LBgVmnXZi1 mtd/OPLwxjLYUJnc7VXjUOilNIvN5beXxgTdqY7AM3ehntAPNOOqnEwA4diWR97dwh0rB/ J6+Glox+JrZrb1JVg+6DSGqLwnEgyPo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=X3clOrNc; dmarc=none; spf=none (imf11.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732568511; 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=15NrJPSuCbNLVlEgikd4xHCNsMtTjOmIIl7SMDwjgbg=; b=Vr6mqFIFQSoQesj8bIlyqC8h/gQIbGBuklSetWNKh2b5DtD12VoYI/TSadaSSLbK8/G/fX 30a9s6xRNICkywKvBjuuF0qO9Vmy3vVT6rqxNKL6aPy/DDEZs8o81aoUCdKaVDfAl7eytr zHjK5yD0CjoylENTjj44K4QebjKzPbg= 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=15NrJPSuCbNLVlEgikd4xHCNsMtTjOmIIl7SMDwjgbg=; b=X3clOrNc40T+OSY1MuXIfkyCWH YrgFiu+ojonpVG81WV/NYL2oyVlwSpR1bSQLjyImrc6jvk4dgaWMKFtat7+vf66kH1dfz7opahyfg m626qm+Zr8CGhg11URX2ZEgBbWFrMuyqoUCv2e9tZBr4ejvhoSc6U4bT8pUf7cAKD+lh3wnPy6Goz JWShP3air3YgpYdP1IvV3vNjLKh/c7PdMFbYUIrI3P/QpB5hIO4bnvPbFplb+VrsJoHDJaPuoh0mN xU4i/pmyOtxVV/nhu6UOJiuQKw8Ay6yfmnoWPAtrDsI/2m2Y9sHW1F50ddNBaUxbMJQSWl46p1d/Z 3q3baMjA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tFgDQ-0000000CUEX-01RA; Mon, 25 Nov 2024 21:01:52 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand Subject: [PATCH v3 11/15] mm/page_alloc: Move set_page_refcounted() to callers of __alloc_pages_slowpath() Date: Mon, 25 Nov 2024 21:01:43 +0000 Message-ID: <20241125210149.2976098-12-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-Rspam-User: X-Rspamd-Queue-Id: BDEBC40005 X-Rspamd-Server: rspam01 X-Stat-Signature: yhtgxo1zdesdmx19c5ueohj6japkj7dp X-HE-Tag: 1732568508-194621 X-HE-Meta: U2FsdGVkX1/XBUencAKF2Lkq1Ucms3w1giFt8u4zazlSCOOZ1ZAPc3weM4Mqjo5Q5HuYJ99ycHpukPWTSCvdUFp/X2/pWsJcx/4gTrCeyBTVAo/uZwQtrxZ7SqMWTAjYrZbjzm621VdLkdsepB/g0C2iEQyXo6bLPufOdXnZZVxwubg3Ha6uaviIf17ZZ5jE+vLhUaWk5oHO9H9P/DQOXiYGiJxOkRlPVFZwrf2lHGmZavq9LGBeFEKeLhw7YNOje5a3fTc+DSdwMOM1jWewx3it6/7IcCYf0cusviQ+dFL5w8KWDeIiopPULc3zziybF8lRLuNcN3heDjX+uX1kSCeb9NErBztme5+ueTuqlX1MGej4633BWxUaGW20e5wcHVgIarbkx900RuF/4JyafzjrmLBq/kmYNIURw+uGjd3pfT9BhZdeM1+yFKue/MDelT8jOC9ZHjRGBimQdviuMJtn3i3lb2Swjye4TzCrO0SqzCei9F86/u+rbo//z27XpHSVHxeiwlUhc5xxeC+8MlLAIjVxIwHVVgdcRS5gIU6bsCl7C0d7/zH/rxFIl+Lqa00+8QNwi1HsyhV6H35rFg4RgNNEGCD+RZvUeWHuwRab4kLZGc2AW0CVooxh9f+QnA2AuYeIMjyPO1P8HN4ykdL22Dh6j7Agz8pyneMOcrW+mMw8Snaftx3UagL6X/EKPvDUpK49GjXaz3YlpWPubbihpFn3GWKaDH/gG2pW0LyioauB5Xkr6udBM/aGqUBGUOPTBX/lNQzLzVA4wNyd5Akrdwt/p4/U3hZ2vHFUe2VhjBSDH80J4TOaasW+OAcArmOP7siiwzoVKEokuVaUvD9im0kgc0OnO5wiTWfvuMrgmpzhs+w3tW9NRXuoDnFG4AGX01vqP86Tm3YYDGNNMWMohSdXKUko8WdLJV3aoJqjfgEwqy6qq5fCS5zglRfyO6hR3bN+BPh4qE46+BT gjIjZMs7 lvH+ZDH2ayqQ/WL1V/3X9Y2BIM8uPQAx7o8N5nOgKzhMZCv0H8obWzU99Y69kCPfkelvwUnnyIZqn5DZ12kX7TjcBNthSNWy5wRRkHvzDyEKARCxCxbbzBN1YsejFhu8DboqmVv6twLV2r6uJJYuJULR75OVQnb6BBXNUEZjEbmVtCZvpX5QjBmRGCijAVlcSIn+IwyEjKaOcNz7sxm0XsnSJ1ua8AV35TD8eQgdgs/weYy1+FE0ycoGn0/edDcR0B5GjDalyiXYqGkFtAuMTN3YfECKbswDhLgcm 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 __alloc_pages_slowpath(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/page_alloc.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7acc32902fc9..c219d2471408 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4318,10 +4318,8 @@ __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) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* * For costly allocations, try direct compaction first, as it's likely @@ -4340,10 +4338,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, alloc_flags, ac, INIT_COMPACT_PRIORITY, &compact_result); - if (page) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* * Checks for costly allocations with __GFP_NORETRY, which @@ -4403,10 +4399,8 @@ __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) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* Caller is not willing to reclaim, we can't balance anything */ if (!can_direct_reclaim) @@ -4419,18 +4413,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, /* Try direct reclaim and then allocating */ page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac, &did_some_progress); - if (page) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* Try direct compaction and then allocating */ page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac, compact_priority, &compact_result); - if (page) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* Do not loop if specifically requested */ if (gfp_mask & __GFP_NORETRY) @@ -4471,10 +4461,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, /* Reclaim has failed us, start killing things */ page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress); - if (page) { - set_page_refcounted(page); + if (page) goto got_pg; - } /* Avoid allocations with no watermarks from looping endlessly */ if (tsk_is_oom_victim(current) && @@ -4518,10 +4506,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * the situation worse. */ page = __alloc_pages_cpuset_fallback(gfp_mask, order, ALLOC_MIN_RESERVE, ac); - if (page) { - set_page_refcounted(page); + if (page) goto got_pg; - } cond_resched(); goto retry; @@ -4813,6 +4799,8 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, ac.nodemask = nodemask; page = __alloc_pages_slowpath(alloc_gfp, order, &ac); + if (page) + set_page_refcounted(page); out: if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page &&