From patchwork Sat Oct 12 11:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13833394 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 D9E52CF2564 for ; Sat, 12 Oct 2024 11:29:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B5916B0083; Sat, 12 Oct 2024 07:29:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F0A66B0088; Sat, 12 Oct 2024 07:29:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B7D86B0089; Sat, 12 Oct 2024 07:29:46 -0400 (EDT) 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 00E016B0083 for ; Sat, 12 Oct 2024 07:29:45 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A9355121634 for ; Sat, 12 Oct 2024 11:29:40 +0000 (UTC) X-FDA: 82664730246.16.2D82A11 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf20.hostedemail.com (Postfix) with ESMTP id 06EA51C0004 for ; Sat, 12 Oct 2024 11:29:38 +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.191 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728732554; a=rsa-sha256; cv=none; b=xFa/14qPeRcHtr5Vry0NV+LmwEpfwCxHPeaTnZHcE1++ycLDYXiSuKqsEbKYT77DrTKBHz j4O3VwwaGwOWOpvK1cwm5jkRri4CEYWN4hIPPiWcY1PFbHZ2Uf6IrRZ6YEAeaSEc2HuSXq 9SUj7olEQq/wXj8y1g1lxPm/zpWQmjA= 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.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=1728732554; 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=PBbxlB0kz24iy7iokK1TfN2qwdTa4QMZvXDcqO85e8U=; b=YrX4oOvDNe7xAR5pzXbAmPu6A+rLgmFNTacWbAomJeQ327wZeuTAIST077iOyxnjpuFOgE m+XFMNAXxGQStwZfQZnU5Iorl+iKmGPMwH2cKV9eL88VIY6Ws/uw9vtvkjZcf4P23/cOwi tpa2pARQ2VuG7UMA+lpVZ8M2rquUe4s= Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XQh7y5lD4z1j9fD; Sat, 12 Oct 2024 19:28:30 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id BCB0E180041; Sat, 12 Oct 2024 19:29:39 +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; Sat, 12 Oct 2024 19:29:39 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v21 03/14] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Sat, 12 Oct 2024 19:23:09 +0800 Message-ID: <20241012112320.2503906-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241012112320.2503906-1-linyunsheng@huawei.com> References: <20241012112320.2503906-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Stat-Signature: 7k1fqp9i8qubansos1nyr5tc1epm5got X-Rspamd-Queue-Id: 06EA51C0004 X-Rspamd-Server: rspam02 X-HE-Tag: 1728732578-875343 X-HE-Meta: U2FsdGVkX18+UbmXo9dKsdKTPpHKpiRvtST8ZFMEqOb4BSeAfzYxYMS9vL+GBX/sruDSKgwe9at3b9XFRl8YeSUTJliA/YXSho2iQEC5qSriu1IWUCAG43AGiJ1KSNnweVe5NPwVoQZfRyML8VtpzXVzVycxk7phPENA+lLveTDStB083g61yA/Hn5TPBcI5czj2Jd8nEBP3wfSNs1uvDvBViWIydSbUOl2YCkZPEc8SYwyNRTi4Ea1R/losYqjlmCbtMu9/8SCXkUgsJg8a7Bay9KSJUEM8AsCnKRBGjU1BDB+t7g8rvTkFw0Ew94UqzdgNttlsD9Dn0uBRn3h8k2JQXUfyi2ISlSLJzIbNc4pm6zyc5Tybm1V8isI1Tew+D3SgYhpx3uwyvcHQ9jiR+cc6L1XX3A1h0iXaGuemFnLSGCPz98KQPqQD0Bc4iD2h5B9H0bFvXAoh0Qs4CiyrGFQTgKPZDlXafJ81hExyNL+OOe/J9DocjvwXjp8pwVeyMxorh8qCqcVl/prlTojqWSyOHeaczHz0063gLLfPXRCxADwyjGpUqkvax1LJZ3P6E1Ty38FenrSP3J1gCLrgN0QsZor9l88+oWIGmIAJp74sfhlkmqPu12v9gJZ2pizJviPjxGUNEPggYokij+AAQVzEdGVq8fbMyoeQD03m63zYcV+Jr8+M4I529xVuqd+57AVQbVbaSIJEoFl9IS6e0qMl4Y1QRnA3lyN4wq1RQeg8xQaTE0R8ET/6JK6p6t+2tx3VTy18vjXUvndb1zVnEkgA1qTf/qfS98dJYBF35bDmdbFM0apDmFNlCKRjA+LbkGaxUVns93gf40Nc6ku2bHmn8lCzduwkDHNbCBHsxaFvmSMqSom6hUIa012JobHmzHjIO54yuL+wJ8NQ30koAujK+G1GBE4EUvWVzYaSONYTXNXB3pzWQIqW6erLzCLsF4WwwFZWBp91fllQNdb 1Dps9ZiB SisCpfLWghou0H4x8wpM03S7vAc/eFHyhy/sPxMTlZsJD6fX2GB5BlnKOIgya5KbAUUaPRxVl9fSZJ6uvDBY73Y8f/KKrd4Im7X41tPg/iHFgFoBTrrM0Wq8bDUSFHL7EngCG1ntssuSi6Tb0cK2CR9GvW/YcPsanvPRdYQ7j7TaY1dLGKCEUJw2CacdNAzM2+BAd0Vy1ors2wm7+HaICGwjOyKjUNTbVh6ZrSPZjom/Wr1J3e152vMGqr9vraUmN8HmzQjwHJLu3OUWQ3rDO+XWdFn0zBpJ1AnK+6fZEoHBN/qNgoo0rSax9UT2IjAE7vLehfeo5WpjJ03KRrm06/aku+Jr8ik1gQlyMfbFoSo2ttRYi+MoZerBHiTatbymnQ0WwWx65CUq52JQ0mDl4kpeE3zIJiwIM5tdiwBDc2yuhtcQe/renJgEbV8v4yKVPfgUq8m5v16MLEhpG0OeYSgdldiqMTYBh3ofsA1DrpvcOgsY= 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 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; }