From patchwork Sun Apr 7 13:08:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13620164 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 D5EA8CD1296 for ; Sun, 7 Apr 2024 13:11:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F12866B0087; Sun, 7 Apr 2024 09:11:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC2A96B0088; Sun, 7 Apr 2024 09:11:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CED356B0089; Sun, 7 Apr 2024 09:11:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B0A9B6B0087 for ; Sun, 7 Apr 2024 09:11:07 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4D80F1A02DF for ; Sun, 7 Apr 2024 13:11:07 +0000 (UTC) X-FDA: 81982771374.05.4129DCB Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf01.hostedemail.com (Postfix) with ESMTP id 040A140003 for ; Sun, 7 Apr 2024 13:11:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712495465; 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=6cbmJ3Bqjx3XmshEl1h+C2PeMxJYAdoZFxbtmgbCWYA=; b=E/AJTVZQGhpqyWy+bN+L5GaEvKKiA+8Et4SR2I6zbyqFeIx2UJ9DdK2iyYgBAgg4FhBe/+ YJs8DTokTWO7eaDamLUKCgQ/JE/kf1hjxfd+E8Ve1j21VNF9zKEh01j99fII5CdqE7wMeF NUeFy1FylP28sIDIFDEX9ximi1O++0w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712495465; a=rsa-sha256; cv=none; b=WmEHXhXMSOfg1tPjoi6uj/0Hl+ui7sW5SkSHxlJHSJLBDNXAIhPh3clTrTWzH/zobCLPEU 1XsndpGKfj5YS92M5RKO3qF9/dOx7Zzw/N49zgxfcyMB+EZMDRhn0fHcfRtnULjo3AoHDV 9Hy4l3ss8yW6Djkp3naqgA5fh9wdMFk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VCCFw0Q1Tz1QCR6; Sun, 7 Apr 2024 21:08:20 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 8DA4B1404F7; Sun, 7 Apr 2024 21:10:59 +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_256_GCM_SHA384) id 15.1.2507.35; Sun, 7 Apr 2024 21:10:59 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v1 02/12] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Sun, 7 Apr 2024 21:08:39 +0800 Message-ID: <20240407130850.19625-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240407130850.19625-1-linyunsheng@huawei.com> References: <20240407130850.19625-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: 040A140003 X-Rspam-User: X-Stat-Signature: hii5adfmu71eifpcy1693i3etzigoqeb X-Rspamd-Server: rspam03 X-HE-Tag: 1712495463-118671 X-HE-Meta: U2FsdGVkX19Kz3nPlQHgJgBRV2SZuu3LEoNwhddcEAifeEMXMy2KS9i+yTH6lpdPbBr2+JsUhADyY4IUn+/n/ABTzewxPiXvyIzLFaAeRNQHDZp2CCQcUFATOe0jWfbcf8x2qVgiuK6yuGNad/oYr4aNMa2LZs3KUOmYXnm9wKuRCRNpuLDBXVrpmvjS36Wk05MhAyVCRH4xXHHK3ZZ+Bxxp/iyu5uiAKVe7sCkrQyRe58BKYna71SfO0dmlZYSDU/FUQGK5qqa4aSNWblfxs9EbNCKJIJv+IMcBRhDDmmIdo6e2uEBGIw/Xr2w6IBtPPiu7UrezoAPowq0hDMtLUTJ7Jud8IrQiBZ5n/Q9sq//mt76cv2SSg4YngUFwxQ8Vwlf2VoUF8R0rJQbz8hfgYM1lYsvZvWSzJt660BlTho+EwrQ9uDB/AVIxpT+4Sweu/XwcbCiR7zL+6klhhP7k6zhoC2NmkKkvM5J7kT+7QTG6oFI0ebmvmxVzGqZ1zeTqAYeXRL/jX86D3VIvj3kUJbva4PuWjBX5Gka1FNFvn7OhKZOmeU6L2E3VkLD30QrN7C9NmPk41IyWk4QO8QqE9Vz9wa0k7SzYZAR6dl0ItnXiJO5p1pXeAPhbkanK2sTS3KHzq3BJhug3ld74Gpts+cY//pOjZOSq6UETKeFIjKB9wDBs2e98ysJEgm/aT9wZFfqwXeQnUjiTN+RGYnKfx4QhTcX8xLfCvYtzLIKZvNlvE0Ocl7LDkKRCL17xAea+2Fy7jKyomC536a6c1ViLr9KL1mMeH+Q17IhYuZLg0mMb2Xg0ZWNtYgHBWjuh6z6WO1jPvZsaCamEA4oONm5rUq6+t4jVP5Hxaqhpmz8tbl8s5/7Muv6b5uR8K1EovUY7zzN8MJKz+E99YDsSavH2Vi3CS/A2iR6nRWd4DY6yyVgxe1InBWsKYtIVFUQbZtV4DuRwWjsukyNb0z0JlR3 DLA== 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 above 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 coaleasing 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 aovid 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 | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index a0f90ba25200..3e3e88d9af90 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -67,9 +67,8 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask) { - unsigned int size = PAGE_SIZE; + unsigned int size, offset; struct page *page; - int offset; if (unlikely(!nc->va)) { refill: @@ -77,10 +76,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. */ @@ -89,11 +84,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_mask); + if (unlikely(offset + fragsz > size)) { page = virt_to_page(nc->va); if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) @@ -104,17 +106,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 @@ -129,8 +127,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, } nc->pagecnt_bias--; - offset &= align_mask; - nc->offset = offset; + nc->offset = offset + fragsz; return nc->va + offset; }