From patchwork Fri Aug 23 15:00: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: 13775385 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 4A564C52D7C for ; Fri, 23 Aug 2024 15:06:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B36B7800A3; Fri, 23 Aug 2024 11:06:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE64C8009A; Fri, 23 Aug 2024 11:06:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AE16800A3; Fri, 23 Aug 2024 11:06:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7E2628009A for ; Fri, 23 Aug 2024 11:06:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 359241C4B68 for ; Fri, 23 Aug 2024 15:06:40 +0000 (UTC) X-FDA: 82483836960.11.EB92121 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id A65861C0028 for ; Fri, 23 Aug 2024 15:06:36 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724425530; a=rsa-sha256; cv=none; b=IUgOfk6avBQml0Eb/Je2jFwBPwJP78YNm55dKvhdZMI55MKycJkQzW4ihW2GfV37HnlAMa 6pjx0R9SjvixwjF/BjDLgyCMGJZVuoUPQJfhrmtYdj7aAi4GZUrEsclDIuwr1A72D3Ecx4 4WYIJhIEQlM0nenpoj9OotIsFFjLz+Q= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 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=1724425530; 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=1F3qEeiEixeBi82tYirsI6u1RGVGGThNAh4Y2uzWuWhRwwoIml9ilgwMQW/beBRNuGR7Du ewRq44CxcI7VirFsof+AyZKqlcbI6QYeR7mXCt2yRehpxU3kAsNARFB2TbUtsfmQairJp6 iYXfH//la2ir8HxdOzET0NReCgsIVig= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Wr3L63s6TzyR7y; Fri, 23 Aug 2024 23:06:06 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 8F347140133; Fri, 23 Aug 2024 23:06:31 +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; Fri, 23 Aug 2024 23:06:31 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v14 03/11] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Fri, 23 Aug 2024 23:00:31 +0800 Message-ID: <20240823150040.1567062-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240823150040.1567062-1-linyunsheng@huawei.com> References: <20240823150040.1567062-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A65861C0028 X-Stat-Signature: 7soa3tyewoz4yfnej1d3wjgnfyyo7bow X-Rspam-User: X-HE-Tag: 1724425596-986135 X-HE-Meta: U2FsdGVkX1+MvlO5mOXE1G68uJnZARaJ2bvTg7fmldZJ2Q/1YYZAdo/XAn96vFJTUdonz4nOMh8z2a34orD520w3zis/jcZSsOpOlLTcPIN5hLOf2GpWXNJZxnoIbROmrIaz6mug/v1h1CWmT4P0pYVjGZ16Ypvn+oPy7G5kz4VQ/z21j0BhunDmUJ023retribqrB8YkzC9haBpVKBTYLONayO8t3bfjRVa9idLidqR0I631D40ZJOyBPNowOgWNRiRTIT30T89B9vhu45yaOsMPrt/C+i15jLeA6klOaNQeUcEKDCqnam/7CSuDgYDIAiIwcGNqs6/Z6lB42PkKVYBW3IdUaE4LWrVmN0f2M6lKZ1rEsf+QeJ7CqhzVSvbFysDWzCPzleL9hnKl7sNRhhgsaxe/yMhwZl4rLd1+geEgnssNF/sYEmZrQq3ynI8oTQhZXeqqxeOLIr1KCpZHcsiIq7/A6roRXMnHuRu+mXy3WpWL3WpCPProIiPNB0M/G6xCTZAs0b6ClRXb5te8WJbPkdDZboDGqIPwisFmIC7nif+F/nsyXsMiagDtjlvS8QRs7R4egtyouHVYo5VynNXTVWqSsxIvleznRd8JIRbBHIFFWjISXsOsi/LqVtvkwkJEPyt7Kv/V7RqAFUuDHN1v7duIzMalwdI1YR81aANGidyjwAx+lxaVOPsDpp5NoyGwBj8xEebIj4ChoyL5FEn8xWUQrhlTUOJ0htFR492NuYveBLMZ7j7BK7izwQKgEZmSy4xJRI32PCWHUYN9g2TLpxRZhlBXgVhtQotf7Ad9IzHp+2MeC78DYkiJPGqR8ep/cONadLY6sEQLSYx1IX8IPt6PECHv6QnTZLk785M28wBLtyU2Bdv+/V+7L+QL9mFd45PG8G1LvAQgocnayu0W4ckmcC3VroCyX1Xq0VS6Cl3Gp+hUloQQ29Xc8GUyKg2mNpIVzGfZKkCo4H PahbFEfw Dm7focbta++gkU0mAFJhD1yGZD22cf78AEKo+Z0UCsGBfnwqYj5WinJtKnGwpZDQkZ98yoFp0R2zG7DD81Ucp9VxuJGmIdJvYUug7P1+GhVzu4KtlkJD6qZ9vw23N9MEsifOdrVt03264H76pdZaIXRyqSl0Ht4G5t4hZs05OxYrKWddLmz9FDb2Ur+doVmqevCRVuCmyTNL6xJ89KBHfPBLuchvKsVifLdC8RoNuIqX1M9AoSWwp448Ckp2q+erEG9imZjHIuoxeWYzZaWp9PWXU9qHlaqKZpgokijiUQX6lSRfa+ZXDuFm417NJgP7SUBAeYlHkv3Ie5ZbBqVbYbOK1cQ== 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 --- 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; }