Skip to contentSkip to conversation

erofs: fix unused pcluster_pools for higher page sizes

PATCH In review Ojaswin Mujoo 3 participants 4 messages Aug 16 – Aug 17 EROFS file system

lore
Share & tools
lore
#0 lore raw

cover erofs: fix unused pcluster_pools for higher page sizes

When inserting the erofs module on an older kernel with a 64K page size machine, we were running into the following dmesg followed by a stack dump (Needs, CONFIG_DEBUG_VM=y):

[    4.616501] kmem_cache of name 'erofs_pcluster-16' already exists

The root cause is that on 64k page size:

Z_EROFS_PCLUSTER_MAX_PAGES = 1M / 16k = 16

and, on that kernel, our logic to create the pcluster pool is as:

  static struct z_erofs_pcluster_slab pcluster_pool[] __read_mostly = {
  	_PCLP(1), _PCLP(4), _PCLP(16), _PCLP(64), _PCLP(128),
  	_PCLP(Z_EROFS_PCLUSTER_MAX_PAGES)
  };

so we were ending up creating kmemcaches for nr_pages= 1, 4, 16, 64, 128, and Z_EROFS_PCLUSTER_MAX_PAGES (=16, again). This caused the kmem_cache sanity check to emit the warning.

When comparing with the upstream code, I noticed that this issue has been fixed as a side effect of the patch:

commit 7361d1e3763baaf7b9349c576137851458ad38d1
Author: Gao Xiang <[email protected]>
Date: Mon Mar 10 17:54:59 2025 +0800

erofs: support unaligned encoded data

which changes

   static struct z_erofs_pcluster_slab pcluster_pool[] __read_mostly = {
          _PCLP(1), _PCLP(4), _PCLP(16), _PCLP(64), _PCLP(128),

- _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES)
+ _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES + 1)
};

and hence the final cache has nr_pages = 17 and doesn't clash with the nr_pages=16 cache anymore. However, this is still incorrect as on higher page sizes like 64k we will never use nr_pages > 16 and the rest of the caches are wasted.

So this patch intends to fix the issue on upstream first and if the approach looks okay, I'll send a backport for other the older affected kernels.

Regards,
ojaswin

Ojaswin Mujoo (1):
erofs: fix unused pcluster_pools for higher page sizes

 fs/erofs/zdata.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/1 erofs: fix unused pcluster_pools for higher page sizes

pcluster_pool[] hardcodes {1,4,16,64,128,Z_EROFS_PCLUSTER_MAX_PAGES+1}, but the assumption of Z_EROFS_PCLUSTER_MAX_PAGES == 256 is only right for 4k page sizes. For higher page sizes like 16k or 64k, This results in us ending up with clusters bigger than what we will ever use, since we only support upto 1MB of compressed data. For example, on 64k page size we will only ever use clusters with nrpages= 1, 4 and 17.

This patch fixes the allocation for such higher pages sizes by adding some compile time checks.

Below are the clusters created right after boot on a 64KB page size machine

$cat /proc/slabinfo | grep pcluster | cut -d" " -f1:

Before the patch:

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-16
erofs_pcluster-17
erofs_pcluster-64
erofs_pcluster-128

After the patch:

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-17

Fixes 9f6cc76e6ff0 ("erofs: introduce physical cluster slab pools")
---
 fs/erofs/zdata.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
fs/erofs/zdata.c +11 -1
index 602ba8b7cc79..5c2c22ed64d0 100644
@@ -128,7 +128,17 @@ struct z_erofs_pcluster_slab {
 #define _PCLP(n) { .maxpages = n }
 
 static struct z_erofs_pcluster_slab pcluster_pool[] __read_mostly = {
-	_PCLP(1), _PCLP(4), _PCLP(16), _PCLP(64), _PCLP(128),
+	_PCLP(1),
+	_PCLP(4),
+#if Z_EROFS_PCLUSTER_MAX_PAGES > 16
+	_PCLP(16),
+#endif
+#if Z_EROFS_PCLUSTER_MAX_PAGES > 64
+	_PCLP(64),
+#endif
+#if Z_EROFS_PCLUSTER_MAX_PAGES > 128
+	_PCLP(128),
+#endif
 	_PCLP(Z_EROFS_PCLUSTER_MAX_PAGES + 1)
 };
 
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#2 lore raw

Hi Ojaswin,

Quoted 27 lines · Ojaswin Mujoo

pcluster_pool[] hardcodes {1,4,16,64,128,Z_EROFS_PCLUSTER_MAX_PAGES+1}, but the assumption of Z_EROFS_PCLUSTER_MAX_PAGES == 256 is only right for 4k page sizes. For higher page sizes like 16k or 64k, This results in us ending up with clusters bigger than what we will ever use, since we only support upto 1MB of compressed data. For example, on 64k page size we will only ever use clusters with nrpages= 1, 4 and 17.

This patch fixes the allocation for such higher pages sizes by adding some compile time checks.

Below are the clusters created right after boot on a 64KB page size machine

$cat /proc/slabinfo | grep pcluster | cut -d" " -f1:

Before the patch:

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-16
erofs_pcluster-17
erofs_pcluster-64
erofs_pcluster-128

After the patch:

Quoted 7 lines

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-17

Fixes 9f6cc76e6ff0 ("erofs: introduce physical cluster slab pools")

Thanks for catching this, looks fine to me:

Thanks,
Gao Xiang

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Ojaswin Mujoo
Quoted 27 lines · Ojaswin Mujoo

pcluster_pool[] hardcodes {1,4,16,64,128,Z_EROFS_PCLUSTER_MAX_PAGES+1}, but the assumption of Z_EROFS_PCLUSTER_MAX_PAGES == 256 is only right for 4k page sizes. For higher page sizes like 16k or 64k, This results in us ending up with clusters bigger than what we will ever use, since we only support upto 1MB of compressed data. For example, on 64k page size we will only ever use clusters with nrpages= 1, 4 and 17.

This patch fixes the allocation for such higher pages sizes by adding some compile time checks.

Below are the clusters created right after boot on a 64KB page size machine

$cat /proc/slabinfo | grep pcluster | cut -d" " -f1:

Before the patch:

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-16
erofs_pcluster-17
erofs_pcluster-64
erofs_pcluster-128

After the patch:

Quoted 7 lines

erofs_pcluster-1
erofs_pcluster-4
erofs_pcluster-17

Fixes 9f6cc76e6ff0 ("erofs: introduce physical cluster slab pools")

Thanks,