From patchwork Tue Dec 5 11:34:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13480074 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 7058AC4167B for ; Tue, 5 Dec 2023 11:35:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA8726B0083; Tue, 5 Dec 2023 06:35:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D593B6B0085; Tue, 5 Dec 2023 06:35:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C485D6B0087; Tue, 5 Dec 2023 06:35:00 -0500 (EST) 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 B20076B0083 for ; Tue, 5 Dec 2023 06:35:00 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7E4A016033A for ; Tue, 5 Dec 2023 11:35:00 +0000 (UTC) X-FDA: 81532557960.27.D511081 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id EDDDAA001F for ; Tue, 5 Dec 2023 11:34:56 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 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=1701776098; 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=sY6rt6ZDWSPLy+R4GC8GwC8YJzCuoyXBaVHV+cH68pA=; b=3E2wtBq7RCatLZX3fG/d7cHzRMvVL8eoF+GSucNrVBKsIBRINOXMY/YoAju7bPOOpXImZp Sos0oavXfo+ZnVlQDhW3v1PE4CmYXLn/oFty5uhVlNdFiLdz94jidYJg3e7buYOoDWKL7q laQOzbgjDBHrsRJb3MCW/bvKtHjvZkQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701776098; a=rsa-sha256; cv=none; b=uVVsVitts3F2XhruHLkmJn6QGaLsKpXgZ0WLTZA1abaJC3h0ceJK+Qaup+oOLYhiWXjAiz 9J5vD3DiOnUPJoMHPMdZ/yJDDPeUqGUUJWaZbq/+QMjuZtKh7zt5bkFugrv7q6FyNlBeLf X+LRmOfduKSwoKjIZQjGpUY6UwCLS/E= Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SkyyH27zdzFr77; Tue, 5 Dec 2023 19:30:31 +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_128_GCM_SHA256) id 15.1.2507.35; Tue, 5 Dec 2023 19:34:52 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next 3/6] mm/page_alloc: use initial zero offset for page_frag_alloc_align() Date: Tue, 5 Dec 2023 19:34:41 +0800 Message-ID: <20231205113444.63015-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231205113444.63015-1-linyunsheng@huawei.com> References: <20231205113444.63015-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: EDDDAA001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 48ea1ign864tgh8j9j983da85y4kxwu9 X-HE-Tag: 1701776096-904997 X-HE-Meta: U2FsdGVkX19gylrarJlMtxdKhToCTjIvGNyXwFbKXh1+bfXhCuSEP7F6hFgFFdP2bJjBMa20zp5vs/Kbi0Y9ulj1maaifUiMYinivgyfepIBCEdOjigK5Pr/eyiSmQDdqCkZ8+t3uggmCC1bRZNXFPH6A5jdPebY2aSWxqKe+nWKy7vCTcAdWM6pQRLhjpzD3tTEgH6TGKr4rSwFDqB2OYiGlqwdWvzwWK6isF+9PumZ3Hf6IiYUcx4MaX5HxjYnRon3R+c9PhWbuProbYI4SzBVUB36JLBz9jD/V8blbn5m+d4yKdhuG3rN6CKY3vqTpf9IcwKCYA0Uas++mvndfm9o+wOFJkDFNnBbU+SuoyrzU5yLudr3DZghLkumSDpdd7gdDAczVOF/a840+Zb2YpOZRPgbv/94teROF7hFWs9swEasKVCCtCnzPlZg5vF2DA5B9qvHgrdk2bJsZFPYd1lDlz83IJSO2bm+WMObp9ExcG2j3wHmfJV2OTaXKMf0lkgKYYnZRtddxFPs9iL9RLZDGT03bs3lDpHh47Ojg9Mi9FuhfbWLFNX3gtG4Q90Rr/bUfxLyuz01Xgr7QMTzboprlUnuiG/9Ktvbx4CGJrap7cgcl3yrn/l3qmC6gFdtAYQJpnK/aKH5Op0Exuj0HZfk7QT4e1ci/d0x8EmHjeADnQvLmhCSHzJ6eWDkaw3jPxwP7E1rQiuEUlHl+133+aP92v41F3mzxXh3w03+R3s347Uf7Hjc5+jFIYcTjOp9bHLAJWWhEqcBeehr5Bl7z2fBUPFBPp6Z6fIJQFXUHw2QYQ4clJGf27aGfkD3EOcQq8esvzZC5J7+8tr5KgWcW32ex8dkzkU+mNTwhRwZEgemDqs2R6NHuKdGXSmnKpti7NMYpquyGPpBKDPGgPZ7gLTopdeGiDyn/Y3RJdliifoi2AchesOe7Mg8TErgl/p1x8rgfuLlUMMigMyuG3U Pn+5Bp6k uxgGCaLuyUWkWrtABzVWntf0CiIYTaEhUbM1h3jRvjb+ZbW2db3fDUv3e/XOhpNSwOp+I/B8gzP+VA7Io+tceuv4hdNq06Tt3bpVszPbyibJWNLvpi0SnbLola+3zwiOS44iH2E4CD+HkEzJY1QCqqLon6y/1EG/1YQH8DMkgAt1aJyvAIN4961wHedeOJkuPCKyc91agyuz0SlE3JdqwoGbnhQuXHF3d78eWazGDXXHlAxvoAEDtvWLAnc8HMGwYes9F3r47h3RTtwvd1ort5+ZJjC+eUTdcqNH7 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: The next patch is above to use page_frag_alloc_align() to replace vhost_net_page_frag_refill(), the main difference between those two frag page implementations is whether we use a initial zero offset or not. It seems more nature to use a initial zero offset, as it may enable more correct cache prefetching and skb frag coalescing in the networking, so change it to use initial zero offset. Signed-off-by: Yunsheng Lin CC: Alexander Duyck --- mm/page_alloc.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1f0b36dd81b5..083e0c38fb62 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4720,7 +4720,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align) { - unsigned int size = PAGE_SIZE; + unsigned int size; struct page *page; int offset; @@ -4732,10 +4732,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. */ @@ -4744,11 +4740,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); + if (unlikely(offset + fragsz > size)) { page = virt_to_page(nc->va); if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) @@ -4759,17 +4762,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 @@ -4784,8 +4783,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, } nc->pagecnt_bias--; - offset &= -align; - nc->offset = offset; + nc->offset = offset + fragsz; return nc->va + offset; }