From patchwork Thu Mar 28 13:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13608542 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 91FDAC54E64 for ; Thu, 28 Mar 2024 13:40:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266826B0085; Thu, 28 Mar 2024 09:40:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 215EE6B0087; Thu, 28 Mar 2024 09:40:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DE836B0088; Thu, 28 Mar 2024 09:40:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E346F6B0085 for ; Thu, 28 Mar 2024 09:40:50 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A3D7BC0D19 for ; Thu, 28 Mar 2024 13:40:50 +0000 (UTC) X-FDA: 81946558260.08.6240B96 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf07.hostedemail.com (Postfix) with ESMTP id F2F834000C for ; Thu, 28 Mar 2024 13:40:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 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=1711633248; 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=1+LR3anLhgNyfy1DdepUw5hxaFlR/GVCDkeZbq8UPPk=; b=DON26GkZAzUl22aNqHsya8yGTHiDrwFZfqMMThHYAJmHHKVjsAtuSobBDkk31wNJFjVcx5 H7OhS4bFW2E9AFv60Squu46nfaeMuVcuJ7x4heInUOqi5t2zkHmw3519RSjgdwND2T31h3 TVpa2zykATbjiT19Mc/rXr7c8UjcBAs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711633248; a=rsa-sha256; cv=none; b=kwNY+KFHIs23z9eE+GrAwZlvRPUFxkxCJg4T2EtMyxnHz4dnJtmpx+OsCoLg92+lesMYN5 C27KAi1bYzuSUlDEgq87PaLo7VSGheQtUWze8O+n0EJ7vp0byBekV09eI4q3N7bK86mrF+ UmYfTQQ6H67dlxBnbMa1KQWlpc6cVKY= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V54RG48H3z1GDX7; Thu, 28 Mar 2024 21:40:10 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id A7813140258; Thu, 28 Mar 2024 21:40:42 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 28 Mar 2024 21:40:42 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH RFC 02/10] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Thu, 28 Mar 2024 21:38:31 +0800 Message-ID: <20240328133839.13620-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240328133839.13620-1-linyunsheng@huawei.com> References: <20240328133839.13620-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: F2F834000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 38f99xeqszr6h8tkw6zpqus749wewf36 X-HE-Tag: 1711633247-948529 X-HE-Meta: U2FsdGVkX1/L6AnQa3VsN9mLIQz2jrsqsaZvQAxRKnh4PyWmxRjg3d9zPP5cIPkUUYjumtn3aQxwn+yzAF+pBmpg4ZX3+zyvi4NSSRphX1x2cqS4WgIIKYaceNSnNbFHSbataw8EToQDQCTX8EH5oyVntyEA5Dm6z19INI+Mj0gEAhwDzgdBKD+P2PWoR82aBEwKs2jY0EDOZIISC5tjikHtK5y+94eERUCd7NizBTVwt8BByk4VADKGUNNCUclg8a5InOLQ8BIbo5TU0MjEJtm9+Xt7vTFGtvEPh2S1uLbGzCrr0uxSpwEYGHdflWcbrv1tHUAJ2a99w/pCfCTINQETzgiJvjDvL1hNcHn0opF8A0Jrl+NigYbMbEjvcSe+IyqtfMJ9royrfjXuulYBXrUMDLk5LrRvXFvxtyY8M6HoXGfyaOcTsFxDI2oj2hCyAOPwi5MORT3oRf0EoBPlB8STTej8HHdiZCYau7LInf+jh6iITNw/j5xOTFlsw9ZZ8lMe3m5PZ9asG2qI9kA9RDJelN1qWkZkjcKwVfdCUiqGKkodVtS48xkwN9JVo3fCKYcCqWJeArMEVyO5CjIOJpYbAoQ4WIeHaZ4dxm3fIV0lBI5f1ZmY59TvIakE6HyEy5MoVLBKNIH0WD0njsW7jLC8n8wE7V+JIRMpzAn3FVOy2Xt72VxPq2L4COimqpvgWqprktct7ljNNz2zrYKrKi8PYHiZYSV8zU4qi/UNSZVI7zbOFgvjuV/O5i8VOnw3PYTmI1+buQ1T90LfyW9SRgLxv+bwV6Q4n4w/lHFRgreXGdmDAa6FxHqhxd5fRChzvUvs2T4xgFTj9rlrbCwXeYIMTD+hRUWhN1b8EumrAhGgyQPqT+eyCKyKwdw8+vroPioWgOJZd6sU7h5UmDMWobu+Qwpr34yC2ft3PyPKm9ch7Fv2X37HuKOw53pHd+skKQGuysWKpMFF6COPVQ4 37h+08m1 6FiSZEqJkw+lRxoU+IwiRF7GT5beJQoFzBzaI+mIBQH6b3osVtjuRubYi9ZZZhrsL6aYNzQ8BRv05FRHE5kDlEztEBujgiAndJMhBE/GRYYTZLm727T1BRe+oWRUFV7ZUvqT0e06pR0/W1Ix9c/dOu+hvRv3OM85+HxqvRVW9FqxeIrt8613ugEV5dmxUPgutuKdTuhynJzvhwETzMuGcI4RacdVdmZNyCDordjyhkBRl9YmsWweStTy0eAh4klVGplkRBb2FCul4XYOY1bjUf50aTLENYfGN11s2djnSNqw+/zE4LPIvm+cDRcjkhP25OaVwkGSkuaaEJRkmL7KVtYrXwQ== 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 above 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 coaleasing 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 aovid 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_alloc.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mm/page_frag_alloc.c b/mm/page_frag_alloc.c index a0f90ba25200..3e3e88d9af90 100644 --- a/mm/page_frag_alloc.c +++ b/mm/page_frag_alloc.c @@ -67,9 +67,8 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask) { - unsigned int size = PAGE_SIZE; + unsigned int size, offset; struct page *page; - int offset; if (unlikely(!nc->va)) { refill: @@ -77,10 +76,6 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, if (!page) return NULL; -#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) - /* if size can vary use size else just use PAGE_SIZE */ - size = nc->size; -#endif /* Even if we own the page, we do not use atomic_set(). * This would break get_page_unless_zero() users. */ @@ -89,11 +84,18 @@ 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)) { +#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) + /* if size can vary use size else just use PAGE_SIZE */ + size = nc->size; +#else + size = PAGE_SIZE; +#endif + + offset = ALIGN(nc->offset, -align_mask); + if (unlikely(offset + fragsz > size)) { page = virt_to_page(nc->va); if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) @@ -104,17 +106,13 @@ 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)) { + offset = 0; + if (unlikely(fragsz > size)) { /* * The caller is trying to allocate a fragment * with fragsz > PAGE_SIZE but the cache isn't big @@ -129,8 +127,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, } nc->pagecnt_bias--; - offset &= align_mask; - nc->offset = offset; + nc->offset = offset + fragsz; return nc->va + offset; }