From patchwork Fri Oct 18 10:53: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: 13841624 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 6BCBAD2FFF2 for ; Fri, 18 Oct 2024 11:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 021B06B0085; Fri, 18 Oct 2024 07:00:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F136C6B0088; Fri, 18 Oct 2024 07:00:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDB336B0089; Fri, 18 Oct 2024 07:00:23 -0400 (EDT) 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 C207F6B0085 for ; Fri, 18 Oct 2024 07:00:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 90E74A18AF for ; Fri, 18 Oct 2024 11:00:01 +0000 (UTC) X-FDA: 82686428916.18.A45412C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf30.hostedemail.com (Postfix) with ESMTP id 2A1C38000D for ; Fri, 18 Oct 2024 10:59:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 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=1729249074; 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=PBbxlB0kz24iy7iokK1TfN2qwdTa4QMZvXDcqO85e8U=; b=UtyG+nMbmVpzYddVXUEs2do7dS0UOlSDJQDyCvuCzrpUgbMohI07nv6YLwV4Nx8jsjK5TT +oDdXmNDB1pFus4bDFKjNObEiwuQ++rVmIWJXwXFhCryHXhbDWfJPs7xx2FR+V3lcyaPGp 9R2DG0Kg4hIeq9gDbFAnFaLrTEGgQ+s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729249074; a=rsa-sha256; cv=none; b=W25KigIUw9nVl8bCHBkEchfuQ31+df0TW5Psbk3DDnlWviBb50dLmqaMcfPuUKg3zHWv/A pu9lhRGUO0IfMQ5A+7c0ZMu4DD87rhiABeZ+zHnEs9Xyl7ZkZ6izIPRjRmNnzPFVdUsbQc M51HDEfgWgr16gMrQ60r97zRlNcjChY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XVM9k75g5zfdM1; Fri, 18 Oct 2024 18:57:46 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 034A8180113; Fri, 18 Oct 2024 19:00:15 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 18 Oct 2024 19:00:14 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v22 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Fri, 18 Oct 2024 18:53:40 +0800 Message-ID: <20241018105351.1960345-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241018105351.1960345-1-linyunsheng@huawei.com> References: <20241018105351.1960345-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Stat-Signature: c75h58x91kkm6b44uaq5bwm7bmm43x4f X-Rspamd-Queue-Id: 2A1C38000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729249199-172632 X-HE-Meta: U2FsdGVkX19sOaZr2AzhX1DC1AHyV10F7efmggCxCPjJ+3XJtJCGIwOvYE7Sxz70YGmkFPA639HE3KSxKkgfXsqd27Sn8jz2iR5LwRnSP9siJUp5MgA38JBBl8hZFLpNKxKgk8hfCeMGbMXtUBBfKY0Ge94uCldsp4mViiIIuifyayY0tm7hP8vqtq/tMpkpQRuE7v9eh2OWkQl7EsCnygw079pR6lYqTT+D8YKK7pY6P2WThM0jQCH99+iaQoOl1RuFDimW4qIVBcJa+4DXAFQliCsCIzoWTvrRBaYxYTMe5SOsr6tWT0+gFT105DY3CrzHmBGHu1+2jNrxG5yvRwldk+KhF7cWzmGyhM9sL66ss1sIz5b/C7IQ1hMFYILOUPYBp/+XhfPasCc1gUs45X0RzYwfj6fn5fFgT7SaOKo8ZXbRRjRkh5IZpPYuOHjZpT+DXvC9gX2pRBahRKnjLkDmhtrOhEIhtxNrE9RwMLIs9fic+qN+5GMpIgjd30VjBCeNlhWYMtfZrbG4jRjvX2Wl/9pLzKV9L+z4AX0a7nneWWZT3WnZeistspkOncCYXBdD8DK50us0dPw4iAOEnCtjaRuyQHsjx1oq+OrnueXBPGa0wD/S8fos5b9KJYqTQVEn/yTa3ryok5RAZLbAyaoJfEJUqTvd5PE7ikvZr+gXGbULYxoWs65spvZICFBaogSFv6DDMSPHtEh3tIiGu8M45DhEOF4hUcC09K2zpVA7VI7R6jen0MIM0hRaExjn7HcZ51FyAtdTz/VqtJL1i2TawqzZxlDsoiDG9y12nq6R3W3x6u8NC0Gess4qeNoA16Dki2V5wkfGYsnbedRIZmt95YxuhJMJmcgyO3bZBwpCAYz/DZRx/sCtxof1AiEZnllcZ3bKggffRHagwD2SDiDpg+E80lJ+RqwywB3j4C4kb8K9dz0gCeoke/j89R2g15oV0+GRmL+6ib1QWoB gnC624Eu MJ5/hW5/J+YmVn8DZMyXnv8y+y8ebaYz6Q7+gaJothjeCmzmCInPeLXnmEWHE9lsU7y/f6TgNlNZjlAMBEcHgNHcgXXDnSMqCVwtAGDJO4HY06HkRTL08D2Feg64BJEYpMpXCNWHgz8SholrGGtb8e/eUUjEx/SjqbPn3Sumz3Tn7L8yIAKb4c5GNSJLem0O+hPwgEtw/KwIAKh5e3Rxx3ZWZCkumvbAvv/lLO9Q8C3fOj0q5IczgoFn7nUkarH7K9M5zLmWMOn9dUXymwPulPZItf55l+UmsRvLJps4sGkhRTZURcT2NE+zJQwhqcYVmsIzHZ2b8VwKfVOQiM5h9+O+Fp+wq1Xai1LUTlbpGGpv3WwG0snUFDpBd+41Pgp+WCbebqJ0WPGNj/iMgjXxiuuzTjnSG3zTaO+2+ddlVukzuvIMVX0oAg9eudAgqvZqw8R3iD4TOwP+3lu0SOdl4bYHFbHdVT675FNkM4VNRS7RScug= 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: We are about to use page_frag_alloc_*() API to not just allocate memory for skb->data, but also use them to do the memory allocation for skb frag too. Currently the implementation of page_frag in mm subsystem is running the offset as a countdown rather than count-up value, there may have several advantages to that as mentioned in [1], but it may have some disadvantages, for example, it may disable skb frag coalescing and more correct cache prefetching We have a trade-off to make in order to have a unified implementation and API for page_frag, so use a initial zero offset in this patch, and the following patch will try to make some optimization to avoid the disadvantages as much as possible. 1. https://lore.kernel.org/all/f4abe71b3439b39d17a6fb2d410180f367cadf5c.camel@gmail.com/ CC: Alexander Duyck Signed-off-by: Yunsheng Lin Reviewed-by: Alexander Duyck --- mm/page_frag_cache.c | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index 609a485cd02a..4c8e04379cb3 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -63,9 +63,13 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask) { +#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) + unsigned int size = nc->size; +#else unsigned int size = PAGE_SIZE; +#endif + unsigned int offset; struct page *page; - int offset; if (unlikely(!nc->va)) { refill: @@ -85,11 +89,24 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, /* reset page count bias and offset to start of new frag */ nc->pfmemalloc = page_is_pfmemalloc(page); nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - nc->offset = size; + nc->offset = 0; } - offset = nc->offset - fragsz; - if (unlikely(offset < 0)) { + offset = __ALIGN_KERNEL_MASK(nc->offset, ~align_mask); + if (unlikely(offset + fragsz > size)) { + if (unlikely(fragsz > PAGE_SIZE)) { + /* + * The caller is trying to allocate a fragment + * with fragsz > PAGE_SIZE but the cache isn't big + * enough to satisfy the request, this may + * happen in low memory conditions. + * We don't release the cache page because + * it could make memory pressure worse + * so we simply return NULL here. + */ + return NULL; + } + page = virt_to_page(nc->va); if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) @@ -100,33 +117,16 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, goto refill; } -#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) - /* if size can vary use size else just use PAGE_SIZE */ - size = nc->size; -#endif /* OK, page count is 0, we can safely set it */ set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1); /* reset page count bias and offset to start of new frag */ nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - offset = size - fragsz; - if (unlikely(offset < 0)) { - /* - * The caller is trying to allocate a fragment - * with fragsz > PAGE_SIZE but the cache isn't big - * enough to satisfy the request, this may - * happen in low memory conditions. - * We don't release the cache page because - * it could make memory pressure worse - * so we simply return NULL here. - */ - return NULL; - } + offset = 0; } nc->pagecnt_bias--; - offset &= align_mask; - nc->offset = offset; + nc->offset = offset + fragsz; return nc->va + offset; }