Skip to contentSkip to conversation

ceph: fix incorrect kmalloc size of pagevec mempool

PATCH In review ethanwu 3 participants 3 messages Jul 11, 2024 – Jul 23, 2024 Ceph client

lore
Share & tools
lore

ethanwu

author
#0 lore raw

PATCH 1/1 ceph: fix incorrect kmalloc size of pagevec mempool

The kmalloc size of pagevec mempool is incorrectly calculated.
It misses the size of page pointer and only accounts the number for the array.

Fixes a0102bda5bc0 ("ceph: move sb->wb_pagevec_pool to be a global mempool")
---
 fs/ceph/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/super.c +2 -1
index 885cb5d4e771..46f640514561 100644
@@ -961,7 +961,8 @@ static int __init init_caches(void)
 	if (!ceph_mds_request_cachep)
 		goto bad_mds_req;
 
-	ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10, CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT);
+	ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10,
+				(CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT) * sizeof(struct page *));
 	if (!ceph_wb_pagevec_pool)
 		goto bad_pagevec_pool;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · ethanwu

The kmalloc size of pagevec mempool is incorrectly calculated.
It misses the size of page pointer and only accounts the number for the array.

Fixes a0102bda5bc0 ("ceph: move sb->wb_pagevec_pool to be a global mempool")
---
  fs/ceph/super.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/super.c +0 -0
index 885cb5d4e771..46f640514561 100644

fs/ceph/super.c static int __init init_caches(void) · line 968

Quoted 9 lines
fs/ceph/super.c +2 -1
@@ -961,7 +961,8 @@ static int __init init_caches(void)
  	if (!ceph_mds_request_cachep)
  		goto bad_mds_req;
 
-	ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10, CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT);
+	ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10,
+				(CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT) * sizeof(struct page *));
  	if (!ceph_wb_pagevec_pool)
  		goto bad_pagevec_pool;
 

Good cache, LGTM.

maintainer
#2 lore raw
Quoted 20 lines · Xiubo Li
Quoted 17 lines · ethanwu

The kmalloc size of pagevec mempool is incorrectly calculated.
It misses the size of page pointer and only accounts the number for the array.

Fixes a0102bda5bc0 ("ceph: move sb->wb_pagevec_pool to be a global mempool")
---
  fs/ceph/super.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/super.c +0 -0
index 885cb5d4e771..46f640514561 100644
@@ -961,7 +961,8 @@ static int __init init_caches(void)
      if (!ceph_mds_request_cachep)
              goto bad_mds_req;
 
Quoted 8 lines

fs/ceph/super.c static int __init init_caches(void) · line 968

Quoted 6 lines
fs/ceph/super.c +2 -1
-     ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10, CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT);
+     ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10,
+                             (CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT) * sizeof(struct page *));
      if (!ceph_wb_pagevec_pool)
              goto bad_pagevec_pool;
 

Good cache, LGTM.

I don't think this matters in practice since 64M / 4K = 16K * 10 = 160K of memory reserved just for page pointers is already quite a lot...

However, since commit a0102bda5bc0 is talking about moving a pool to be global without adjusting its parameters, I agree that this fix is valid.

Thanks,

Ilya