From patchwork Mon Aug 26 12:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13777859 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 92B92C5321E for ; Mon, 26 Aug 2024 12:46:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53FFD6B04AA; Mon, 26 Aug 2024 08:46:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F0646B04B2; Mon, 26 Aug 2024 08:46:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E1A76B04B6; Mon, 26 Aug 2024 08:46:19 -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 0F4BD6B04AA for ; Mon, 26 Aug 2024 08:46:19 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 84069141079 for ; Mon, 26 Aug 2024 12:46:18 +0000 (UTC) X-FDA: 82494369636.29.9AB1FAF Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf15.hostedemail.com (Postfix) with ESMTP id E7692A000E for ; Mon, 26 Aug 2024 12:46:15 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724676307; a=rsa-sha256; cv=none; b=zkKHTGXGmlCmMTeIgfbLroxX1bi8SDtC3rRLiVPP53O7kBKiAUeMgnVF5lZvxweLwIQ9SR 4oF7NvzgroRJ5W5XCmOw4XnplXFMbWx1XGAP2VJ3pq7WbLQ7UMI2RZFQCbvvgdRrG6TYPv mRGTEI9jHPoy6f43go9fVvAHa0M3XW4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 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=1724676307; 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=kPIYPG/OrE/t2+FUNllMox/LOqC+P4YoIlou5mKg7a8=; b=xYBHxA0hKCkDRKE3TEOn26TDqrKJkw5f7B3np27Wj4uw80qcgWPQAwlPU+puvDTB/kB0F3 WkRke4km5g/71lAUn6nD69voYJ3KdZ/KTBOuT6VJh6jCUGhZ8AUakORs3FgGuodF8F7+qk CvnVXmV4S4IQ7n9KKKJLAXOnL4Tw9zU= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Wsqzn0vWpzQqhg; Mon, 26 Aug 2024 20:41:25 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id C66221401F0; Mon, 26 Aug 2024 20:46:12 +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; Mon, 26 Aug 2024 20:46:12 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v15 03/13] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Mon, 26 Aug 2024 20:40:10 +0800 Message-ID: <20240826124021.2635705-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240826124021.2635705-1-linyunsheng@huawei.com> References: <20240826124021.2635705-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: rspam12 X-Rspamd-Queue-Id: E7692A000E X-Stat-Signature: hthrhqmcxwnor9oh5oujjw1f5xae3fei X-Rspam-User: X-HE-Tag: 1724676375-381431 X-HE-Meta: U2FsdGVkX19KkM5BfsBglo1VD+XfkQtlkCvwHu2cIquuyXu8cCknc9JpmMTH8yIKZ8WQJhJC3ETTJIOyPH3oFCBL+vlqNxjFI44tsazIY5nRXGfN9SnCKO1IpWzwNLqu+xfxCiCR2OprXxJnRXD2wPdWC2Va52xWOQxb1e4yQg10MHxB2uHidjTLOEYRbq1ZiF4vs1QCgRA/ICpeFCGyAVENH+rXw9Q0sW4yji4u2mb+EyXlqwyRFmOAFujPstcEirTc1JDRjHe7IsK0ewWla7fPfkZX5YTwkraNWDx+JUMlNx/MmvAyyjkPJ2Ldp+Xin8TjLO9aVWWOEUIYi0WPhOpiCmossJz1JLzXPjIXa4DYQG8+NyOwOWTNYAuAG0v6u7LB4UrK8j0PXn0ZKPtrpKRcQlJF7pShneJEseGfPi/6xQbRD77OKZ0RZymLH3+xVApCk05FDrGUB5KexvExK+6ylHrJrpagkAWHXgVVw3KdFHy0sA1QvT5O0qIX+dS4+x0VH7TBlsVqu40zA6Zlp5XfoyAhZ5rxQ0mt3QZEnNkUkl6WipUBvRWn6GHuF5VJFdLbFgxQRSrHTgJI81GF711vFi8wv9W3Kvs21Pd3XHMF5UQNGYgtzKcmZgEorNvQuOJRzerfCl6t2fBqCBFAiWUd75z20lK2G3r5ESYnMr67N5G53pQV620hyDjscKCGQc9W683aRe74ltxNi8Xsxvs4sQXCgkyN5PJg4+gu3alJntl+lzer1FMULx8KTuSQNvzuS4AintSVxhyQSBoee9kfegIgLtwGvvJ6flWK2h1gLKIdxztWbooXApdFHpbSgrAEp6Qnw0XG7KY756QnBWRkTT7/ueRqMUHwYq4RxwLep1FQXcIzw8exTttk42NbJpZ9nIuMybYvZMHM8/5o6yxZogIDCnY7ow/GLH1n1Tb/cE2VNKpa7LpkkmcDHlNBaqNQ1tLkH/d7qw2MRMA UWlMvkmg ERv7V0XI5qZArTVpNolxyxBtoaSukK1nhxNH+Z8NxESuyBcxntDMmd/7eqBP5jY0dANManN6Cri97yWK/YxHW6Y6mCVQz1Wti9WgrI/n3aukc3HIrkOocbvDAFudUhBrava2Abphh8RPUPCnnE3lJ4/lOGPzNOj2U4p7RkdoL50HTzI3bKJVXoD/nzEc+F1Uaw02phjPD5enPjXUt7xEZCPiaDOfCZHL96Vvo11rghwp2qCBTWEHvdO90FuCpi8FPkRg2xc7mUKmhm+i9Qhwco1Bm090BbJx44ertLXGZrLbv4ZAjaBU5JDZxnVmH1Akc2HhlGTkBXSnab8/fETBCH+qmoA== 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 --- 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; }