From patchwork Wed Jan 3 09:56:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13509825 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 9AB8DC3DA6E for ; Wed, 3 Jan 2024 09:57:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430688D0062; Wed, 3 Jan 2024 04:57:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B8388D0061; Wed, 3 Jan 2024 04:57:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 231FD8D0062; Wed, 3 Jan 2024 04:57:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 001F78D0061 for ; Wed, 3 Jan 2024 04:57:27 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C2642804EE for ; Wed, 3 Jan 2024 09:57:27 +0000 (UTC) X-FDA: 81637547334.11.9245C3F Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf29.hostedemail.com (Postfix) with ESMTP id 59195120009 for ; Wed, 3 Jan 2024 09:57:24 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 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=1704275846; 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=SGK/CWaMN9IPrEOdnuuT6UaJyfBY/KNouXC35C1lu4Q6O9Xf1ylwQTAbUWu4T9p3jrbhvo TOwhw/wZXxiW/DvHjse2MBXFDLbDcOSoPHjl/GM4+6X9x2CtZBuqc1gJW4zFfIhfOM577V mkfU6fWaNJim89ta2ub87KenCFH68i8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704275846; a=rsa-sha256; cv=none; b=W95NH5HOV+G9d34pcmYAi5Qfve1+APgMB/klfpYie/zN3WYI6/lixL6YyS2sh/xRiGchNU VrN0od0gQcGwl37pTf8IQkmnebBf4Z76H4ce93A6Yg3u/0uUpvHQiM79tC+X1UGzPKKqv2 I8DLyYg1rA1cy/ys+pk80T9iVABmdsM= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4T4lVq5pjPz1wrCT; Wed, 3 Jan 2024 17:56:51 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 86A2B140258; Wed, 3 Jan 2024 17:57:21 +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; Wed, 3 Jan 2024 17:57:21 +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: Wed, 3 Jan 2024 17:56:46 +0800 Message-ID: <20240103095650.25769-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240103095650.25769-1-linyunsheng@huawei.com> References: <20240103095650.25769-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 59195120009 X-Stat-Signature: 1bujg8uzehck4tdj8kjc8o3eoqc65p6t X-Rspam-User: X-HE-Tag: 1704275844-102573 X-HE-Meta: U2FsdGVkX18AtcF9cs8nwIa9EJhIcitsWFmifcjc3HyxGck9nJIdMEMoqm8r7nCGNnEsAWiaKA6GP7Er+rYfaFZgq0ua1MFemsXeJ7W9zUAd2bqsrAP34fXAV/hpiLIUfz2pudmBVADc1KocRkR1URRjkoF7eVQmQgQUqpSpveSxVy3U2w410B4PjTZmxEsKHxNFEY70H+OgUQXUU6LOKvdXh/UPdw9jHlp/t0PiFnHg5u7zK594JqnIJaE8oQxVgfi3lIw0Z+X+03aW9iWr9v0Ro4qRN6fiqJPyK4g6uplN4ARxhbUF5NWfd2Ch59iGwsa6zBivvrxH5WPR7ANZ/AFXOoieyWYfJBvQekiIeGugkRzKNL0+TIo7b6KEKxHG4JeL63dHERxXMOu8H5Nf9q+kuhl2hOkuWeA+Yf7ivmf5VorXGM80qxXYcRXSuW6D9P6E4dztIP+IxnLW5QdAN16Z6xj5oj3DgeIjrHQ9So/JuWwYC5VLub6XLALNCNxhDxspCadnT8odWfKpHXiMwJ9axdrkwS4choyj5Qy2khZpBLNO5zf26Mm9nV2HMj9xGVlaoPoKtQkbIlcY06EJxXq1Wx9fr55OOG17WVTZ4WP3KcDnPNs79llYxeRJy2pkSumjw0wg5RMUT9NzDGi5bhjc4UNKLGS3pSh5ihzkKnS/2OHkjN9GCGcFsFIiY3DWvdmF7PkIX54Pm9bMWg2x+Ol5+UmRkBx6KSlfNXM8MIv8XPoBCUuPd0eh3zLKT1R7ngc17BBo5fYZwhg3tgm0In2v4r0KrOQ1xql8zqU+KDhavcOuLoqqxtnPXIo0uR82kiXtLOeHPUO0miuTGvbYFKwn1JzZ0PPaWFdYwp6EqlsgfsM6HSNeDlZiSzptd89JIzTjlTI2wNqWUT6qGJjqD8/JTLWx/s96W4ZalpE4OPoochiNizz+xpdvC6+S76w1m5ZgrNSB1g5/ymq0G9i wIOV9pMh Vw3L0JE3uwrOqEQXhiMEiwOxoGkJ+GFMpXeHRkr9v2n4NaLPHpDTzk5E3/2dQI15Eknoz39Xb7tsrj/WQzM+Q4poWkC+EUbj+RT4Jnzj/gx2zNBuShdhfWf2zcRmBdEVWh1gNmKMRUi+Iygk1wxrWVn4cqcq/GCwfhjtDvPq+ewl60FHvzXMxYQbFEYJ2gKloUPCJ/eA09VluajAeiegZvIzQ3W2vwC2hqrfnxIHqtTFhSB3TDP/Ptp7SdXgXncqMPPXPddiONYmvkOEVgP0VtYIzACoj7uJSUvDl 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; }