From patchwork Mon Oct 28 11:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13853361 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 42C6DD1359B for ; Mon, 28 Oct 2024 12:00:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D8596B0089; Mon, 28 Oct 2024 08:00:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 286136B008A; Mon, 28 Oct 2024 08:00:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 101616B008C; Mon, 28 Oct 2024 08:00:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E66C26B0089 for ; Mon, 28 Oct 2024 08:00:16 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A6876161E9C for ; Mon, 28 Oct 2024 11:59:50 +0000 (UTC) X-FDA: 82722866772.09.6A556EA Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf15.hostedemail.com (Postfix) with ESMTP id 4CA38A0024 for ; Mon, 28 Oct 2024 11:59:49 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1730116772; a=rsa-sha256; cv=none; b=kwVQDQIELNF+DPpbnhh3HWz+05JPOJfEf5mEi9GzVByQln2Oqh9vtSs+TB+4ue4x8kj64l gMtlCUhwKA3mc5c/M37bfYcdxr24F0syEdGUg3RHyWTJ1IbExFFHV4dysRjiLmREwMCo+/ lN/OMED0g8d3ElQz8+bA6t6m6JlQbgo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1730116772; 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=abRKKi75LmcSbEZWqBUvRSsRQadP1Xm82D7oThKxcrw=; b=wrcVUCcmHw6nNwR1sTj2iFIvMG+Vc6WXy2LL1GN4d8JpEp1ZkBrBYUuzOk2C2tbnz2lg/b aUcIxaPPHYekqQyBqvCMIkHiYAAtFFp/sOdO72T28qKmv7Bz5SwuJNbkaRZl+qFIjlrWVl /x/dVXVqA26fBjDKdcrrkvQsj32gKZA= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4XcX413cz8z20r0s; Mon, 28 Oct 2024 19:59:13 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id B1EDB14010C; Mon, 28 Oct 2024 20:00:10 +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, 28 Oct 2024 20:00:10 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Linux-MM , Alexander Duyck Subject: [PATCH net-next v23 3/7] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Mon, 28 Oct 2024 19:53:38 +0800 Message-ID: <20241028115343.3405838-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241028115343.3405838-1-linyunsheng@huawei.com> References: <20241028115343.3405838-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Stat-Signature: cozfqu4d973fpmu5adsip1fc3yffj9p5 X-Rspamd-Queue-Id: 4CA38A0024 X-Rspamd-Server: rspam02 X-HE-Tag: 1730116789-46799 X-HE-Meta: U2FsdGVkX1+Y+HWmtpWEOXBaS+2Hs4XlJRVK08Q4+mqY1wWjVKGk/t2DmF3JETm6EpKp8Akfj8Txe/YbEw77I1xcIELABvkBGSjUD8sSKfNBRmszz8/c1zOik8yaho52+qlFg8Z2y3HBlPwH19uSK8BkeIizRgaogHo2dQGG21Eo3EJRRV9CItNsugSqRfkYqkf9ETnhT8YhU6jehSKpZifnY522bKXvN/1sIzQHr8Vs0p3TZN6G1wnggoWEgkmMuZxShuRYq/zMPjph7LfOttDof4zAsEawCkB7klRj3/KQY1EiO++w8/XaKReXKOFdn8BFX8Lip0kdRxQ6avtzSGCVuRWozrW/+tlI0XXFe20FeU6/ciIycRqsrezKtljM1nDrbafigL6NNGMQyvqMobaUfkIIUS32Qh5eeq1xZ/hwDj4VzYQuuZtpQezrR+plyh+0roZM4RB3Lyw4gZ+V75tZEOX2JQmqOp+6msb03rAWoLy+i3/B4jl3Z5skHtjT67Ourw1c3RQ72DllW4aKmJKlwwYMtir0ODXSzgKWB0Ng2vdWsfsUKUGbSxhsL1xerdXDMJHf18O5111ZFjPKGe3J7R2oRGW9Bv3jTpRQqWItjtrD8ucdmpTbgOUXb7yZ45JB3dAOswT9n/f94mB1WQEipr93lqMIX2F1flUqkrEetfBo0CZCa+Rdcu0idPiAkUZkBraQIJ8sxm6ZHri5VScJ17DevSjalqB8Lb2/zAfIhPqfE1itahnwAtp8I1uwogR9Y7ZOqjnz1B2YXaBsYhfT0Ty1FC6ug5cvvEN9yB6YelNNPJ4TjuQz9VIfnpRrFiRbvoy0ikhgWXRLN3vvolGmWw6Ham35sIm9D+8OaavRyZuxgO4T+EmJsV/P9VjYE+bK86B/vPtkbSVVwXZ+hX38sGjnzDeMIicnN49JZ/8mRcSz34XpDULKcZQzt/EoZ1/Tq7ET+0CM6hco2ny WLgRr3TJ NqAlDeyPCYW8zqQX53GGVTtqjIo95BFdvfW9C01qIPVDfgTB866ZOd3Ft6h9+HenM98cwl+aQUVpRnyC2FjDcd0WdM7BGBkhwgJAH7tbJZ/jxIn4jFt8KYJgKbh9nRVZ1PYs0S8x2NelT6RGj6vZda+BlBqhNWW+5vznvngQtC5psGacF9G9C/aPzJQr/L1vWhCOhbhOXiHS/88UQaPA/gzhLthZsFe+OMS12qkhGWXwvIsG3hNHE67VI3Wu4OZ27NBAXsRqbe17LD5DpRgX7ZjGTYe/8EeSEiz9uu5oelzLaUM9rAh1FQK5vmgUmy+gVQFNO6WpPenc8+3x7xYsjPndy/sD7+UQG42Ca3wh/heJwAKM9xaWZxCxNTFsQu9tjTCJ6t3eRh5S7j7zBUdnIfX2YiN1urI3Ho8vT3Oc35xIg+5LwQQIK65WEEyvgNvaOyh04vrXUrsG68gRRhHl2qKtaynpbL0rO1hdWfil+Ih/y1NFO7HCNONIXxTh8zgfv5AnMnibKaDi9+s5kaSQiqKE9rMIiBwcFOyZnV4erAc5orMde/ly8cYyJozFYFj9JyOdGuHDxIL9kbhE8I5cEeLPvgLx4rD5oXIVq92C05ITnx1c= 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 CC: Andrew Morton CC: Linux-MM 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; }