From mboxrd@z Thu Jan 1 00:00:00 1970 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 74AEAC3DA6E for ; Mon, 8 Jan 2024 08:59:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF1546B0074; Mon, 8 Jan 2024 03:59:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA1FE6B0075; Mon, 8 Jan 2024 03:59:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8EC16B007D; Mon, 8 Jan 2024 03:59:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A61A66B0074 for ; Mon, 8 Jan 2024 03:59:58 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6DE73C0729 for ; Mon, 8 Jan 2024 08:59:58 +0000 (UTC) X-FDA: 81655546476.15.E757A34 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf14.hostedemail.com (Postfix) with ESMTP id D7B3810000D for ; Mon, 8 Jan 2024 08:59:54 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 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=1704704396; 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=61kTnVjsFHYoVk33gB2aH0tjhCFRp4+uId6tGitbWLs=; b=7IzLPbHdohA3xwck5+lNLQJg6LlZ45huxOmSCIof1V0beIFHdlMsyg3a6bNFjyeVGPAank 811otZiwthigK3yaMipjVjtdlRuYyrjJm+QQ7UQlLas6BNmcBpfnbNJSX/MmSxezHQWDfL Vu8cntyKcIGEwzfxEtca2UHjZK44PH0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704704396; a=rsa-sha256; cv=none; b=fqIS261taMDDrQmYkF9hNs9nNhmnPrGLN6JoZ426UtQRl1pJSWPxcOTpFgKGfOMj5WHMaw I82A3s7cnttsHYQSw96vZfOxxxS+uwPEC1Ghg3Hdk0oxAYyEU+TrNXu08/jzzkoHYu6n0X zTentr7InhGdvYXXWAp1XwSzdIRnIDo= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4T7p0263HfzNkdv; Mon, 8 Jan 2024 16:59:14 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 5B9121402C6; Mon, 8 Jan 2024 16:59:50 +0800 (CST) Received: from [10.69.30.204] (10.69.30.204) 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; Mon, 8 Jan 2024 16:59:50 +0800 Subject: Re: [PATCH net-next 3/6] mm/page_alloc: use initial zero offset for page_frag_alloc_align() To: Alexander H Duyck , , , CC: , , Andrew Morton , References: <20240103095650.25769-1-linyunsheng@huawei.com> <20240103095650.25769-4-linyunsheng@huawei.com> From: Yunsheng Lin Message-ID: <74c9a3a1-5204-f79a-95ff-5c108ec6cf2a@huawei.com> Date: Mon, 8 Jan 2024 16:59:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: D7B3810000D X-Rspam-User: X-Stat-Signature: x5o668j7wpcx5o73px4myma9rtojpdfy X-Rspamd-Server: rspam01 X-HE-Tag: 1704704394-265978 X-HE-Meta: U2FsdGVkX18kgEe5nqZLQsqfvAEn0JzEbrAj074l7C/l7q6O3KRhdD/biZWNBpvZ2iLwQ6VL0KJO4E/gLkbV3sTRXunpipcljlNHQzZ2B77EMXZA4qqIJwx27KeYbSmeuFIE6Kx3Qtix1FSu3I0ydNgQZQmFbQQb4MLvrk4yjDCsMLDQvFUlffrG0hR+XDG3kvKNtR2k0A+rAtndchObL2OwY+3fWN6Crc4+Lsj3f6jHBO15u1QG1tmeMxQ/ltqMCG381ADZxW7FQSnjEM97Pk7fh9e7vbv6yFLJfLKZitbTPMT+3hG7+xwW5wJn/26t/wiUvOfaRbE/MJjnUeuPnTuRb7oPS55gPpQ6ALaKg7/d5AOFviAWxmpFNj+dmetuFsB8xcq+z+FZd6BZBdvPsaLNxg8244HG3ylieUyYHXcNvdWV2A9D6xspYnZ1l4cMsjwZy7uMNW1kuB+kZEbOO4T0M2nSDq3hbSOpzqGG4mCBZJG+4zRVNZQ/5khWSeJiPdu4AhaIi9YUSdLEzgZkPNKMrgNR5KqKVCajs32I/LCw03vRFuEfsK+XXwdu8+Joil9/oKAH7Q5NJL3SGgaObjqgri/2eBIZKaB4gCB46/5AEAjkb/xaE1dwNAdRHry9jg0hD07dJ/LrTcv80wnG9vlHGuBhQmo3uoKhY6Gp193jorKGvw57cnC2JYw034LrTSTZg1t9LvN2J8y3MtMgwg/127FnadT0u39nHh40qUusN/lSc+fpdcwfh3Fx0K1Im3MgZWPvzAUBas074YYgFr+0hVubUywvxIOAPVqPhIYv5u8cSwQbNl1N8CJOMVc9pl+V/mqj/COQAOwpTSkrZr6KQBVOhEhKphYikFIWEX0qk3liXOAyYIpZnpWEQmdkCZwiFuQOITCo/UkskvHwnZrK/wBTQ4dDxVgwP1Ptl2BPgPaKDKrv/nwX7DZc1e7DsuBu/fs2JboNK4R2QV6 lE845eab +gyEO9SXGClrkKmk9Nj7cWcZzSwhSvzoHB35m1IJxt90hbe9HIYlKmUSchSirR+WNaWv5iclWY+GEODvRrdmBuxmGxbJ/sq799GcDFTUCmAT0bBz1tmr/+/ay6dWJnSW9M18vbqL0vZswo97hRzFRBWaoYq6UEBL9JQ8CSO36Nau3z10L2PGdJUA7Zee2y++q7ukxtjQ6cJkHKB2Y2dt1X3t09DVxabHNh/x41Y1mlv9zS4Xn7vUVKVDVYmUj69vcCBClW3B/aRXrNNrR2SO4cpHOfwUwwzmhLGcoQlU24uNSEhU= 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: On 2024/1/5 23:42, Alexander H Duyck wrote: > On Wed, 2024-01-03 at 17:56 +0800, Yunsheng Lin wrote: >> 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 > > There are several advantages to running the offset as a countdown > rather than count-up value. > > 1. Specifically for the size of the chunks we are allocating doing it > from the bottom up doesn't add any value as we are jumping in large > enough amounts and are being used for DMA so being sequential doesn't > add any value. What is the expected size of the above chunks in your mind? I suppose that is like NAPI_HAS_SMALL_PAGE_FRAG to avoid excessive truesize underestimation? It seems there is no limit for min size of allocation for page_frag_alloc_align() now, and as the page_frag API seems to be only used in networking, should we enforce the min size of allocation at API level? > > 2. By starting at the end and working toward zero we can use built in > functionality of the CPU to only have to check and see if our result > would be signed rather than having to load two registers with the > values and then compare them which saves us a few cycles. In addition > it saves us from having to read both the size and the offset for every > page. I suppose the above is ok if we only use the page_frag_alloc*() API to allocate memory for skb->data, not for the frag in skb_shinfo(), as by starting at the end and working toward zero, it means we can not do skb coalescing. As page_frag_alloc*() is returning va now, I am assuming most of users is using the API for skb->data, I guess it is ok to drop this patch for now. If we allow page_frag_alloc*() to return struct page, we might need this patch to enable coalescing. > > Again this is another code cleanup at the cost of performance. I > realize many of the items you are removing would be considered micro- > optimizations but when we are dealing with millions of packets per > second those optimizations add up. > . >