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 6D61CC61D99 for ; Thu, 23 Nov 2023 02:25:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D97366B05D5; Wed, 22 Nov 2023 21:25:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D47E46B05D7; Wed, 22 Nov 2023 21:25:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0F296B0616; Wed, 22 Nov 2023 21:25:42 -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 B2A116B05D5 for ; Wed, 22 Nov 2023 21:25:42 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8285C140B1C for ; Thu, 23 Nov 2023 02:25:42 +0000 (UTC) X-FDA: 81487628124.21.3B4B6B6 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf10.hostedemail.com (Postfix) with ESMTP id AFAACC000E for ; Thu, 23 Nov 2023 02:25:40 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XKNsRTZM; spf=pass (imf10.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700706340; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=alCRNwrrdh7rHKNUzjSmzrgdnxE0eijK4L857D75ssc=; b=PwyDYFKUixGSOU33KpuxLDTpfZYHUVCV9seBY+Qgy/nHNPIZXzaAX6YQZSHCWNCpgBGSnQ MosZcTZHnhHeq4QebslssWaVbJ2qWv64KHnzd7jKcNLrgSHpjYJGkTjNrcpTwCJaV71s69 5CfXxgaxXj2binK0F5KRcWDQnosysgw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XKNsRTZM; spf=pass (imf10.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700706340; a=rsa-sha256; cv=none; b=QcF3Hroh9N/TrKhnmqGwCw5fNIHhVeMoWjahfIKw/0+n1cZQ3ZKaKk5pRxY9MEZ8kKIrmV jCPqSZ14w5HyIVkfvRL5E4SG2rquXMGCMbE2l+Ieb89mli/W9qJttvQvDiPUaV2I0k0Kez dRoZeMrKuTjck5Yv7q9bejVGeV77fM4= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1cf7a1546c0so3570005ad.0 for ; Wed, 22 Nov 2023 18:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700706339; x=1701311139; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=alCRNwrrdh7rHKNUzjSmzrgdnxE0eijK4L857D75ssc=; b=XKNsRTZMbbbhnUkIQehfd0M9mjZm9rNVfREIawMB6T7hBX+dTTPTULnimnYo2x4ySZ UeOH7eZ/1j9ij9Eljd/GsARtYGGAvk9vvRtGzBCSeRGHerI32HQ4H9fMwYP7ewyk3nko OURbTPHdFCHVBOWjiPQyRq5rjwMJHOcFWTFWKLwnum65ZQXgVJkyn/9uCxR+jOm5Y7uX b6KPINHw9avqJjkOgd4E36XCT9EeuIJkVxRY5LU7NzuXMuhbwp3eio4m5D2pGYrnpgdq TOmN3PPGET+wMEtv8eN2VnVHAwWVbwT6PIzudeG08NEpNkPd3ehQwjeCQV1o6Ps5ej38 LKOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700706339; x=1701311139; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=alCRNwrrdh7rHKNUzjSmzrgdnxE0eijK4L857D75ssc=; b=u5bPqtP65bKIU6xwB8cCPuZmsTvTfH5DLuCshHkUuTa0gSFgUQiV8/iknya1Z6Hi1s zxFgtl157PjAihz+GFLKPFGJqw5H6+wHTj6NdYOZQrf6h5ewvUeCznX7zEx91i8GAFk4 6fNaBfw9icP9SHIz+Mjuc3uPGnhwYtiro70vsLhByFOxrs1RMCRvXW+8HwmyqAL7EbUo s5mIuRVVGch35MgIqDu3eD+KmQCuK/PhjgcYASwwoUL6LucIaq2r02jP48gEmcefOa72 1rou/Lz+8qD+g9ZjhV17NgU1AN20MU5h6XPtERuRmrcdJom2GSuVqhjY68nZSEZ2GQyw 7Tog== X-Gm-Message-State: AOJu0YzK2F7QVHxD2Tox7GBTApdUCB9J3zzomiBOMWs8X+L5NYHskXzM PUQNclNzVGqrrR7VvLoBg8M= X-Google-Smtp-Source: AGHT+IEG52qjzrUeruPSojmlN7ETuyzZbhdWyD2gZBEzpIbw7WjFTO6cPT+hHLaRHL7XjIPh8c6egw== X-Received: by 2002:a17:902:9044:b0:1cc:29ed:96ae with SMTP id w4-20020a170902904400b001cc29ed96aemr4162097plz.41.1700706339368; Wed, 22 Nov 2023 18:25:39 -0800 (PST) Received: from localhost.localdomain ([204.44.110.111]) by smtp.gmail.com with ESMTPSA id v11-20020a170902d68b00b001ce6452a741sm32880ply.25.2023.11.22.18.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 18:25:38 -0800 (PST) From: Liang Chen To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org, ilias.apalodimas@linaro.org, linyunsheng@huawei.com Cc: netdev@vger.kernel.org, linux-mm@kvack.org, liangchen.linux@gmail.com Subject: [PATCH net-next v2 1/3] page_pool: Rename pp_frag_count to pp_ref_count Date: Thu, 23 Nov 2023 10:25:14 +0800 Message-Id: <20231123022516.6757-1-liangchen.linux@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AFAACC000E X-Rspam-User: X-Stat-Signature: 63rstbou45aip44jp37d4umn53ietchh X-Rspamd-Server: rspam01 X-HE-Tag: 1700706340-549684 X-HE-Meta: U2FsdGVkX1/8n6luG0R1b6iQSGhKj8e6hhQVSdH6aEKgMqWc1YHVWeSUQHkwMTiMOqv1d8z1jE2xsddhto+39sINhsNiQ9zZFG1k3hM3+QuH7jZlYTleH/2N0gOJW9WPW6NOebUzPT0xob86LcJLNafmNAYX9mqe7PSKhE8YIZurldLgwLcfi5hiUpTDvcb+FEq3E0XuZvs5O2tO3G0cSf6DPDxwno+65oMX1UrCvj8AjqIJKlhEHShE3GXd9Jh4hwlLRIXsTBP+9wobPfdntomTdyWZ7hGPKcLLFCpfWqtkTgFdsuBZapqqgjw/EW8R3Od4pwWL9Wh0vYwf5YN0gryF/ZGfhT55OAsxaBATPtjBiaDlLQd5x0XhdDvHEAqyigakcfGdOI1UczkPL3za50MRGo1xWdp+DV3onswJxbWXCsPyfoNlAD2jK2Oqs1eVOrgR5shEmFrWvSeDbBlesYhfjJ5pV3TbnuWRRNsXi0ibbxojiHsLzaeN6U4sm+mikNU1OVP1NrC/JXcUCVY1ePX4e8HhVyf8Kf67lQ8qnhYX0gNh1sPjMLLQ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X2wM0zdy1SAlT25UoKyMSghVnVYo8AmM98X5s7toNsCVqWjg= 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: To support multiple users referencing the same fragment, pp_frag_count is renamed to pp_ref_count to better reflect its actual meaning based on the suggestion from [1]. [1] http://lore.kernel.org/netdev/f71d9448-70c8-8793-dc9a-0eb48a570300@huawei.com Signed-off-by: Liang Chen --- include/linux/mm_types.h | 2 +- include/net/page_pool/helpers.h | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 957ce38768b2..64e4572ef06d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -125,7 +125,7 @@ struct page { struct page_pool *pp; unsigned long _pp_mapping_pad; unsigned long dma_addr; - atomic_long_t pp_frag_count; + atomic_long_t pp_ref_count; }; struct { /* Tail pages of compound page */ unsigned long compound_head; /* Bit zero is set */ diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 4ebd544ae977..a6dc9412c9ae 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -29,7 +29,7 @@ * page allocated from page pool. Page splitting enables memory saving and thus * avoids TLB/cache miss for data access, but there also is some cost to * implement page splitting, mainly some cache line dirtying/bouncing for - * 'struct page' and atomic operation for page->pp_frag_count. + * 'struct page' and atomic operation for page->pp_ref_count. * * The API keeps track of in-flight pages, in order to let API users know when * it is safe to free a page_pool object, the API users must call @@ -214,61 +214,66 @@ inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool) return pool->p.dma_dir; } -/* pp_frag_count represents the number of writers who can update the page +/* pp_ref_count represents the number of writers who can update the page * either by updating skb->data or via DMA mappings for the device. * We can't rely on the page refcnt for that as we don't know who might be * holding page references and we can't reliably destroy or sync DMA mappings * of the fragments. * - * When pp_frag_count reaches 0 we can either recycle the page if the page + * pp_ref_count initially corresponds to the number of fragments. However, + * when multiple users start to reference a single fragment, for example in + * skb_try_coalesce, the pp_ref_count will become greater than the number of + * fragments. + * + * When pp_ref_count reaches 0 we can either recycle the page if the page * refcnt is 1 or return it back to the memory allocator and destroy any * mappings we have. */ static inline void page_pool_fragment_page(struct page *page, long nr) { - atomic_long_set(&page->pp_frag_count, nr); + atomic_long_set(&page->pp_ref_count, nr); } static inline long page_pool_defrag_page(struct page *page, long nr) { long ret; - /* If nr == pp_frag_count then we have cleared all remaining + /* If nr == pp_ref_count then we have cleared all remaining * references to the page: * 1. 'n == 1': no need to actually overwrite it. * 2. 'n != 1': overwrite it with one, which is the rare case - * for pp_frag_count draining. + * for pp_ref_count draining. * * The main advantage to doing this is that not only we avoid a atomic * update, as an atomic_read is generally a much cheaper operation than * an atomic update, especially when dealing with a page that may be - * partitioned into only 2 or 3 pieces; but also unify the pp_frag_count + * partitioned into only 2 or 3 pieces; but also unify the pp_ref_count * handling by ensuring all pages have partitioned into only 1 piece * initially, and only overwrite it when the page is partitioned into * more than one piece. */ - if (atomic_long_read(&page->pp_frag_count) == nr) { + if (atomic_long_read(&page->pp_ref_count) == nr) { /* As we have ensured nr is always one for constant case using * the BUILD_BUG_ON(), only need to handle the non-constant case - * here for pp_frag_count draining, which is a rare case. + * here for pp_ref_count draining, which is a rare case. */ BUILD_BUG_ON(__builtin_constant_p(nr) && nr != 1); if (!__builtin_constant_p(nr)) - atomic_long_set(&page->pp_frag_count, 1); + atomic_long_set(&page->pp_ref_count, 1); return 0; } - ret = atomic_long_sub_return(nr, &page->pp_frag_count); + ret = atomic_long_sub_return(nr, &page->pp_ref_count); WARN_ON(ret < 0); - /* We are the last user here too, reset pp_frag_count back to 1 to + /* We are the last user here too, reset pp_ref_count back to 1 to * ensure all pages have been partitioned into 1 piece initially, * this should be the rare case when the last two fragment users call * page_pool_defrag_page() currently. */ if (unlikely(!ret)) - atomic_long_set(&page->pp_frag_count, 1); + atomic_long_set(&page->pp_ref_count, 1); return ret; } -- 2.31.1