From patchwork Fri Sep 6 07:36:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13793529 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 59A37CE7AE2 for ; Fri, 6 Sep 2024 07:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 797CE6B0089; Fri, 6 Sep 2024 03:42:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7219B6B008A; Fri, 6 Sep 2024 03:42:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 599306B008C; Fri, 6 Sep 2024 03:42:51 -0400 (EDT) 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 3E25F6B0089 for ; Fri, 6 Sep 2024 03:42:51 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DDFC0AA150 for ; Fri, 6 Sep 2024 07:42:50 +0000 (UTC) X-FDA: 82533521700.21.BED7B23 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 6C4AFC0018 for ; Fri, 6 Sep 2024 07:42:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1725608439; 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=4yGbngEcJsz6m//zfut85fFVzSl9cLtY6l3mpf84x8Gg6BXX2ZHrayNQvR3vj5hJtRWerN gKUcujGHIKIFTEQWcBEynTuA3JmmycrM1rj/0ofJyfDwFFlYDwDSHSiLSqrmGMFjEBnayB kzgK7eUsrVVOJIJKKfO0oQ7iLnfR0ns= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725608439; a=rsa-sha256; cv=none; b=S5ZmSDg2CmlmWspO5QdQWgu0WQbzVge6RBTn2Z0CdXEiYC2lKOW7oV/zvb0c95bcaxnfKC DXZa7g2Q0WyOmSem/q1xq+s14zfcK2OOQ9fVxAbJpJKRCJB2upFc1a+y/gNYp3VMn9tITF bAfDJ+P+PRLRZyycIoec2VZHj3dPjWY= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4X0SqK11wLzyR1R; Fri, 6 Sep 2024 15:42:05 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 41B8818006C; Fri, 6 Sep 2024 15:42:45 +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, 6 Sep 2024 15:42:45 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v18 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Fri, 6 Sep 2024 15:36:35 +0800 Message-ID: <20240906073646.2930809-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240906073646.2930809-1-linyunsheng@huawei.com> References: <20240906073646.2930809-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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6C4AFC0018 X-Stat-Signature: wx5hsppob8aiiwse1zb3njfxpn8hchet X-Rspam-User: X-HE-Tag: 1725608568-707398 X-HE-Meta: U2FsdGVkX19YFetZYiCF3TzwsGHyF3oyAXjq3s+jfnVmziNwAQdApAoWBd8FQt1r29o4TOdgFOzIhgcs58QmeAWxRMso/iVOJrDLUQGMyMCAV0N18s0ewZVZufjqS6XEODmYlEA44SxJCsXgoCqKnt4PS7ne7GYLnHEBhHoAfDBd8Rp4T+QDPm7huXBwYaUjOpWucrzF58rYcm+5WsE7dlg0NlKNSEti12JJvk3iXQ3NhRsD4GPAoruHBA39YTeIPNYkIkKV3HQfaFf17c1e8OjVXZJz8pUaCajr/DiiwHkI5Vt26CY3a5RaWpSomi+T60d0oSKhKDZpDzngU8iEiINMylkyze6t57HW0CS+rTMLXC/2d4u+FfZ1nWti0TxA/ejRiU160V8ZXLe3rRN6QVTmOKJOmLe2mTW2mWbdFgxS7uRuYPcXY1KE1S7OVYCW4WB+ENj6ldYdbs6pRw5M9eIgnGG1hwwnymnLXqkTFJOhDRm9le47ldT07ISOo1VRR9OFQPCfQ3coanYHZYO1wjbR/F1R1hRRHrY5KQM2FxFStmXdniU/L2xOL/5uT/GfdiPP/mdHSlV2UkjJpwc+gqjKQ9ia1Aw1u5kSrrdczND2fh1OFoIfkwQ/SiX09yASoGh2IrE+YhzVJ21+ftxPcsAdfLqjEeqjVPRCB7bKgequr9wysSAmm4xeuXXPDEbUxXJHsHt4OlcTQvsKNg+ToADYOMwzXjkT8YJKlwehf3sGp0X25tqgQN27UcaSMp9QyiZ+72/vTvsoMnbt8y7zDS3tsp+3xcrGO6/qA3GdI+pnhw3UO3FToqC1L/Dc3ZDiK/4QbadAUsSz0+ZcZn+P/DSCYsTChPzoftxS25ktZ0vvb5b3oii8heizv6Iv1X7GMWJO+S2SbujwGi1PYE6+/0tqt6BkZ8UwCS2/N5RZI0LIYHvKyh1S4A5CyPaPm5Iwn4jN9waLU5633fdD0Py 3t9w4kXh n49dpiTFzY3P4NXgN7+VdkMaYlDW9mhkkt/mOPPnLBv9nl+xOwNwKfTHiZEvTYSoLktya6hLHtKzqvapK/I0jT2TluYqqZ9j1b05nMC2G9kvDIpb2oAmxqhjuaCI6uWF48NT5kp7I5RaptUGBW91M83y5MBJFJEm/wGy2v71U04oO+nsntW/wuBjlzdqxQm8MS3LPrd8DY/pQdyCtRR1aReOe4lKHYXuy6nMaxvfia4lWcz3AqABNjowh/MGWUisUjs06kaMS2ba/zRC66PeFhEB7CDyNm69npn/69nxPcCDMSjzuMiN1Ssc0vsS6968ye4f7rJdo7BiB0lc= 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; }