From patchwork Tue Jan 30 11:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13537369 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 D6C3EC48285 for ; Tue, 30 Jan 2024 11:38:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 507476B0081; Tue, 30 Jan 2024 06:38:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B7566B0085; Tue, 30 Jan 2024 06:38:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 359C86B008C; Tue, 30 Jan 2024 06:38:09 -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 25BE56B0081 for ; Tue, 30 Jan 2024 06:38:09 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D519F1A07E8 for ; Tue, 30 Jan 2024 11:38:08 +0000 (UTC) X-FDA: 81735778656.08.C14098C Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf25.hostedemail.com (Postfix) with ESMTP id 01095A0007 for ; Tue, 30 Jan 2024 11:38:05 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706614687; a=rsa-sha256; cv=none; b=jQVYNFumiFDwHwE11aqEkcOfFxdkeG2yBQxSJYnLpDPU9zWHuwhSIedqNDodKoNAltBRs5 ECVPmtxDB3kwFwHXJTLA4Z/Lii45Q8YkneEufithk5ceIpNjhxbc5c3KH2Tu86m3rsLHKk n3dcOP9J8yhap3u7gjPNIqsvHpTJZG0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 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=1706614687; 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=Nx3W3AbRHATaBu6Xj/hr+ojBJlJZiofIFCqrk92OYE4=; b=hWaXBDbZkquA/vDdcMZTrB1g4iEusZUOJUcZzKTKrHCLk8Xn1zJIksJhepF72W2MgCQgqn KKH2ke8sYPGr7g6X6nmwLZHe+b6UqSbrvhsAUh5SVY6gw19x5X6N0LgCQbQxR2r6NkgUCm iEv+afnp0vaJV7YAlIJWoFH5wFAzSHQ= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TPNQx3VyMz29km6; Tue, 30 Jan 2024 19:36:09 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 19FB01A016B; Tue, 30 Jan 2024 19:37:59 +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_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 19:37:58 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Eric Dumazet , Subject: [PATCH net-next v4 1/5] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Date: Tue, 30 Jan 2024 19:37:06 +0800 Message-ID: <20240130113710.34511-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240130113710.34511-1-linyunsheng@huawei.com> References: <20240130113710.34511-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-Server: rspam08 X-Rspamd-Queue-Id: 01095A0007 X-Stat-Signature: mutqbyrgwthaadicjynq3qzn9ubdggmc X-Rspam-User: X-HE-Tag: 1706614685-475362 X-HE-Meta: U2FsdGVkX1+YAjCeDHERHAlJSw11K2Tya0cDe6JUbreWNSjEaMI50+IJX39YWjQv/X1l1chk2rHbg2jbNnM7UBeAU2mN7JXnGR7zh+9kMTWoQuZEuwUqucdSN8FTsvcg9+Vwpf6a667O71RgQwZKEA2G4BznVEBljBWFidp5lUx95V02fSt6FXjeWE8O923Cu07zQTVksidJaeZOpA/T/JK+ZLRNByuIGlyvKK8KSCwjBC44DrXaSxOJhQP4wesyR4OTBtEqs7U3xxAvagtKTHr3MVYGPf/rQUVIW3owUfrpr36BWiTyRWG+z9kzN95+zuMuo/cr7Rp4flo66nWMOpavk9FIE1MhwKZhPFdvKnT00qQafC0QqyZTcdWAaYFFP6Scsex1wJMhWSOtsEFWHt4F+JyrZPaBvYemWL3dzdm4ZbG1Lj+4tCBkiNfsPZYA+mEhE1myrfDGE4Bnppa286MLc/v3+E1hJXjRqgjvuq/tbJ06y9BwSLf/18sHUk7qPI3QsZ+0IPABLR6YCbIoryHT2Q1CFzy9yG/tVyveoINxmrMQEHbqfjKHAXu7Y9iZXcJlESofQ7U20DbzCNt8qY3XeAeK+NPlQ90S6l+I4gnwmZHrlwyUg/aixdaDvqxdiVrhwko+BBeUFTLchLboEbCtSANeYiilD4T5LixQav0VGo3zSURCpD0QvbFVWAqhpQ5TKwBwYT7DKEEDR1W7GPtDALBwgjX3a59XFWxD2P0a/3NDoNI/l7wiDMjU9Wm+ylcHoXC/uNf4fpIuyWb2jfMpI5Q4HH3NSCptSlu9WLGJu+CcvT7ZjwaLZzphSzbRRGUIHT103RR4lxyDX9Gm8mHFYhreaFCjWxFWUEdh+Klj9kS7dWUT2qgkM2hqFD4RBlWqdzO6z24e8Lr4C/IJVIKgw/6+qLxTxrCFrj7cOzT69Gp0nSafIguiG9ARVNKLJwNy+sifRRUSg7134o4 wTQT/f5d A4yuW7vQbyMBCqVJsQ+VJ9lpRBQniUgDsjovJApbAu+luG3RWs3qYmG1ZVCMVUlVhEhHxhyhrTfyBoVy8O1sKLyw/b5LWvXPtZG+2ytVlPJaQ/3JoiDKsWmtUj20MAd9lV7kuEAs/nzbIpDHH2Tu01eQ4ISosND9ZrN5oXnvHNu4aH5djtQt2LYrpFLpD/W6lWEqnls2Bt/VFCAC63BB4zHoKI/oyEPvWk8BsDWsGxpYLLjpYEbMq3uJ8pjGo9Si2IAtPQcmRd8jUIKc4HwPjHExF8uhwtQaDTKSk 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 | 6 +++--- 3 files changed, 18 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 edbbef563d4d..bc8f3858bc1c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -297,7 +297,7 @@ 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); @@ -309,13 +309,13 @@ 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 Tue Jan 30 11:37:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13537370 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 25254C47DDF for ; Tue, 30 Jan 2024 11:38:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAD896B0085; Tue, 30 Jan 2024 06:38:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A5E576B0087; Tue, 30 Jan 2024 06:38:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FEB36B008C; Tue, 30 Jan 2024 06:38:10 -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 7C5696B0085 for ; Tue, 30 Jan 2024 06:38:10 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 52557406EE for ; Tue, 30 Jan 2024 11:38:10 +0000 (UTC) X-FDA: 81735778740.25.12AA08A Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf30.hostedemail.com (Postfix) with ESMTP id 8271780020 for ; Tue, 30 Jan 2024 11:38:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 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=1706614688; 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=e1pknDONHysj+m9kim1Vp+hm/0LOKTlssTV6yUUkXBs=; b=xmdqg+1yRmlgNPnUSdpHdhmH1m12ow/I1WgUyqM96YNWukxhbhrbaZSba4XVM/F06oOZwV X7MhFz6LnDFz/cpFpMM/mTtbe2d4IDPI4ILg5wVLUJoDXZvHxvMmj1Fb54e+eUn9oGjpFT 2LJ7WCu6H9AAd6BDmWpN6YZqHP13Kro= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 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=1706614688; a=rsa-sha256; cv=none; b=OoJIYlQ2F4dyGiZRar4rDKFZsQyRk8dudRuZnyLLvfAgJ0u0PJRJuLOtiWE8phjWJR5cTS G1+Q8SVyVjss8Iu36kq0R1vP7U0ch1VG7tpicQnMVIwFm9vk17vJIyAcn3M7wM8anRXfX5 PYFCc2cwbaOXK/sKOBMIvguLdlZHS9A= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TPNQz0vJ8z1Q8H5; Tue, 30 Jan 2024 19:36:11 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 1039C1A016B; Tue, 30 Jan 2024 19:38: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_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 19:38:00 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , "Michael S. Tsirkin" , Jason Wang , Andrew Morton , Eric Dumazet , , , Subject: [PATCH net-next v4 2/5] page_frag: unify gfp bits for order 3 page allocation Date: Tue, 30 Jan 2024 19:37:07 +0800 Message-ID: <20240130113710.34511-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240130113710.34511-1-linyunsheng@huawei.com> References: <20240130113710.34511-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: 8271780020 X-Rspam-User: X-Stat-Signature: dc1qfadzr8u8xdbna4ae1zq1fgbh7djk X-Rspamd-Server: rspam01 X-HE-Tag: 1706614687-578803 X-HE-Meta: U2FsdGVkX1/SsZOgyIf0a1a+NvbjHa5DsCnn2anUemkGqlxbj25p7rvxSuSHrfe1DBJ4KwCvDs280+Bixc3Yt3/hvAqVQm97MmJNahq8nrhosSLU8p34HwzbUosGF+vbpv9LjXLhJOlrb4sMAx6B8MX20fIoc7Cj/Kk3jZk5s2k2kC78JMVrWcNzm6dFBItzkBKPmXzxRKc0yzC3xIwAan0l2TY/KCoV+E7Qu4tibmmOwqsjseqNNU8EcGAMWsMepyGbe8KYtINsmCfBC0dhUJbciKPkz07rDPSEOhxuhdKuf6apjM8g7nAOUH8GmR3fS7Qk0iQe5GOzTAMzcTWMv1miU6AJfiZJ+9Vh02kLFLyKbfSjMR2v4XVFumXJjmR2XtM+rHEfDxlX29X3qYybLNs2de6tTBeGXnDsMBY2NC9B98Yw3T6wz4bxB7kC/d7aolrNnkt28A6xhlEHlRvNLzLSZdrCl73S4ku3xfQF3yANbLit05/3neWF8JFYnddntdH2dBg1Hyu2aTKajsHsEhOlMSKiIheu2xPAVncOSEjccTCnuJgmvIs2Yq2FNBdNkRFoKRBtqLMu83Y6y9dKDikO8mQOPiXlQBgWTF1hTc2GG9YTj4/brjT8kuGSCJLNtatZcAN/Ifl1Sn8br1Iggp6uOdzJQnl04BGVxSrhXk4TT0AXF+9d7t0us/eljpzsEYsvZkejW0VwpNmL1R4y3siFRAk3aIpICpIOprG26p2EUinYu6nsucCDMieFS/Wy9ZPXzRMUgZyofYbdtGKWVgi4but3F0Lo+VJB0VFnNY/ON6fl3tX79Ld7I6Excm1O2VZxpQ/FLLwoohoIeRMbmQXwKjWKhp6AWJn3/VNfVX4U/WcX+QuQCHZTWa3UyIsCzZS1T2AzHI+rw2l/mNh0oTeCYQjQt7J1wPkFTwrzU063E+JLVLxFH+zPYFJtg0Iu0VhVdH6tG3neXcR50lk Jo58M8xt 7olob3S3NotMZz2e2VSS8SMfT5evwEahwgF1Xaunc652bnOck3i/AvPk7RL/sUvPhCCH6TT8QDLaK9Se4vyLaPjrUzBrZnZXLyiZKtH/o0A/9oUFmDRnCw1SuPPVnxQCO/ej2BiXMKpw3iaP+huY7xmKZpwQzWCg9Ma66f5CAghVm0PkJX5KMW36oQXJImT83Ro8j+75gtlupCTBkGSo7WWo/38EUr+gjv0eCUtUoPhYjxdE4CZSMz7+1klNwZ+SQmoEmkaSms78JdJ/woYssFQ6HMiKBdKCPNU34WQ4uJq2UVuoG3P3afAHhNdWZbNv+kJA5HKgIi/SeI8/5nYhTfOlkXw== 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 implementions 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 skb_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. Signed-off-by: Yunsheng Lin Reviewed-by: Alexander Duyck CC: Alexander Duyck --- drivers/vhost/net.c | 2 +- mm/page_alloc.c | 4 ++-- net/core/sock.c | 2 +- 3 files changed, 4 insertions(+), 4 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; diff --git a/net/core/sock.c b/net/core/sock.c index 88bf810394a5..8289a3d8c375 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2919,7 +2919,7 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t gfp) /* 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; From patchwork Tue Jan 30 11:37: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: 13537371 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 0C504C46CD2 for ; Tue, 30 Jan 2024 11:38:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE3B86B0087; Tue, 30 Jan 2024 06:38:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D43206B008C; Tue, 30 Jan 2024 06:38:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6FE26B0092; Tue, 30 Jan 2024 06:38:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A69786B0087 for ; Tue, 30 Jan 2024 06:38:11 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7FAD71204C2 for ; Tue, 30 Jan 2024 11:38:11 +0000 (UTC) X-FDA: 81735778782.11.2DA08EA Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf03.hostedemail.com (Postfix) with ESMTP id A286120015 for ; Tue, 30 Jan 2024 11:38:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.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=1706614689; a=rsa-sha256; cv=none; b=R+QwOlH/NKs7vTUvS+0cJmJr+MlX9U+0iWcYar2NhVCTKql7SsXUb5WkjQmIynqYwvhwvv ptehWD6jK4DyRfHsKy6s2aw+le8bYuxtmO7hDuDFYeyAu2mruXZgBhkx7gEP3cSPMFd/7C AcEMnvVq8y/KqdIgjn3RsoUevmpUSfQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.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=1706614689; 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=LFeLLnJaR3JtjOxpUpdms1bffkbapejcBiKMtBdfGb8=; b=KPgjKqs1967IhuNj68xlw8v+ASmby+FAmkjTA8SadxX9XZ7dOFIIIBtgTzsQQybtgE56G2 hNi/et/pZzFfQN6SXQqP4M/iYTQekM6hteCP7iq9SuIUUkujEEFfCcES0DDua1gae5BJIe ShhWX34WlpaztxWlmypYKVSGfmjeHvU= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TPNR22P6rz1gy1H; Tue, 30 Jan 2024 19:36:14 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id B48431404D7; Tue, 30 Jan 2024 19:38:03 +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_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 19:38:03 +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 v4 3/5] net: introduce page_frag_cache_drain() Date: Tue, 30 Jan 2024 19:37:08 +0800 Message-ID: <20240130113710.34511-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240130113710.34511-1-linyunsheng@huawei.com> References: <20240130113710.34511-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-Server: rspam08 X-Rspamd-Queue-Id: A286120015 X-Stat-Signature: oqc4qczey1fchep7o1x4rnxp645n616w X-Rspam-User: X-HE-Tag: 1706614688-751380 X-HE-Meta: U2FsdGVkX19pcoNpluN2ALxZ9xntrUPdmqAEToCa89MZ2RCLu75fT+C356/GmsGiGcmx416somse5jEaY0IcMDvQyv0HP/W3YvNyjRoaKVQR71XgiwFGezAtV52ZCjBlyetLKSkSdvlDxa9BrShYTev4I91qsPBEU6+5gz+Gx9Qjla3GxxSuNbWvE+w4B9Kex1FGy3WkGn/vKUT43SEBH/NVKxUPqNZ6v0SNRGk0TqIruLK41yUy9RjXOjKpSctOJUkdKz7WsYM/Qz6GAGcUgCU0x0izA5PcoG3qRN9gE3d1OWnNv+WfmAOjskzjXhc7r4z+Q5FdAtiWPt5y/aOZpIVHD1RCg1xnV39hLrYHKGZTAH7jlK/qu8XY2KrUgflYsKljuOUNvY0tkasDULF1845ShWYNEoZw3KGoNjzilPv0V2CYlYLLoXliFvC+sZtfMYt3KSDHeV3Ooqg37onAgu2v/x78bjZdgCMakd6IeXHnVaFY+0D3vEyDqsyLBA/6Z6ef/9UtPcYM5dheFXsuqxjcGw9RhnO/ztl35xUHBodGXw53/k4/JtlHsXLqYDNPS0VdElnox53Roj8iohHZY9AO+diYgIoIYT0JEpWGGOTdCdGbd8Y23QmTsuIoRcGVLMLIGV8Qh124fKuPEL5tOtW+B7MuN9LulTBa61CM98WziBMS/lDcfAln5dV0JFmFD41TLekbvusPYUG7uwqCwlNAAvNUNPCuRpefK5wttyaLyRwGuUtw19/sHK60RPGZQLeBrMIvgvU/Z1qD6Hv4H3A/MRNnlBhCGlCph6KqqtvhyJpbCumxt6FsBnppABvPSPn1NRf8XNUaXbabtWWov+rdee4RpML+ynJkgGKPq9+qVaVfgBVPqHfOCO98YW8OeiUBTUCsjw2WGK8GfstSN5FAUHtZrayMYZiiLAmdDyfUGnOUW/L1sp3r+jEZ1RbRVj4kkDUiIjfxUgYqRDY bk5wcciF 8R8JAuL+OPhlNH9GeOPjt4vH7rMrr3ClmwzIJuobh0exiJ1FLrzIpU4wEET1mLRvudAxhEct2pSyqk+82dgm+Yd5P1Kj737bQ99Gzu9AZ7XUm3goefnOYcLzM/ZM/8Oo6/4Ct0Wfo0jynyCNNvas/IlBuEbH8A965FuwpbSny8e8bPONiwr8mmxK4FUDMIyXfAO1ngXzAhfpWC0oSxlNFJZYuAUv9Lri/TmhMekTW3T2YYhSRbYZfPA3aWpVonER92dhHu2t/k8j+9hDYO1i0k4ekm4QTxz5/OO2gJmLT1P5lHt36X7OMC6jUVLWzYff0n9DLwb4l7eVsWPAHZmfEd/629w== 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 d058d990532b..22e1fb9c9c0f 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 6a1e6bb80062..56224dc59f17 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);