Skip to contentSkip to conversation

net: page_pool: scale alloc cache with PAGE_SIZE

PATCH Applied Nimrod Oren 4 participants 4 messages Mar 9 – Mar 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: page_pool: scale alloc cache with PAGE_SIZE

The current page_pool alloc-cache size and refill values were chosen to match the NAPI budget and to leave headroom for XDP_DROP recycling. These fixed values do not scale well with large pages,
as they significantly increase a given page_pool's memory footprint.

Scale these values to better balance memory footprint across page sizes, while keeping behavior on 4KB-page systems unchanged.

---

Changes since RFC [1]:
- Converted from RFC to PATCH
- Scale defines instead of dynamically capping values

[1] RFC: https://lore.kernel.org/[email protected]/

---
 include/net/page_pool/types.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
include/net/page_pool/types.h +10 -1
index 0d453484a585..08ffa766c26d 100644
@@ -44,6 +44,8 @@
  * use-case.  The NAPI budget is 64 packets.  After a NAPI poll the RX
  * ring is usually refilled and the max consumed elements will be 64,
  * thus a natural max size of objects needed in the cache.
+ * The refill watermark is set to 64 for 4KB pages,
+ * and scales to balance its size in bytes across page sizes.
  *
  * Keeping room for more objects, is due to XDP_DROP use-case.  As
  * XDP_DROP allows the opportunity to recycle objects directly into
@@ -51,8 +53,15 @@
  * cache is already full (or partly full) then the XDP_DROP recycles
  * would have to take a slower code path.
  */
-#define PP_ALLOC_CACHE_SIZE	128
+#if PAGE_SIZE >= SZ_64K
+#define PP_ALLOC_CACHE_REFILL	4
+#elif PAGE_SIZE >= SZ_16K
+#define PP_ALLOC_CACHE_REFILL	16
+#else
 #define PP_ALLOC_CACHE_REFILL	64
+#endif
+
+#define PP_ALLOC_CACHE_SIZE	(PP_ALLOC_CACHE_REFILL * 2)
 struct pp_alloc_cache {
 	u32 count;
 	netmem_ref cache[PP_ALLOC_CACHE_SIZE];
Signature · 1 line
2.45.0
maintainer
#1 lore raw
Quoted 7 lines · On Mon, 9 Mar 2026 10:13:01 +0200 Nimrod Oren wrote:

The current page_pool alloc-cache size and refill values were chosen to match the NAPI budget and to leave headroom for XDP_DROP recycling. These fixed values do not scale well with large pages,
as they significantly increase a given page_pool's memory footprint.

Scale these values to better balance memory footprint across page sizes, while keeping behavior on 4KB-page systems unchanged.

Jesper WDYT? I'm of course happy with this simple approach.
https://lore.kernel.org/all/[email protected]/

#2 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines · On Mon, 9 Mar 2026 10:13:01 +0200 Nimrod Oren wrote:

The current page_pool alloc-cache size and refill values were chosen to match the NAPI budget and to leave headroom for XDP_DROP recycling. These fixed values do not scale well with large pages,
as they significantly increase a given page_pool's memory footprint.

Scale these values to better balance memory footprint across page sizes, while keeping behavior on 4KB-page systems unchanged.

Jesper WDYT? I'm of course happy with this simple approach.
https://lore.kernel.org/all/[email protected]/

Sorry for the slow response, LGTM.
Patch is already applied.

--Jesper

#3 lore raw
In reply to Nimrod Oren
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 9 Mar 2026 10:13:01 +0200 you wrote:

The current page_pool alloc-cache size and refill values were chosen to match the NAPI budget and to leave headroom for XDP_DROP recycling. These fixed values do not scale well with large pages,
as they significantly increase a given page_pool's memory footprint.

Scale these values to better balance memory footprint across page sizes, while keeping behavior on 4KB-page systems unchanged.

[...]

Here is the summary with links:
- [net-next] net: page_pool: scale alloc cache with PAGE_SIZE

    https://git.kernel.org/netdev/net-next/c/15abbe7c8266

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html