From patchwork Wed Feb 28 09:30:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13575102 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 0F547C54E41 for ; Wed, 28 Feb 2024 09:32:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A10256B00A0; Wed, 28 Feb 2024 04:32:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0BB6B00A2; Wed, 28 Feb 2024 04:32:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AFEC6B00A3; Wed, 28 Feb 2024 04:32:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7B4786B00A0 for ; Wed, 28 Feb 2024 04:32:03 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 568C680F20 for ; Wed, 28 Feb 2024 09:32:03 +0000 (UTC) X-FDA: 81840696126.26.2E95314 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 716C340010 for ; Wed, 28 Feb 2024 09:32:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709112721; a=rsa-sha256; cv=none; b=iBVkjZKiBrA3jeV+yGl6JJIzjka9GNc5zeFh8xOioWaDLyCwj2+GVK3UTo1GAFAlXo96rX CcXOhMEQNOKYxp2PMt/9iVD/bN3hW2bW1HAEG+zvdA0RsVN/wbvsjev+wwNzHQaJx4G3Pb IakyijCvwD6PJ8Z5tex4Zrv2NCL+S60= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 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=1709112721; 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=fsCym9aHBeJvlUtY57kt8x1IP0isH1vXizI9Lm8sOsM=; b=BN0Kp/KidNZ9EeZ/GTm/FYbIn7icXgUqe2LFteTWUdZjRwnXQqvNYDihxX7kPTuA1YfLK5 8P67mwCegYmoZpssgfM36+GoNQtwmTfbRzPMInT+Ec9A8hSnEkqxdYEuqZ6EQvViUehig+ 3pqhbGrRVfnfsUAJAqqTU3iN6F5VHjo= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Tl8HW1WW4zqjHD; Wed, 28 Feb 2024 17:31:19 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 5F7F01A0172; Wed, 28 Feb 2024 17:31: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; Wed, 28 Feb 2024 17:31:56 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Eric Dumazet , Subject: [PATCH net-next v6 1/5] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Date: Wed, 28 Feb 2024 17:30:08 +0800 Message-ID: <20240228093013.8263-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240228093013.8263-1-linyunsheng@huawei.com> References: <20240228093013.8263-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 716C340010 X-Stat-Signature: w8dp3kzhycnpgudwhknw1f5necuqqigj X-Rspam-User: X-HE-Tag: 1709112720-405809 X-HE-Meta: U2FsdGVkX1/AZADzXxo+SUN5InTyl9FjnEsQ9WvdAe0Y3tsg8KSIbqHd36CpmCBtqIMzzWgwW3snazfv4LenpnTH25bnWIMK6UgC8Osn+WcHzgQIjVjmzmU7d06yd8S4R9UWH8jaXxOniQnfvWAcNkDO14eW6sGqwZHi5sZ1OART/Z/+6OSWZ5oy5eXbQQ1ZW+WtyrcOPkFaw/kpBpwTz5sI2mAGWHuqck0b+on9GywYtdIIj3PUWY+KOc1bFE0OKL2DtzSXUNLCwH11adPk8HnWqNYqqgLmTKpA/w/XKK0paGPrLyNlb/CTQY1bdPbjex4fjvZLbrF7HmxuiOH318IFuWujX5jFnXgFJ2loAYsgV6rW+rQTFdaKXpnntNZfpe5FBsz3I1RFCdUaN/mk2nKvQZirVDem1VhyzMpgS9LyJbbOZ6KBJVu0ripluo2wWFxIp1P37eYynymGmHm+gKOy+klp9/hBUfzHQBUaIaaP9R+HyxDvAy3Y8f8jrwaeqUCjXXGfIyXqdWgq0qoy1heogYPRiGy/0Qs+VvK+9GX7zgbQRkgKS6ZZQY2NFJFOOQVo2rg0BBA/+KfLYVIFOqhjUOQ5/XpNeoonWHG2tLzmPRyDwqjHQAHo9i4Q/rTWy48YxCd5UVQxettU7Xlx/lsurEuUQNu/nxgoP4pMPBXfGFtKqaAkunEXRHm7I5s1DHeYmS5KG3/BS174mDkyz1wY914+5hkTVAr6EE7E8WuM+9OaHB7ZvG+i3JL9fzuUtzAnkVNQP2+pcXmVsV3GooeKCJalGeM899PdCLPvD4gTpNoIGDGHxU4e29LtmcnNbn67wpYN6eeMT03XHmm0AUlMl36dd+fLtES7wkpSH3PmxvkgVa3UHYgwPCtxyN28zawSXnldKCEA7Nwkwphm0fwhZDMzykX6v6IhhbCzkZYDDmz08tVmjnt+11t6psXgoabGN5Jv+WEchWoGfrE V7A== 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: napi_alloc_frag_align() and netdev_alloc_frag_align() accept align as an argument, and they are thin wrappers around the __napi_alloc_frag_align() and __netdev_alloc_frag_align() APIs doing the alignment checking and align mask conversion, in order to call page_frag_alloc_align() directly. The intention here is to keep the alignment checking and the alignmask conversion in in-line wrapper to avoid those kind of operations during execution time since it can usually be handled during compile time. We are going to use page_frag_alloc_align() in vhost_net.c, it need the same kind of alignment checking and alignmask conversion, so split up page_frag_alloc_align into an inline wrapper doing the above operation, and add __page_frag_alloc_align() which is passed with the align mask the original function expected as suggested by Alexander. Signed-off-by: Yunsheng Lin CC: Alexander Duyck --- include/linux/gfp.h | 15 +++++++++++---- mm/page_alloc.c | 8 ++++---- net/core/skbuff.c | 9 ++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index de292a007138..28aea17fa59b 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -312,14 +312,21 @@ extern void free_pages(unsigned long addr, unsigned int order); struct page_frag_cache; extern void __page_frag_cache_drain(struct page *page, unsigned int count); -extern void *page_frag_alloc_align(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask, - unsigned int align_mask); +void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, + gfp_t gfp_mask, unsigned int align_mask); + +static inline void *page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align) +{ + WARN_ON_ONCE(!is_power_of_2(align)); + return __page_frag_alloc_align(nc, fragsz, gfp_mask, -align); +} static inline void *page_frag_alloc(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask) { - return page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); + return __page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); } extern void page_frag_free(void *addr); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 150d4f23b010..c0f7e67c4250 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4708,9 +4708,9 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); -void *page_frag_alloc_align(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask, - unsigned int align_mask) +void *__page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align_mask) { unsigned int size = PAGE_SIZE; struct page *page; @@ -4779,7 +4779,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, return nc->va + offset; } -EXPORT_SYMBOL(page_frag_alloc_align); +EXPORT_SYMBOL(__page_frag_alloc_align); /* * Frees a page fragment allocated out of either a compound or order 0 page. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1f918e602bc4..43d7fc150acc 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -315,7 +315,8 @@ void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) fragsz = SKB_DATA_ALIGN(fragsz); - return page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); + return __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, + align_mask); } EXPORT_SYMBOL(__napi_alloc_frag_align); @@ -327,13 +328,15 @@ void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) if (in_hardirq() || irqs_disabled()) { struct page_frag_cache *nc = this_cpu_ptr(&netdev_alloc_cache); - data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask); + data = __page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, + align_mask); } else { struct napi_alloc_cache *nc; local_bh_disable(); nc = this_cpu_ptr(&napi_alloc_cache); - data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); + data = __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, + align_mask); local_bh_enable(); } return data; From patchwork Wed Feb 28 09:30:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13575103 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 96993C54E41 for ; Wed, 28 Feb 2024 09:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1113D6B00A3; Wed, 28 Feb 2024 04:32:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09AF26B00A4; Wed, 28 Feb 2024 04:32:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA44A6B00A5; Wed, 28 Feb 2024 04:32:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D7A286B00A3 for ; Wed, 28 Feb 2024 04:32:05 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B561EA140F for ; Wed, 28 Feb 2024 09:32:05 +0000 (UTC) X-FDA: 81840696210.04.93E1F1A Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf20.hostedemail.com (Postfix) with ESMTP id 6A44F1C0006 for ; Wed, 28 Feb 2024 09:32:03 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709112724; a=rsa-sha256; cv=none; b=NTJ/jf07nnqgEXpi03YycqRbXyLQtchWqUJ+LyU3eTHc4JR+1t/uA0sWqff+TmhbAH53q/ pv+V1zYmqvJw3WOPkCU7Sa4QGf1HTUuQAOup9NoUHUtEpfBKC1wahoHEaa8KmKrd0daFWu OYMmcOGqExzIJa1PPbePBBYo/+vzi7E= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 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=1709112724; 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=j/1JfrnawbAOp+6kwWbvQ2Ur8RFze5N0GSOLfndyATo=; b=FV41AfsAmqpBmYJsU/RMhqkK9FSF0XMSfB8fL3SSEM3GR8rG/WT0f1CL5cpgNrMKQ/99q+ uNEEpZZIGI9OfSuZfvf2BS0R+n+H7V4byGXbq8wItdH6u+ti792ZkKc6Ddhg/Y6wmxC/u6 rMt1JXlxPt7rwvXDvzX2b0EXAS9pESE= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Tl8BW4Jfyz1b1CP; Wed, 28 Feb 2024 17:26:59 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 9A90B1A0172; Wed, 28 Feb 2024 17:31:58 +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, 28 Feb 2024 17:31:58 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , "Michael S. Tsirkin" , Jason Wang , Andrew Morton , , , Subject: [PATCH net-next v6 2/5] page_frag: unify gfp bits for order 3 page allocation Date: Wed, 28 Feb 2024 17:30:09 +0800 Message-ID: <20240228093013.8263-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240228093013.8263-1-linyunsheng@huawei.com> References: <20240228093013.8263-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6A44F1C0006 X-Stat-Signature: x5hj3pmnpg65e4wsdqewbwizpyw3zu6i X-HE-Tag: 1709112723-532483 X-HE-Meta: U2FsdGVkX18fDFGN+gjdnojKG8FvYNExf06kDyVOJUbQ6wJVJKlIA8LDUJDUFVgqMFZERGhg31SpUWiF1OMq1dTI/1M6goZo+77yJNFL+rkcFs01ahTo/BKgbgdp6nb8xo92OQsqBmbyckRKdaQrMSK2eQSN8xAoUx40LUHDB06LdZ3gRLh6+nuqzV2d0HSvV6qwFDrgD2SirKJ3/WicZ5SXamkm6p9Z2bLNzYMYiKTNVGKFteccuB6vzwYUBFVV/RZCtUmctLIUiEOyBL7HzVMKAwcyUkEkPx+MI+N4GHG4bv/f3Z+WSY+qcEwr0jPZ/MHVh9MDk6894UWiDwhyJQtAmUr6UyFVjsL6m6GdL3nK570VNqxSF7aBS/tx92W1KN5d/PqDLb6pfQRacFFZSre9TvjOIM3RZHrlak6MhAF+wtfGVrrCh8Ex9v/bX9Us5zdF9a32dCELdJ4T2ETeMspHQ2e0Ey28GhU0POxNPNxDCk1jL6lyIEZko6kSKssvkEBTU29j+XvyKL27GyE/1LxtAPJQjoYrM3qlj6y4WM8+BDKNUJOQUbnjC7c4nvuJ2X3LNe9q9EcAVIRObw70NAYNX8aQIBmDpyxlaZTtLfqIqvx6xKHop9WoO5O4sr9N5nFmut9tT0X7YA8nM+E7JuMBOFWImCwOi9ZH22LcBVIdbbLlGhkH1gU2K+LlDUZFV49WOwG7ptcHtY+aT0wpmFb3hSMWMgzxZ4PLXc+HPvluC1ACak0aM8nuiuee5Gd+24NqJetcdDAvwwRuahHRVzQ2gXwnCsbmUJpaDfD0slknlYr/dLdVkjdyYr9wqKjpV7gBXh9rz0MkPDdDKNsxhZrGH3aDd+XnDOlBmhxUzb+t+f77LQmRRN27Hk9ZkSZPvC2r0G3Ce6SzBweEoJBcfqOxNcpPqfKdfamjI+0bjoe8rOW+7kitZq9iCfLTOswOKHOxEVOeBSjuuaqBx8z nJQ== 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: Currently there seems to be three page frag implementations which all try to allocate order 3 page, if that fails, it then fail back to allocate order 0 page, and each of them all allow order 3 page allocation to fail under certain condition by using specific gfp bits. The gfp bits for order 3 page allocation are different between different implementation, __GFP_NOMEMALLOC is or'd to forbid access to emergency reserves memory for __page_frag_cache_refill(), but it is not or'd in other implementions, __GFP_DIRECT_RECLAIM is masked off to avoid direct reclaim in vhost_net_page_frag_refill(), but it is not masked off in __page_frag_cache_refill(). This patch unifies the gfp bits used between different implementions by or'ing __GFP_NOMEMALLOC and masking off __GFP_DIRECT_RECLAIM for order 3 page allocation to avoid possible pressure for mm. Leave the gfp unifying for page frag implementation in sock.c for now as suggested by Paolo Abeni. Signed-off-by: Yunsheng Lin Reviewed-by: Alexander Duyck CC: Alexander Duyck --- drivers/vhost/net.c | 2 +- mm/page_alloc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index f2ed7167c848..e574e21cc0ca 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -670,7 +670,7 @@ static bool vhost_net_page_frag_refill(struct vhost_net *net, unsigned int sz, /* Avoid direct reclaim but allow kswapd to wake */ pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | - __GFP_NORETRY, + __GFP_NORETRY | __GFP_NOMEMALLOC, SKB_FRAG_PAGE_ORDER); if (likely(pfrag->page)) { pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c0f7e67c4250..636145c29f70 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4685,8 +4685,8 @@ 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) - gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | - __GFP_NOMEMALLOC; + gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | + __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, PAGE_FRAG_CACHE_MAX_ORDER); nc->size = page ? PAGE_FRAG_CACHE_MAX_SIZE : PAGE_SIZE; From patchwork Wed Feb 28 09:30:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13575104 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 AA820C54E41 for ; Wed, 28 Feb 2024 09:32:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1ABFC6B00A5; Wed, 28 Feb 2024 04:32:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 15CC16B00A6; Wed, 28 Feb 2024 04:32:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0249F6B00A7; Wed, 28 Feb 2024 04:32:13 -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 E66BA6B00A5 for ; Wed, 28 Feb 2024 04:32:13 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B9C92160F01 for ; Wed, 28 Feb 2024 09:32:13 +0000 (UTC) X-FDA: 81840696546.15.CA00D74 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf23.hostedemail.com (Postfix) with ESMTP id 84702140004 for ; Wed, 28 Feb 2024 09:32:11 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 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=1709112732; 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=gHFfDnJk45UEHuXmxXtzvJNbjxSIT6xCDWqw9xVfWpM=; b=yXNjJe7y2IxpSuwpZIbOEVMIKyBUfM20z6k8aggmIXlyw04uc+xBec3glYH35Hc5NIKzs4 R38znEcwmBOb/A3tfpS8HdPhLw/QrgXla0YwFrOvc+DiXOF0CToW5nWNZZERfBhCgTaeXE iKESnNNhRnbZAnLjKWVQDMfUoKhdjTc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709112732; a=rsa-sha256; cv=none; b=leajZO9xq4cLsgevBhYS69Iv8xEhaWCkWDnyFo94ofAPX/GfkEux0pYd3xYjCIrelKNOgF UbMHpZ6u5lg090tFK1StTZEb7Nbd9zdBh+LuheNfnwwKPHVDXB1b0etyl5T7hTMfw8Pe9h DW8FcA4M/Ge/1o6toxxJdZy3aD6Cne8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 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 szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Tl8Hc5Rb5zqhtb; Wed, 28 Feb 2024 17:31:24 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id E74F71402CC; Wed, 28 Feb 2024 17:32:01 +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, 28 Feb 2024 17:32:01 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Jason Wang , Alexander Duyck , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Eric Dumazet , Felix Fietkau , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Andrew Morton , , , , Subject: [PATCH net-next v6 3/5] net: introduce page_frag_cache_drain() Date: Wed, 28 Feb 2024 17:30:10 +0800 Message-ID: <20240228093013.8263-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240228093013.8263-1-linyunsheng@huawei.com> References: <20240228093013.8263-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-Stat-Signature: owamxjudtyw1wgsgq53b9atqcfgp66a9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 84702140004 X-Rspam-User: X-HE-Tag: 1709112731-410956 X-HE-Meta: U2FsdGVkX18XExgkm2kmzqVfPV3EtvUAJzF+8hjHa+Zn+ghyQNLPOf2KUnYNeyg/5AbZ4xbZGB24fMN/U3cS9G7eGQ6y9CJrcsNvdVNlO5IDPdk32nVO1ZLfv4IElXhJwbDpwFz3CaDy8mg12dYe40LF14xB7CMwjeTcURWdwcKznXrhzv+mWULaE1RoBEMmVmvbNqRbHQfwwtyu9BY9/5wmiAojZQggi5XWQacjJ6psTG7RYJbnc2VcPZMYsJBnALNbsy1dBydHl0dwUxCsKJTYtvQBYaBEOttq+uo2js7cfGyWAh6KiattLSt7ND89sjr2jg6pN7dwLANUkBckS+QL7Y8FMe70ZQ1aHYj3ZxlEXSCF7qQl6LYK94TSTxR+lh6oUyTCFqKOuc1adj5D0tdBKSR1/gWNIe13NbDvgLGyJCxwYsPC/fX4hcMTd1atuh6srqXX+S/TdfALPxU2twNOKWkz9mN3FBwgO7Uv2SYcKU5ugVGLhOzNIKJGEQQnRiN7hUFdMMtisaYO+XoBHAymWeHhK5MPuCPdB6WQFU3YFbrfu2AKw4vgJGLbQHr96FV7WSSZF8uNHFZw0PaF0feH9JPkzrlKR4VNd5gjaLcM9eLj0W5n3myQODiD1yaqJKrxSTxvfhAXyklLG6qPja8dcH+EfoTP373spg32gpO6LyNh5DDK0kkvP1rXFnaJF8QCPzMMl5rRXS1uc6CZVq3YboBQ+Vo+10cN3IwUyFLpagrSEzR9lh0fPNPAKzL2STkCjNHKptqUq+j7FQB1gfEk8PwViK8Y0ZnDZ/D1IPlV/brpvNS7Pxdw+Se69AwRtdLgZnui2oWX1Feu+3mjUaQ3OULqnsD4UzW+rPKs1v47R9TMcwngdTosIcpyBflSz7Bbq87plJx/fB4UPeOG9DjdBtOhAQPyqAi1ngEkvurUZtlfQSxfXDhHYsnp6lrb08ewqQyJ9cgc5Osfn8v 9Rg== 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: When draining a page_frag_cache, most user are doing the similar steps, so introduce an API to avoid code duplication. Signed-off-by: Yunsheng Lin Acked-by: Jason Wang Reviewed-by: Alexander Duyck --- drivers/net/ethernet/google/gve/gve_main.c | 11 ++--------- drivers/net/ethernet/mediatek/mtk_wed_wo.c | 17 ++--------------- drivers/nvme/host/tcp.c | 7 +------ drivers/nvme/target/tcp.c | 4 +--- include/linux/gfp.h | 1 + mm/page_alloc.c | 10 ++++++++++ 6 files changed, 17 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index db6d9ae7cd78..dec6458bb8d7 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1276,17 +1276,10 @@ static void gve_unreg_xdp_info(struct gve_priv *priv) static void gve_drain_page_cache(struct gve_priv *priv) { - struct page_frag_cache *nc; int i; - for (i = 0; i < priv->rx_cfg.num_queues; i++) { - nc = &priv->rx[i].page_cache; - if (nc->va) { - __page_frag_cache_drain(virt_to_page(nc->va), - nc->pagecnt_bias); - nc->va = NULL; - } - } + for (i = 0; i < priv->rx_cfg.num_queues; i++) + page_frag_cache_drain(&priv->rx[i].page_cache); } static void gve_qpls_get_curr_alloc_cfg(struct gve_priv *priv, diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c index d58b07e7e123..7063c78bd35f 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c @@ -286,7 +286,6 @@ mtk_wed_wo_queue_free(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) static void mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) { - struct page *page; int i; for (i = 0; i < q->n_desc; i++) { @@ -301,19 +300,12 @@ mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) entry->buf = NULL; } - if (!q->cache.va) - return; - - page = virt_to_page(q->cache.va); - __page_frag_cache_drain(page, q->cache.pagecnt_bias); - memset(&q->cache, 0, sizeof(q->cache)); + page_frag_cache_drain(&q->cache); } static void mtk_wed_wo_queue_rx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) { - struct page *page; - for (;;) { void *buf = mtk_wed_wo_dequeue(wo, q, NULL, true); @@ -323,12 +315,7 @@ mtk_wed_wo_queue_rx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) skb_free_frag(buf); } - if (!q->cache.va) - return; - - page = virt_to_page(q->cache.va); - __page_frag_cache_drain(page, q->cache.pagecnt_bias); - memset(&q->cache, 0, sizeof(q->cache)); + page_frag_cache_drain(&q->cache); } static void diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index a6d596e05602..3692b56cb58d 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1344,7 +1344,6 @@ static int nvme_tcp_alloc_async_req(struct nvme_tcp_ctrl *ctrl) static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid) { - struct page *page; struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); struct nvme_tcp_queue *queue = &ctrl->queues[qid]; unsigned int noreclaim_flag; @@ -1355,11 +1354,7 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid) if (queue->hdr_digest || queue->data_digest) nvme_tcp_free_crypto(queue); - if (queue->pf_cache.va) { - page = virt_to_head_page(queue->pf_cache.va); - __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); - queue->pf_cache.va = NULL; - } + page_frag_cache_drain(&queue->pf_cache); noreclaim_flag = memalloc_noreclaim_save(); /* ->sock will be released by fput() */ diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index c8655fc5aa5b..2aa5762e9f50 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1591,7 +1591,6 @@ static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue) static void nvmet_tcp_release_queue_work(struct work_struct *w) { - struct page *page; struct nvmet_tcp_queue *queue = container_of(w, struct nvmet_tcp_queue, release_work); @@ -1615,8 +1614,7 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w) if (queue->hdr_digest || queue->data_digest) nvmet_tcp_free_crypto(queue); ida_free(&nvmet_tcp_queue_ida, queue->idx); - page = virt_to_head_page(queue->pf_cache.va); - __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); + page_frag_cache_drain(&queue->pf_cache); kfree(queue); } diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 28aea17fa59b..6cef1c241180 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -311,6 +311,7 @@ extern void __free_pages(struct page *page, unsigned int order); extern void free_pages(unsigned long addr, unsigned int order); struct page_frag_cache; +void page_frag_cache_drain(struct page_frag_cache *nc); extern void __page_frag_cache_drain(struct page *page, unsigned int count); void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 636145c29f70..06aa1ebbd21c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4699,6 +4699,16 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, return page; } +void page_frag_cache_drain(struct page_frag_cache *nc) +{ + if (!nc->va) + return; + + __page_frag_cache_drain(virt_to_head_page(nc->va), nc->pagecnt_bias); + nc->va = NULL; +} +EXPORT_SYMBOL(page_frag_cache_drain); + void __page_frag_cache_drain(struct page *page, unsigned int count) { VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);