From patchwork Fri Dec 1 12:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13475704 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 2F330C46CA0 for ; Fri, 1 Dec 2023 12:02:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A709E8D0070; Fri, 1 Dec 2023 07:02:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A20518D0001; Fri, 1 Dec 2023 07:02:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E7FD8D0070; Fri, 1 Dec 2023 07:02:25 -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 7EA498D0001 for ; Fri, 1 Dec 2023 07:02:25 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4D2731C0282 for ; Fri, 1 Dec 2023 12:02:25 +0000 (UTC) X-FDA: 81518111850.12.856D110 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id 379AF4004D for ; Fri, 1 Dec 2023 12:02:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 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=1701432143; 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=m21myrZxxHZ4tvSPxHmf5UUjiuR8Kw6gSpKrihVxiGA=; b=bs22ovVo3CzbEWEY74ohrgvdjrO2/kLawKITWSrZ6Zz3JnJ1h4ekFLumtmbnsMtExuq3fa 74EEsUf5rOqLr/ZwQDXnILJcQ1vF1fbyfziClAqR4U5DhmPOUiUT6DoRgeS3KlfrtKFJmB v2tc4XQivOnu5e6HrKlthsNGos8UfLc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701432143; a=rsa-sha256; cv=none; b=kIEpBNWPb3hr2Vt4UL8U5ciBouCdMTooHJbvFo7TEDThB5A0aK+nqtFosq9Ij9KVK62WCR aJQHUQ43KHs5K1oHgwQY17+aI/Um5yaZZ+7CHoqemEd9WgV2uf05WaPInsbqw8sQsSycDu TjhZiwwYQfBKSL+V3lczx5LwBNsJyU0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ShWmV5SyqzsRSL; Fri, 1 Dec 2023 19:58:34 +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; Fri, 1 Dec 2023 20:02:16 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Eric Dumazet , Subject: [PATCH RFC 1/6] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Date: Fri, 1 Dec 2023 20:02:02 +0800 Message-ID: <20231201120208.15080-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231201120208.15080-1-linyunsheng@huawei.com> References: <20231201120208.15080-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 379AF4004D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zt6jau1ggjgzxwja1kiqyh1me4q9g3to X-HE-Tag: 1701432141-197380 X-HE-Meta: U2FsdGVkX197Mh2uZKSQ4phCXs6qgFVnm3V+nIyetgT4FDrJ1nk3B8x0t4lmt3ixkjRZupYtM/moOHqO6YWoJ0ROxR8r2Zw5/+lmObIIxgXgC5ulAwy4Da4QO5Si0i7qkyFREe/7os1XBKxWizAOT+u4O6sjZXnqJ8befT0BjialPp8JvLEEvTovJgLI5dp4rm2BF6wTyn7A0lIjHr6vFR/iZh2e+6uIFeKINRqF+QYASM9wKPWu1FdF2h/SPm7alGzCo2C+s1tdefYLjkmnP4ShrHDTySm2IAaNPtfTekvLiWc1wjiwB38rlzPhR3dO2JhPnWRmABRQtpt10OhKwl1e4zwZnhyY0dUJhzEMuUKk/GTLi1MJuxYxnu6qTy4OtDi6wGZmFJayT6mV35PB9KBhktwZJZSbATPGxspLBZ8ORDe8K2p3RDZli3v4bd8JRVJvHShpwPzbZkucX5fqU3wxy0hiW9Q/MaMyujs3qx7d/VnSPNuxrMC4k2Ftytp/OzAOvytINp8yyFa0OkXgqj8cnj1OVkZHlifwAihm3gvXjL7mJU+TDdIxv6UQOVtywRNJvLGnuUnCP0+Dwt9ud6iwYJw5wNpj350vHeiEJcpDbtAeIAE9ntAbtGJRd1nN/5X2PEPkArPg022Kk9/w26g731nfprAj73ZchJC3dSLEPC50tQor1yUdQIqWxJOY/mCCrzs2L9LDAITBDX1ALSEX1CMXetJoyzFwTXbrq89Pcjv8iBcNYOmNRm1dJDlxERqUW9cLd5z2Qubh9q9PUkfeuIs+yyXO3ck9oi8HKneym2um9ABuaes8wEfrysiuXvCx3RTzy9cUTL7sekfmaXn0woTUEuLShNlzyrQEmb2WJDGsLYRVoDTm36T0xQFiplZkhmts9ntDEJc7euSX/qeQ52kDrDI/5d9gYfz0Dw8Ny54OrTtMnNoW6wOAnW8eJVLjlzX94t9B77IVowL OM+Ajh6K Cz0TDsMhQKoO7pS9QxrpDfjMCZQ4EI4agEio4YI3YGpyUDjxDuFwqVYkCR37qNoJ1QQ1r+Zyuzj7yQOz/Q6BjYS3HnutVD92pdLUs6HXRqymfyqmPxPvLf1NxlCCwjZr04hH7rxJaoUL9S8kjfJJUc3G4P66muRMt2WEP8GI2Mc0RQsdCzu5rZrrvaFHV7fwIvpl5rxgy0Qkjkw6zhtEDY75uyqDzCNgg5p5InRpZ7vpwgObzlVuSzra3Y/LRmSlNSs6Wdx/LpdKSAyMrsTeSuBbUmvsrLGxzQTqW 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 align and align_mask conversion, in order to call page_frag_alloc_align() directly. As __napi_alloc_frag_align() and __netdev_alloc_frag_align() APIs are only used by the above thin wrappers, it seems that it makes more sense to remove align and align_mask conversion and call page_frag_alloc_align() directly. By doing that, we can also avoid the confusion between napi_alloc_frag_align() accepting align as an argument and page_frag_alloc_align() accepting align_align as an argument when they both have the 'align' suffix. Signed-off-by: Yunsheng Lin CC: Alexander Duyck --- include/linux/gfp.h | 4 ++-- include/linux/skbuff.h | 22 ++++------------------ mm/page_alloc.c | 6 ++++-- net/core/skbuff.c | 14 +++++++------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index de292a007138..bbd75976541e 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -314,12 +314,12 @@ 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); + unsigned int 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, 1); } extern void page_frag_free(void *addr); diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 27998f73183e..c27ed5ab6557 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3182,7 +3182,7 @@ static inline void skb_queue_purge(struct sk_buff_head *list) unsigned int skb_rbtree_purge(struct rb_root *root); void skb_errqueue_purge(struct sk_buff_head *list); -void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask); +void *netdev_alloc_frag_align(unsigned int fragsz, unsigned int align); /** * netdev_alloc_frag - allocate a page fragment @@ -3193,14 +3193,7 @@ void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask); */ static inline void *netdev_alloc_frag(unsigned int fragsz) { - return __netdev_alloc_frag_align(fragsz, ~0u); -} - -static inline void *netdev_alloc_frag_align(unsigned int fragsz, - unsigned int align) -{ - WARN_ON_ONCE(!is_power_of_2(align)); - return __netdev_alloc_frag_align(fragsz, -align); + return netdev_alloc_frag_align(fragsz, 1); } struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length, @@ -3260,18 +3253,11 @@ static inline void skb_free_frag(void *addr) page_frag_free(addr); } -void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask); +void *napi_alloc_frag_align(unsigned int fragsz, unsigned int align); static inline void *napi_alloc_frag(unsigned int fragsz) { - return __napi_alloc_frag_align(fragsz, ~0u); -} - -static inline void *napi_alloc_frag_align(unsigned int fragsz, - unsigned int align) -{ - WARN_ON_ONCE(!is_power_of_2(align)); - return __napi_alloc_frag_align(fragsz, -align); + return napi_alloc_frag_align(fragsz, 1); } struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 37ca4f4b62bf..9a16305cf985 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4718,12 +4718,14 @@ 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) + unsigned int align) { unsigned int size = PAGE_SIZE; struct page *page; int offset; + WARN_ON_ONCE(!is_power_of_2(align)); + if (unlikely(!nc->va)) { refill: page = __page_frag_cache_refill(nc, gfp_mask); @@ -4782,7 +4784,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, } nc->pagecnt_bias--; - offset &= align_mask; + offset &= -align; nc->offset = offset; return nc->va + offset; diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b157efea5dea..b98d1da4004a 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -291,17 +291,17 @@ void napi_get_frags_check(struct napi_struct *napi) local_bh_enable(); } -void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) +void *napi_alloc_frag_align(unsigned int fragsz, unsigned int align) { struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); 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); } -EXPORT_SYMBOL(__napi_alloc_frag_align); +EXPORT_SYMBOL(napi_alloc_frag_align); -void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) +void *netdev_alloc_frag_align(unsigned int fragsz, unsigned int align) { void *data; @@ -309,18 +309,18 @@ 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); } 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); local_bh_enable(); } return data; } -EXPORT_SYMBOL(__netdev_alloc_frag_align); +EXPORT_SYMBOL(netdev_alloc_frag_align); static struct sk_buff *napi_skb_cache_get(void) {