From patchwork Wed May 8 13:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13658777 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 603B3C25B5F for ; Wed, 8 May 2024 13:36:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0094A6B0085; Wed, 8 May 2024 09:36:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EFABC6B0088; Wed, 8 May 2024 09:36:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D74966B0089; Wed, 8 May 2024 09:36:47 -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 BA09B6B0085 for ; Wed, 8 May 2024 09:36:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 745731610AE for ; Wed, 8 May 2024 13:36:47 +0000 (UTC) X-FDA: 82095328854.25.5D65D68 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf06.hostedemail.com (Postfix) with ESMTP id 1CC7D18000F for ; Wed, 8 May 2024 13:36:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715175405; 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; bh=lliFZr6GKraR8G24zn6kAgvIajI96YnfDePdDqHBH4E=; b=5NXVxYbrDNrDEEc7xmSss9ZH9ddHtTuM9sFXY9IeSQ1ucdOzrdl7XpNTKrP3TRrX1GzDJL KLFfcAqOy6FY0C/oAXlVYyRaYYywJsSAsJkfr7QCVxweNNTbIHw3DfPJMBs5qlj2zx5r8c Dmyipt3grPVk7GviecOXTp0DCEFavd0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715175405; a=rsa-sha256; cv=none; b=i0zK/Dt9pgUT3ZnfU7OxEIglRzHlpSetKsuOF1NL2SmBA2BdAqJUQZt6nlP9jWXiG1vvz8 xySk2uyIZyq1Lc7+7HfP5jUmh2qWdThD0YGAc7AD65v30vtWHFo0EfxZQi0ScxhIN21v3T NKBMS5r4KCJmayLr0tLFLSvq8i47K/Q= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VZGLX6Lg4z1j1Kh; Wed, 8 May 2024 21:33:24 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 621BB1A0188; Wed, 8 May 2024 21:36:41 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 8 May 2024 21:36:41 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v3 03/13] mm: page_frag: use free_unref_page() to free page fragment Date: Wed, 8 May 2024 21:33:58 +0800 Message-ID: <20240508133408.54708-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240508133408.54708-1-linyunsheng@huawei.com> References: <20240508133408.54708-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500005.china.huawei.com (7.185.36.74) X-Stat-Signature: oiqoiu7fkgfptqitqhtwkz8es7rckkyq X-Rspamd-Queue-Id: 1CC7D18000F X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1715175404-690829 X-HE-Meta: U2FsdGVkX1/0pNNcSgiiJ6XpBaXThUgnxLtZO4mzv3UFrnNHHA68RDWBJyX3v16zKZe2eXFy0zG10jQ2/aPRICM6fs2l26zVIy2HEEsKux40JjMu0cRamQZ63Zp/I91jKoFwwzygMmBvbCYtQo6kazssqICgnLHq0Jp44T5YD7Rh80UKL+qsd9idcMKqcj/AY3x1niUMq0ls3X60QiUeTiQTe3rj5F6vu//EVJ6vNKhasK4cpAsKe2WblGUwI5nIIP/DVnhrXMTBu1nBXj6pw9WUeIlp2mnZTxO+5FWegJmaz8SZK50NEH0NKoYvN9WTwN1sn34/6RmomjM/z8jTIiUl6WXxeG2/hJTDk5+s3SsFfbq4SvO5FwEM2CLUcfCKsiOg/Ufp39Wea5BP1PzQWvk3d8x2Lpf3YkK/nfUz7wWuRblVLv0Cekb38HcjrH4+AnyTurpRTnCzVjfRdYYvoQw+2wcUOkwL7Q74fgnILM5QSIJQIPnv4ajxXyk0u+w2z9PllJd48RLM2zt7tZB0D0GntxfaO5rwrZrV0Mmdv+eDNbtyAThWxgHi5EetouAm9LB0BLtnhNlfqArfsmXGs9Gw1+eMWbiwDJComyBfq0PM3+630Hyb8urUIraiug8yj4+on8785mDON57Ob1ZLxkOaoy23FyHhZ1Bng1H3KV7ZGdvOcB7uQZAGGi6uWy2rYUtkvLtqaczWkM7YRC+dVpPa8hb7kbeT/w1SH6U0yccbfH4y4BVNaru0iP+9QkngBYv/LGnAY59r82qoQAYC/R3nFjo00usZNtH47vyVL3cBlQbHK4zumxl/ftrgX6NQfdsTkWgVgpy6Bz0bT0iiLR6z8dBVKGjBlKUkG2Hinf10dX9gToTsFiTbWLMBxybKhjwlyyN9j9RFjcs8wPGzX9KUSS2tY2awVRBAziT6F+31v7rzq3AYN3vBqPRXJos3iVKuBajnQxrZCkRHeAe O0h7cftY aqM8HhTw7Wi/uqvEfXh6Q53EovxaAvIIlo88DzZfzADbSfjA1O5aXohNFCb3++B33h2qoj/ho+QGjxIwGuaEWzDhUgs+VnXoFT8ucW9DGzECnyZ5FteYj2o7Yy9EkyXegrVTLH3/zH1sFB97X5kVgDwpERquNNDFI4AxDIa6keK0S4qNVDD9uHBJBj7/ZSPsSCUJ1DU9dXRBkmLJpxY32UFGMwuAU0raFcjxOP2lS35XG8mdTf08cUsQ/dhpd/CkOrMI5If6bNWY0ZqbdUprtj4iPmToMuAGhrfg6 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: free_the_page() used by page_frag call free_unref_page() or __free_pages_ok() depending on pcp_allowed_order(), as the max order of page allocated for page_frag is 3, the checking in pcp_allowed_order() is unnecessary. So call free_unref_page() directly to free a page_frag page to aovid the unnecessary checking. As the free_the_page() is a static function in page_alloc.c, using the new one also allow moving page_frag related code to a new file in the next patch. CC: Alexander Duyck Signed-off-by: Yunsheng Lin --- mm/page_alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 14d39f34d336..7adb29f8f364 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4693,6 +4693,9 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_t gfp = gfp_mask; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) + /* Ensure free_unref_page() can be used to free the page fragment */ + BUILD_BUG_ON(PAGE_FRAG_CACHE_MAX_ORDER > PAGE_ALLOC_COSTLY_ORDER); + gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, @@ -4722,7 +4725,7 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) VM_BUG_ON_PAGE(page_ref_count(page) == 0, page); if (page_ref_sub_and_test(page, count)) - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); } EXPORT_SYMBOL(__page_frag_cache_drain); @@ -4763,7 +4766,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, goto refill; if (unlikely(nc->pfmemalloc)) { - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); goto refill; } @@ -4807,7 +4810,7 @@ void page_frag_free(void *addr) struct page *page = virt_to_head_page(addr); if (unlikely(put_page_testzero(page))) - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); } EXPORT_SYMBOL(page_frag_free);