From patchwork Tue Jan 23 10:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13527214 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 674F4C47DDB for ; Tue, 23 Jan 2024 10:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFD886B007B; Tue, 23 Jan 2024 05:43:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E86B06B007E; Tue, 23 Jan 2024 05:43:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D27CC6B0080; Tue, 23 Jan 2024 05:43:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BC7CD6B007B for ; Tue, 23 Jan 2024 05:43:56 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8B8E21A0A37 for ; Tue, 23 Jan 2024 10:43:56 +0000 (UTC) X-FDA: 81710240472.07.36AE6CD Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf13.hostedemail.com (Postfix) with ESMTP id 7654920008 for ; Tue, 23 Jan 2024 10:43:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.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=1706006634; 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=ArnAVatl20FbZa2aeKJZfm/QxzAi+wlsilsoEf/p3FtB1tjR2jD/U3ELnOqOrJCuU2sgsa kP2ngxdtODZ3yhAlKlnhbQPpcNtBTVuqxJnlTBMi6OIYaRCeWmuDrCCdLj5s+oMCDkVPyD 6+wLcmIhaZeMMMx87rVWcey3LhP855E= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.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=1706006634; a=rsa-sha256; cv=none; b=n+3rLHp5RF5zLEfV9uOb590d3ac+xjBdi0qYOSiZMmdbSwXIBjOfACuz5Oc20i/md7bKX5 alvBAJC4vYYIsU+iB/UjRj74rdw8R4pfzNtXjyASoYCUoy7ZiUOpOpfxzbuof2HJrXEAQx xJSSVbtdnZYZAgrWox1HWjQ4R9pYQcg= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TK3Zn2FNlz1xmWd; Tue, 23 Jan 2024 18:42:57 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id AC1F81404FF; Tue, 23 Jan 2024 18:43:33 +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, 23 Jan 2024 18:43:33 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Eric Dumazet , Subject: [PATCH net-next v3 1/5] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Date: Tue, 23 Jan 2024 18:42:46 +0800 Message-ID: <20240123104250.9103-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240123104250.9103-1-linyunsheng@huawei.com> References: <20240123104250.9103-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: 7654920008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: x8gjkib5g6ufdprbg1fosob9dqxesr87 X-HE-Tag: 1706006633-502297 X-HE-Meta: U2FsdGVkX1+2RL/rz48qtTVkbfw4sXNHjTrlfOSMf9mbHhMcbBQ7VDoCenTnQ8MBzmNmBPXZfnbZ8WOA0FYk/2a0YgdgZISUV0v9mMwdnokfhc9NsMwSWvlVts7Or54+VVTUm800SM7VhFvDQDvMmT2iXVjrJctIBXqeVx+HQzjNQmIIEM2WFg+HKh4xd1Y3OeQAFb64SzB0lS92f3ZIMaGfs7mGxk1dsaPPNrJ6M3Gk3bDyGsh7I54vjhGVszieMzGw9RVFU9HhkGNr2EdGi+HziFzjj1ZncnTERhADkNGIobOu1LRfl0jDqP5jEqWCe5sa/NZE4TD7VYMv6la6vO+WFUA2M3F10J+WmABG1xkWkIfKEGdZggZI2OjP2vSxV5uIa4/qAemssStNFDdG3R2kyuaLwrPuw6rc8IwC3wMdNAtUgSrh51NatoXKxe/ol3AA9d+Kpi2P1KxkdZsQfeCwrgcVx9KK097xqj/LFwdJAxFFLTsKzW9aIvhRGYQFgOl51JirfBGc8OmirRLQno+MeZr0HY1b42YQHZknCrbIl7zmx9m8WiewB3aEXHhx6fHZIkaV+SV7H+cv8g4K6AISAGOrv5pE5PDaHnp6H7ZNwt3fZuuEOzgqPXxC4L29UUP0UNIpMx0+pHBlNkvOvmFUOyiuYY3VA8UEie4ZXbq+13ZlHpbHesvttoGJDWvIlyvA4Z5yYa3Bl6y/uYqWD4ADMLUrwSW2b3ByzKoPUmRQZ3rineYw/mjQP4wPpxBRg4+hD8YtlPyevvE8lmkMopuRBZHqz5UwNN5TRj3KH8TBnXw+xGADGW3BzNdoJS1sCilEhjE2VTBxCXM5un3kf1YSbpuosEjDViyuvtY6wy3S7W7FnnFfV9uoFIkwRLvTFmDgYmNPj5cUgryOvzy+z2RdnkVN/axWC+rs89LnR9mcE3DBSV8pPyl7uvLsriHgbuwVNxSN4AeLoWSj0AB pU5+Oz/i rOU6bQafue7F8ak7yv0VC58HXlqTvh5ntYA56w6FKgkqBuXz3KZJyCfzh5fl/D9ELQkxx3IMXDFfPpnI/Xd9NyJ0CeTWE/Ocho/y6AYBRvOvOZ8XKEekcUjufsTk7w3pACxrGBYWVp92XKo7K8b5OXx8FjmmXdF9xNTwMMxzTwVPRNIhbJqVcpA1dolc/bRNV3tQuzo31mTtoyFEofti5+YNG97hZMaYfOnPvLEI8BwVKSPBDUn5k6U+Hydx2IGGZ+bI+JuEoIcnEQ6SBR+RNPBXRwrWnUyvWgbJD 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 23 10:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13527215 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 73088C47DDB for ; Tue, 23 Jan 2024 10:44:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A5506B007E; Tue, 23 Jan 2024 05:44:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02F726B0080; Tue, 23 Jan 2024 05:44:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E11F96B0081; Tue, 23 Jan 2024 05:44:09 -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 D1FB76B007E for ; Tue, 23 Jan 2024 05:44:09 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7954E1A0229 for ; Tue, 23 Jan 2024 10:44:09 +0000 (UTC) X-FDA: 81710241018.14.06BA2F3 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf07.hostedemail.com (Postfix) with ESMTP id 1E5BE4000B for ; Tue, 23 Jan 2024 10:44:06 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.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=1706006647; 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=jf0l1UYva5auP6nYlKrgu67I0vTDR0VmH+NorAnif7E=; b=I1FTOTkO4xVbAMZVzKFsdtrajZLPNueS3LB6P8z67jppwrinXnyfKtK4PFxot+Gnfx5ikX NdbdYrbvdXzE61pC7CC5KVgspQghU1GVHPo8kh0ISWmxjKM4CeTKI6tfQ26PuOQhn4xeho RLwA1BYopRDwEJxzuF7CVwagekV450g= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.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=1706006647; a=rsa-sha256; cv=none; b=cppr4df/D6Oq83xbajOCPkHS10H6vbNYT4RqZBd67elQRIrpFhXUbyH6hT/eanYk2dEcVB LcXanas0D5bIWdqkZcOHdvkKdUy2BzA2e7QzrpRBbo44qfA9JkqQKV59uNkZBO913rWzuI ORPK6Wxq6pkB1E5tis1hmNtiERz8n1U= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TK3Z422B9z29kHr; Tue, 23 Jan 2024 18:42:20 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id B05A8140153; Tue, 23 Jan 2024 18:43:48 +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, 23 Jan 2024 18:43:35 +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 v3 2/5] page_frag: unify gfp bits for order 3 page allocation Date: Tue, 23 Jan 2024 18:42:47 +0800 Message-ID: <20240123104250.9103-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240123104250.9103-1-linyunsheng@huawei.com> References: <20240123104250.9103-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1E5BE4000B X-Stat-Signature: 5ye83w6bk84gcncsnniiwfc5pm97swqk X-HE-Tag: 1706006646-579354 X-HE-Meta: U2FsdGVkX180t0YC2Ovq1SUS925zaeJ1u3sEA/tmuLzlI5wyB4AvZvBV8ZDCNWR25Sbxd66lVg3IYpAEZg2rg2ZK8IEyNgkbcSroEE//l4ZWKXKwe+VdVMdKwyXVJ0mewBtEup1B+mC4VWpHWdcEJnlgZ6b1MVbLgWsXaZDYSLVVXIQ1cIvLR3akY+ycGrGMA/pVRidt5vnhmqRXrcUIr+DzoT8LKOAmw7XECCoYiFJV6OcTNNPUQOnp1bvq2jXlEQuOAvMCefvTy47+XMnT4wsZNGxB2FbBKioaMWv6CC6bCmOndBxPbQkSZftv+fcV5gFMqz5Ms1KQkbCJmh/NOwFrytyNgSP2V6ry+pnAVfKxVDLCzjtmWCU8Qrxz+yjUiOjBnrmbuVFilGvQ4wbn2OJtrSyb2kCE85qxQxI7z8VCb1V2b4CROYxAG61vlMLz6l7SYR80VXhy8R4vSgrin/xaDOx0EhBYC4fyd3bQ9Mi1Z7ejhwGLELY5OflzvUkV9BJkjI41pCYJdxOOFPHPgMbg+75hReAbBU0I2EDV6zlN7OyD8Cv4MgIN8n9RRfQWuOcrtF5El36vwTx/JcnGkd95xymE4SlNoX8wYXruU4v4wB82jXa2O2DUbbgGcrptM3+UqwRoEGLXFHBQZ9Jx1w2B/BFrRo/+HnIfBwZkFbIGGztqFb7Da2+AH3wOHKhwySkyhovriAl3FR9t4ZfFYp4L/pjWigUyWxcQtmBsibNBtkRXkFUV1GtuWGvO3hZWMYCv2pS/egU8GAJf1eXp0lS7AQgP+P6HFJrU9BaO6FIyZhQQDxhL38r23GExwEZUJTI1S+OvQzw0sgGbCvkmnCbLMd9iEh6ZTzlouLd3gdno6ZcnRweN1hpvazi4+WVv/UmJ4wZAF9vXedmvZMD7BA2gqBkAUONzBHOmwiBW/U0QloXUrntXzwxtwG3+4S5RzD8trBe47KiQI3Rq/sW T70rbFGJ 89eXkPeMn8VkxrsIpLeO1qNoJHmofbbLT2k2cpqMt9mwHZyULQTMFlOrsTkRsB/8Wdlq8LxxR8CrZuMo46fF7iG9eQ8U+tYnRwX4MO6Ob0CFP9fxk5iW9IU4E8AVVM77fRlRZV0E3pLIwRqw2s6gqml2bbo04A4mz6aVs/m2JkOer2dgYXQvUgNBb3Gy5MaT8nSS3g0732fqAXuH4QZRWENeyWb3YVvGNxBbJCgdMraIQg3LCq7JrshKL3Bf8iQaNniVmBObx1PmG0LZ4R5b9WKujKkqaquynFhjAl0pJgVrQKPjFByBe0ffZU5JnIQX80gIddibr69iTLmaXc6tBnSn8f+Jj72mIuqpb 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 158dbdebce6a..d4bc4269d7d7 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2908,7 +2908,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 23 10:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13527216 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 20B9DC47DDC for ; Tue, 23 Jan 2024 10:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB9816B0074; Tue, 23 Jan 2024 05:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A42D86B0080; Tue, 23 Jan 2024 05:44:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3166B0075; Tue, 23 Jan 2024 05:44:25 -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 740266B0080 for ; Tue, 23 Jan 2024 05:44:25 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0E36D40A48 for ; Tue, 23 Jan 2024 10:44:25 +0000 (UTC) X-FDA: 81710241690.26.8571B95 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf01.hostedemail.com (Postfix) with ESMTP id 6DA1940011 for ; Tue, 23 Jan 2024 10:44:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.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=1706006663; 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=BZWLD8kZydrbnEMhbWiN1ZsDya9JS9FS/nBFJqsWDUk=; b=SQ9xZ8GedjSKamnNRmNMTMuywaprTIm65YBPEu2PYEZiRoyjMlWafHNQFPl+1CrCxv9zhI mYsSqhFmpQbW9cJOVx71Shh9KM5GApZg9gLLDkxpH1Ol4AEM4akq0+49k2xtNHjdNn+C8e AktFFSbI+uKbYK60B7E7JXmHJuopz7Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.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=1706006663; a=rsa-sha256; cv=none; b=QdgEuotGPn36ikxai8v5lXGNQdFmKkvhBPxG08imFxmeYD0PrYbKncdq/gIEsxob744Fcd VIWUOeEcWoq/TpfxGVWfuZnRFQZQse+LLNQS3ypKOntOSGnK6YN9hY2pjW3831qzkd+HVv ZBDCsV5wzzOqJls/K/4SV/bDn4yvwDo= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TK3ZM3bX9z1gxbG; Tue, 23 Jan 2024 18:42:35 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id B54261400D9; Tue, 23 Jan 2024 18:44: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, 23 Jan 2024 18:43:38 +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 v3 3/5] net: introduce page_frag_cache_drain() Date: Tue, 23 Jan 2024 18:42:48 +0800 Message-ID: <20240123104250.9103-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240123104250.9103-1-linyunsheng@huawei.com> References: <20240123104250.9103-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6DA1940011 X-Stat-Signature: g549968a3u6kce5kjkpww3ckug49imt9 X-Rspam-User: X-HE-Tag: 1706006662-18461 X-HE-Meta: U2FsdGVkX1/t7P8YW6gOEK5/YpOBHUAP306xsZWZ7vCJpkNmU9XO+BCOaDrdCSqzLfMU7X9BHKreH9jyZ1CiWmSwBWHlK/LBiWBmrgcBZjc0HtDisNmw1Fypq80QYGcCZhREHjT9QwFeFa1jFgJoZF2sZwNGM9H3eDyVu6o6J1C6ADXeRnIw4Z19cyiwOzTSqD7/OT4aSj/8RXmHZOp+fUFHrqsn7MssOiu4WYcu4Ql9jbkboeXHllry4BWOvjElS1nvXLJjASjfExHR2VWsrynuhqUEBcsVP20XeYSaoWyhxqhnIWr2Gb5Z2+RrYu0BHX9AxOb8pEtC3lIp7sNaZuUj4uTYpmS+5vpKi9sHyRmkoYuU2DWiiixA2vV0Vi8UH9qh2uGDyUsWQX9vNxp5s8EdKpI73qmcg3Ggx9pVJpUcNVcVBLLgeE1KxomyuRnrfhZmUVb6vDvgJmHrXPsvjqs2Rw3ytFixT7VpX2lBj0oHAS6cfI9WCwIqnxnCcwnPCggk57jFgpHoifq99aU8RI/jhH2YHyjeHIPcvaHwZwKo/ySQeEGOhpS+cxQlEkqmWFMqlkpRYvx/m0N9uD9jJ2Xxf0FkssCh6kQjwi0W6UxsU8iQthUuJ1E2oTpphmMGuPDDAHstPxJALR9uC0l1wJIhmnAP9DdMO/CZ1wYd7fFesLsmiPFNaTiuAeSB7PApcyQ/xSA6eJ/PXSF9zigCkaReCbJ4jvy2GdZKGzW3z39I2gDC7AscOENqVWEa9/Yev/xZdgyutD0EKaohOejRgMtp6h26D6CLrWAp6r1XuVI/SwU1quzHaxaL5CLs++I8hqHYDnaGmtFJtrNfzQNB6Guan+RYqdJe0QHdxFHyQIaIp5rDPMuZxVCaIgnX2ZKObWPd18hftNUPMGsmhv342w2Nd4UYTEbph8xwIC8vls1B3c1i00LHqWTsewLtkUN1Tuoivvln1mFMuM0PXRe cfpNkXM6 KL02wUdUxert7nJbOefD/l9eWBoiZw/+q1XP/uE5yjG7+0RW01MUOI00Nk31uu5Ji4ofccicspMl5aYZu4iERA7KLJGpEGqAXIEie5mB34nHysSoRhR6sg2tf6n37bXwEm7uVz8WVvqyZMJQcmRokH0GgBDBtNmp2ndabhqKySiv5stEFcNWeeIibx7iOZWg1Gq6pks5fR7QnMuWpBufq91fW94uIltkpjdgF2Tx7rpFuL//4aFBAbGJjaLc4fUdm9fHZ0drz4TmcGjjWpVKB2w7DU6VvibTYh0/3TaOhRbDYnNtaC0Hs4Dus2+lSlIrsQhN/7+nPoxOe5AQYmXScuLt42A== 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 619bf63ec935..d976190b0f4d 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1278,17 +1278,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 int gve_open(struct net_device *dev) 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 08805f027810..c80037a78066 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 4cc27856aa8f..11237557cfc5 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1576,7 +1576,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); @@ -1600,8 +1599,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);