From patchwork Fri Aug 30 11:18:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13784983 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 848DECA0FE0 for ; Fri, 30 Aug 2024 11:24:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE98E6B0111; Fri, 30 Aug 2024 07:24:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C97D26B0112; Fri, 30 Aug 2024 07:24:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B38B76B0113; Fri, 30 Aug 2024 07:24:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9496D6B0111 for ; Fri, 30 Aug 2024 07:24:49 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BC7CF417E4 for ; Fri, 30 Aug 2024 11:24:48 +0000 (UTC) X-FDA: 82508679456.18.1AB299A Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf27.hostedemail.com (Postfix) with ESMTP id 380C440007 for ; Fri, 30 Aug 2024 11:24:45 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 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=1725016996; 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=hCSmgUw5AsCX2iI+aZOW+yA359aYOsS2/g8+DO2CShb5JoSS1DK6QIHjszRJfbZXvEbsfy KOKqxqyDbS6DY+5cnLMc2srnzvPR+H/QMjKtJtWKRcu/Z+4QLXICffaOqaaaDi0U9N+1mb VL6pN66NHh2CCWveKfzHGIjJzb9bkik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725016996; a=rsa-sha256; cv=none; b=e22KnVnQrecmWvNRTVq+GxgJRaxe2yUGadrO3oVAnAc2TV3Y5m4k2U3bTpNqWc9zxVOinM mHXxGyV1WNVZjBYqEgiH8BLpsYWAWY8ySbHSOtkNo3NmtveIJRaS8aPGWqaWcGu05qxOtD PLBCneQLE0CEAWlz9xFeLlM03VAaQok= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WwG581plJz1S9VV; Fri, 30 Aug 2024 19:24:28 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id C0655180042; Fri, 30 Aug 2024 19:24:42 +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, 30 Aug 2024 19:24:42 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v16 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Fri, 30 Aug 2024 19:18:33 +0800 Message-ID: <20240830111845.1593542-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240830111845.1593542-1-linyunsheng@huawei.com> References: <20240830111845.1593542-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 380C440007 X-Stat-Signature: ggcuij44nezcdws64jr7jdcson591tm8 X-HE-Tag: 1725017085-870459 X-HE-Meta: U2FsdGVkX1+Wv+YFW52HYylgBIHQovljyUgg9uScS1cEKBQ5H9cK7N973le5h14QuW9oJNAf0NRQEM1RqeE5+kI3nu4u9f8Btfu5JUfrk6zCP33bUH8paUFtMYMTFpCb4P7+VBO6acYlAxwLiPUoSNn3AyfshsS5j6WlasKZ8UbBq1souLBg4f7DtvPyAoI16oLDlGSK+xe2yP1lYaxy/Tk45kLbh2o/u2eD6Ik6iHAU1+FPZBnsfhgWCrGFD9cNuhN5r36TvU5fKzJ6CrEIZ550PlIyp3sOssdvWd98nWIo/ci+ZjX1gW9Pblz08acwtXNDZXv9RfcA2a/Y27l1FEXMc8Z+gpvHs4F2oV4e7PxNVUxJ2y9Bw619a39dzaKCNhagG5V5UewsA2UefHf20hFVnZAfqLp/n/ryDOssUouL/ScO7ZJUnLg7XBAo9N3HtS8V8G9GkosP3vdpZWdCRqVZuM9uxgTypPy6ppl3vaTocIJ4MapvowKO+Xy/4EC28SSz2PyWPZUT3OV3K1sG8vjyWNLdnEgy5KWs2IRZSWo8x6LyDH+G86jVsWkWuIjWDclZ/US1htNBSdKsfk0CjsalNvMfjyqZax3v67dVbosOOVCOFwN4hmATXEHOKcg0C0RRrzCDLq8dTpLqN1JUGuz5+pDNRf+zB3XYLv60XHZx2XHCnwcA2TY0y0aHxp/QRsk2wgzn8GLfxlPWw1/HHM7uJVkhqWpxM7D75LlhebO2SeCOp0++8/azxGYwJ33fErfht5jdDzzKJlzyN1aLAA/wrcNnRRg3rUVXGxVZbkqzgbAE8U2kFxvWzKltiuqT1HWPnJkfvR1s+QXzW+WsVwy/Tu0VshpuGp+dS4BihVNlGKB+bgE189HMyauh4kl1dRaXzhkbd93jr4XQ0HcdmqeVb+W79jJY8LxXN/P1FYbPLA6oMtJxk3PdaBttww/seFAtkhyhJx4jZWCqhc8 Fru1Io11 ZT2I5L5kcEaUm/KTRQ/dPxpn3DueA2Ikbiav5ovVYK5h+MbREU9TjZPvwsAcSNkwxCjJon4R8tA91c9Ic+BlBslCdB7emwisTdqr82kBDsqwpgBck7f3QHUI35lENu9Hxpk9+MJjWhcOrbulwyPKhvEnOXcP61mr/YlfMKo/a4gEh3LlSIu2TBd2JoKPCWlUhEJkQYKNZAt0G5nR0T3AHmO/7RuTNHOMmVMhYLcwHDmlJ7PBftBaArQHXAG5g1Ur7jHEc+EOAztOgUm6YApbdvQ1P8ZBEbq+Js5aS0HPkYchDNVYNWJnfOGIlZA== 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; }