From patchwork Mon Sep 2 12:03:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13787179 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 AB4ADCA0ED3 for ; Mon, 2 Sep 2024 12:09:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C18948D00CC; Mon, 2 Sep 2024 08:09:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7A818D0098; Mon, 2 Sep 2024 08:09:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CC0B8D00CC; Mon, 2 Sep 2024 08:09:18 -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 722238D0098 for ; Mon, 2 Sep 2024 08:09:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 255B71A1C88 for ; Mon, 2 Sep 2024 12:09:18 +0000 (UTC) X-FDA: 82519677996.12.06CAF1B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf23.hostedemail.com (Postfix) with ESMTP id 53B03140013 for ; Mon, 2 Sep 2024 12:09:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.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=1725278862; 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=fAI0xotaG4RDBVu2+eFy5HmWbmt9296CCNeVuGeLObWl06hk1xYZWxHkGxVdGQZw4iFCbc 2Jov05o54Uenw4qloGd0Y+eFrIl59r3Zvqg3EtlUlp405pzAhNyAi/Sn4lc0wK8n+QmTr3 yS22RfUztb84uNCR0EghhRdfTuSdmvw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725278862; a=rsa-sha256; cv=none; b=yS28sMuVRtwuhAkFpTOLo+Jb764wwDz8hmOq6lBLoIuvBYmGkcZHKDWWAnPN+L8d82jk2w BymWZCjQXunjmGQjcoCVfPnl7uUCa4z45AfT1BFZ/w7y1j7uPm6kWDRGM5N0iiimonXVJS aQSECbYzlFLORMWuGNhJ6NEIts2MTko= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.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.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Wy6vF3GMBzpVHS; Mon, 2 Sep 2024 20:07:21 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 2C89F140121; Mon, 2 Sep 2024 20:09:11 +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, 2 Sep 2024 20:09:10 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v17 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Mon, 2 Sep 2024 20:03:02 +0800 Message-ID: <20240902120314.508180-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240902120314.508180-1-linyunsheng@huawei.com> References: <20240902120314.508180-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-Stat-Signature: xf9ife4k6t78n1fga3gctranwzaru9h6 X-Rspamd-Queue-Id: 53B03140013 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725278954-116521 X-HE-Meta: U2FsdGVkX1/0Qmm7feQXezz5MzB9hklP0IzR8sbrEZASywEzYIR+WMVjwvJ9RtMCU/LCABm501Vgmegx+LBqoKL3w8fWdz4hD9FIzNP4lwRSYY0ZYdLyJy4y1cHY4PurKdv3y03f74IFws5n5E/SEQzKCfnActdbJLb8rl2EBefgK6iAtUXKayoCXxzYbbftTSlgBTTUiiVvkLRCpi/pBI2e5QR82ZfXL3Q1y/i2zXrWu+rZ8OqqDdbcM76ZXN77QSJRmZ6j15grjahHBPXM8TK14+xnwMK8PMAcryU7AyzAMBwrnXeI0csQW+bSthYYgBV6CD1S4N1ZD5TvTSCF6yZd3gxIZhL8c8oKe4emiSokfCW3nLJGJEFh2QHN5YUyGqUo/cu5ikN2q7nUpqwfzsy0ZuyDN45+58dekA90PSpJTZC9uImgForQ6ZS+tYCn/sAz/q1pz+d73Uec4hhlt1QS67/P856Koes21YbqKagLk2AW2ucNmBGHXt0JymBpl6pOJAWM8ixJQPZdD+enUK4oJ3OtXyYCnadfWfQCqDeCOYA8/H4TPDMAF5QNsUL3nUCSdRN7CLJee/hCai9U3p0d2M18Di5SWAz+2v+R12VMpMpdGUSq9qB/8KmjH6AEUVddHwoxIQ0sYiq2aIrt/krKrNdhQHW5OGzLWH8yz/vC68+6W/YKpjwnhO6rvGFjq8KTMXBU8ho7WDbYnmePKRhKC/vxehnX5DZSBOYGLL2/gNbRVytAUcSfPsYV1tvxrawYrK/Bvht21TlJTpLqMQLCFUgmJ3Th31x+ai/Io/3aesNDWy1wXn5ybWrHBMJ9ThPqYNCYP6cOjIp46ZzmpaxUkVvPmTJfi7Oa/aE+bmatHn8zOcqejZqgQOnhY/FD5XN7X8s/CZ5sl34MhqJ214/LfBZqzYZ02/bJ/3kqVzJtu8sI2HUkn3jOV7JeAWXWzhvWQ+7417ZD9Wx71Se A291mhLt IQR8ztJCvqT6pI/vGZL7jjKjgFGcJi0Gsmebm+FtR3OWHvAX4yqvq97M8dxb4T8o8G+fcnDzE5lLhrGt38RliPZ4wIQKMyLPCZNjKSZ5LwpcueNnWJeb0IeikanetMh+AMfk2+YVVxdKTLYuGVCuFASalGOdBkatCx0b3o9fyyKiMXKJY3oynwOsLbDXASFF8Xhf0oEs8fpUHamGhHu0Sp8NHAZjrXduPkAxbiTZs6NVS4H0TyRyy1qPr5OkzoqQpiAInXHLdYb56w2D8u0OWmz2mmlWfT9hiNYQUyk1V8snc/vj8UQJOBXubhg== 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; }