From patchwork Sun Apr 7 13:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13620165 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 6519CCD128A for ; Sun, 7 Apr 2024 13:11:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 611446B0088; Sun, 7 Apr 2024 09:11:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C1956B0089; Sun, 7 Apr 2024 09:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1CE6B008A; Sun, 7 Apr 2024 09:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 31C1C6B0088 for ; Sun, 7 Apr 2024 09:11:09 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DF7F81A0580 for ; Sun, 7 Apr 2024 13:11:08 +0000 (UTC) X-FDA: 81982771416.07.52381F0 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf28.hostedemail.com (Postfix) with ESMTP id 054DDC0018 for ; Sun, 7 Apr 2024 13:11:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 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=1712495466; a=rsa-sha256; cv=none; b=4RQnt6D3JFC+FwnbPD/NUHNSURvUO4EVjgBVcBOmoDQc+GvvztJLTeQawJ5OEPwvs4VVB6 boRzw6rVqi6vLNve26P0I64P/ZBcSfAI2+cq7hVHLITiHQZzH5HD/ZUB4sHxqlh0OwzCFY ueWHkXxyEvojALOMYfVs8eo6V/2PySo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 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=1712495466; 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=csHs/6EOnMLYAL1ZoQ/O7qgdOuwkAt68E5NLMmNzJf8=; b=NMmn9IQ+NJ2ND98jh0TqlrBN3cSo0Uelq0hGUtQ/zrDKh/7DJuzDLPcc4z7oRxllZrGHvH 521+pL4uKMK40wd5E5VtDNNnhFMMX2cLu78NjqFPGNXGdO5bUZ7JWenehW37cNWD/zJOu8 SM7gQ0L3cwaMhOJqi2hnSDOYolonPbA= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VCCGT43NLz1ym6R; Sun, 7 Apr 2024 21:08:49 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 1C8211A0172; Sun, 7 Apr 2024 21:11:02 +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; Sun, 7 Apr 2024 21:11:01 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Andrew Morton , Eric Dumazet , David Howells , Marc Dionne , , Subject: [PATCH net-next v1 03/12] mm: page_frag: change page_frag_alloc_* API to accept align param Date: Sun, 7 Apr 2024 21:08:40 +0800 Message-ID: <20240407130850.19625-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240407130850.19625-1-linyunsheng@huawei.com> References: <20240407130850.19625-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: 054DDC0018 X-Stat-Signature: 8tz8hr3q8mju3ytennwzx9h3j84iyjzy X-HE-Tag: 1712495465-224210 X-HE-Meta: U2FsdGVkX19ootbCBp5kVHtMvGwI5dlXLBt7IoAZBfroopnqcy6p8rtrk1jTWgBMyqWAJT7if3S6KA+xCythkHpamnpa5X5neSIy2UKugyuWiVV9F8PeJSn8GDrLjg7kczUTe4d0+RtKrSZRRtXQ7ROt5dAqaeu7vS8bTzedsEXQzXXe7GPWKAbiikN3VsWzG7IyZ1ODWRxzUDxs6us8WV35zC6Rs1VGMvGGJ7x2+fOieptu2cHwSj2RGhbzjfKOy8f9Isox3RAuxC8vgp7ncklPTx9TzvmQcq3+pniOkNKBtmzC43yC5glXDhZ515yBSPt5kfC+29WtG4Fvzl+/k1BLdj2S4bWp32yC8Ak2t5gbz4kgDJxbJZpf+g+4WbN2ME+rjRh4vqHxY8uWz24bb0bICrMTI/8Ukt4NxTrKplgEpuuiUyvIiiBf7W8W95qYEtux6bdD2I2AAF++Mz5tuQrm6X5ZrzcPwiTPO2gC7p0hO6NCXJO2nc2+Ik+nON5vkqBnC73xPyOCnToOkQ+iAI8fOQi69e0vg4pg5lThFA7GsmFEReAiovdYB07waluh1/uIi9ZX6x+2IaETVGW7vfSABbRvrTUM05IBreN4/rfdySDrzkTQ75heRLJOUeS10RNWdfC37yJpp7rvsxqHazlZtLIIHzgwulyovSYM3Q9yGwu88k/3jQq1m5A0V6u7ui6JNmOEslvNmRmLGTKRar9bD6qA+CD29y3u9Ft73ELQ8032ih0Wr7Lf79TYzFI4CDvPSRr7leXu6cJSM9RxsVr5KRLlLqUiwYC+17PpsBOvaVwLPYFULwaNEEDjwqWbF+R+6jn6Pfq70lXOme6HUpHM1zNvUwcaOJ7P5qOKXg8t0Iuuz60KjLLI4r/LFlfVoL7PmneT/I5m3Y2y/uPzVZW3wAYM5MTR/x6vi1TGS5slXZZvzYykTlL8ImSvnNX4VrruAhoJCcCyxb8g5En OLRSp0ON glpqlMbOGgtGqJ8+uUCnmYXEiYqEhPk556cvtq1KLd09QVw6YpxKwno8FhdyPO0AJiUv88pMcfK23yVMY0w0KMTzgd5m8uJmDPaem//wAeD0fqh8Yb8g6/Cx63HwI2WR7QH1G2eoLcOZS2CGhDQ3SJYHnzhVhiiU6etFzmbtiZ4LXsjlkk1/xa4uEuTs2UmgJrBar 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 page_frag_alloc_* API doesn't need data alignment, the ALIGN() operation is unnecessary, so change page_frag_alloc_* API to accept align param instead of align_mask param, and do the ALIGN()'ing in the inline helper when needed. Signed-off-by: Yunsheng Lin --- include/linux/page_frag_cache.h | 20 ++++++++++++-------- include/linux/skbuff.h | 12 ++++++------ mm/page_frag_cache.c | 9 ++++----- net/core/skbuff.c | 12 +++++------- net/rxrpc/txbuf.c | 5 +++-- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h index 04810d8d6a7d..cc0ede0912f3 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -25,21 +25,25 @@ struct page_frag_cache { void page_frag_cache_drain(struct page_frag_cache *nc); 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); +void *page_frag_alloc(struct page_frag_cache *nc, unsigned int fragsz, + gfp_t gfp_mask); + +static inline void *__page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align) +{ + nc->offset = ALIGN(nc->offset, align); + + return page_frag_alloc(nc, fragsz, gfp_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, align); } void page_frag_free(void *addr); diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 76c5be5b1a8c..2ef14dde5bbc 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3268,7 +3268,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 @@ -3279,14 +3279,14 @@ 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); + return __netdev_alloc_frag_align(fragsz, 1u); } 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, align); } struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length, @@ -3346,18 +3346,18 @@ 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); + return __napi_alloc_frag_align(fragsz, 1u); } 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, align); } struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int length); diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index 3e3e88d9af90..39c744c892ed 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -63,9 +63,8 @@ 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(struct page_frag_cache *nc, unsigned int fragsz, + gfp_t gfp_mask) { unsigned int size, offset; struct page *page; @@ -94,7 +93,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, size = PAGE_SIZE; #endif - offset = ALIGN(nc->offset, -align_mask); + offset = nc->offset; if (unlikely(offset + fragsz > size)) { page = virt_to_page(nc->va); @@ -131,7 +130,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); /* * 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 2a5ce6667bbb..e5196c284b33 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -305,18 +305,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); -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; @@ -324,15 +323,14 @@ 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); + align); local_bh_enable(); } return data; diff --git a/net/rxrpc/txbuf.c b/net/rxrpc/txbuf.c index e0679658d9de..eb640875bf07 100644 --- a/net/rxrpc/txbuf.c +++ b/net/rxrpc/txbuf.c @@ -32,9 +32,10 @@ struct rxrpc_txbuf *rxrpc_alloc_data_txbuf(struct rxrpc_call *call, size_t data_ hoff = round_up(sizeof(*whdr), data_align) - sizeof(*whdr); total = hoff + sizeof(*whdr) + data_size; + data_align = max_t(size_t, data_align, L1_CACHE_BYTES); mutex_lock(&call->conn->tx_data_alloc_lock); - buf = __page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp, - ~(data_align - 1) & ~(L1_CACHE_BYTES - 1)); + buf = page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp, + data_align); mutex_unlock(&call->conn->tx_data_alloc_lock); if (!buf) { kfree(txb);