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;