From patchwork Mon Apr 15 13:19:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13630027 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 C8061C00A94 for ; Mon, 15 Apr 2024 13:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C7FC6B0093; Mon, 15 Apr 2024 09:22:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44C496B0095; Mon, 15 Apr 2024 09:22:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2ECDC6B0096; Mon, 15 Apr 2024 09:22:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 134516B0093 for ; Mon, 15 Apr 2024 09:22:03 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D0EC31205DE for ; Mon, 15 Apr 2024 13:22:02 +0000 (UTC) X-FDA: 82011829284.15.4A2B39D Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf06.hostedemail.com (Postfix) with ESMTP id 50CEF180018 for ; Mon, 15 Apr 2024 13:21:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713187320; 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=zeduTcCDg526cCCJK/3xfYqN0ch44Yy/ybdxwM27+Wk=; b=tRTN+yb48hE33GWwKluenuVMmbv4i7DWKokLXgog050Pn2fK994P0jRRtUauOJurMBkgto xKJx11SJKo4BAm+UURk8Qh59I6WNSKv08HCX60dIkCBUPxzwhseLMi5aElRvOFMBruAwsQ ZAOD0uBKSUnYW8psFC7IazpiDCGNgJ4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713187320; a=rsa-sha256; cv=none; b=7fV1/yikcXyDchqUqupeWMe1RUhXgVjplZwKhpuMVjzAqYQ2C3O19c/e5g61FbwVjLIGfl UfdJtr4lrLGRWvi0OGmXrbpzeSu2jB5ynU/3D7OjtpPvXrH0+JeMahP9NidGOM4gPMD29j xuidHU+JT3rBUvFDXbF8DjZhrAi6QP8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VJ76X1L9Kz2CcLb; Mon, 15 Apr 2024 21:19:00 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 98FE71403D1; Mon, 15 Apr 2024 21:21:56 +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; Mon, 15 Apr 2024 21:21:56 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Andrew Morton , Subject: [PATCH net-next v2 03/15] mm: page_frag: use free_unref_page() to free page fragment Date: Mon, 15 Apr 2024 21:19:28 +0800 Message-ID: <20240415131941.51153-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240415131941.51153-1-linyunsheng@huawei.com> References: <20240415131941.51153-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: 50CEF180018 X-Rspam-User: X-Stat-Signature: 1oswttuk45rg1k88yzom45kw6y1xidmj X-Rspamd-Server: rspam03 X-HE-Tag: 1713187319-707424 X-HE-Meta: U2FsdGVkX1/CWhMzYrBDrU6TcZBD91JmfD3RsMw8Z+8ZEz/eaPGBcRyJU8b60KJI4YxVbzb6P9FgBIvepbWtiUP/ysKN4J9QbwM9qJzJLn2E+WOa+U92Errd6FZ71MYmqrJgjX2jH7zFrf96nE5U360D/J/TsodxtjUGQS4aPdruZtp/4TDbegmqu++q0NQ1+aWZqjTqn7iFCe3qaT0yFmmBLfATf3ifO1MZQbktJeqLoUfkyID9pX6PzxGylagyDRaZMkgjAjaaDcodmcOLXyOxR1kaNmSD1YUY/ubJK9GWqIhQgdqnKzpK7RefwRff0mVCJtlm7ezPkPbYRYhrssNy4Pp8WHCwly8glNKwULn31ajpOUehElryj6concuDFVkT8Qq4kx/oxxv6sUVRXVRk2VNjkDMZHQJ6dDuMjyE4ZfdyLpVtnX9xWEwoD006VQPBv6E3hRDLEJnyb2gK6awgsiN1x5vWP/df0fyT3/RvB4xehIxeTfAb0SlY21ru9hOz1TbeNwuFEaSBVsx1ciNtIfqKaE9UbCwF3aBQZTUE03PmjfhZCp4GxvDjcjLo0lAnJ4E6kpSWL37AYbPL5ANH2YkAkEJmIDb3t63n/z0+OLQVZAHLc5HADnd+74MgZJ8CIqtiLdtYirIxgMGpNWcY9cFi0nFxB6lRc0TjOP3nViGUuSz2jrZS7/ZSC7TwhCpCVveipsSwo5R5kbuKIo7mTDQei4kttz6FnM/+BxRBewoPzSLVPMfvIB6kJCf4BYE7Rt1ulCwfU9S0xgd5n/8jkAX6o+3nivPCQv9CsxD1tShnUAWW9kJxhnuXZrw70nOgaDaWn/r7o4JdSWssforRtyKAZSp5dn2BnDR0M6on19UZRJ/nnfVwVxTN5SzLi0p1C91VoMVYY5ID4iTJBN52di7jF3sGxkP/yyZuXDpDqxAakSm7tmss8IwrOIfbptOnxLY6rKao/fF72Ks RBAATPOI z6gVV0XME6EMRnd7oVSHmqZIkXbj2MaYpW41oyfNcGBrpUgXlj4XNcTNGubbucMNuBXnpdYske5I/A+c4fTZkKP/B1VlMn1+YyJNzcTMrdNwygz1aYB4DuHrnHV1L1bt8xeMbUVB3rvEkbz6Naiy7/hw/PNuDV9uBeLoG2GqREvXiFzElR3j7DCZ5MR0HGzeHibgKvTncRyRpPfyYS2pTESCU2tOXS/4mbjkH 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. 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);