Skip to contentSkip to conversation

mm/slub: fix memory leak in free_to_pcs_bulk()

PATCH In review Harry Yoo 5 participants 12 messages Nov 11, 2025 – Nov 13, 2025

Subsystems (2)
lore
Share & tools
lore

Harry Yoo

author
#0 lore raw

PATCH 1/1 mm/slub: fix memory leak in free_to_pcs_bulk()

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +6 -2
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 
 		if (unlikely(!slab_free_hook(s, p[i], init, false))) {
 			p[i] = p[--size];
-			if (!size)
-				goto flush_remote;
 			continue;
 		}
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		i++;
 	}
 
+	if (!size)
+		goto flush_remote;
+
 next_batch:
 	if (!local_trylock(&s->cpu_sheaves->lock))
 		goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		goto next_batch;
 	}
 
+	if (remote_nr)
+		goto flush_remote;
+
 	return;
 
 no_empty:
Signature · 1 line
2.43.0
#1 lore raw
Quoted 21 lines · Harry Yoo

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Quoted 6 lines

Thanks a lot! Adding to slab/for-next-fixes
Vlastimil

Quoted 37 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +6 -2
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 
 		if (unlikely(!slab_free_hook(s, p[i], init, false))) {
 			p[i] = p[--size];
-			if (!size)
-				goto flush_remote;
 			continue;
 		}
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		i++;
 	}
 
+	if (!size)
+		goto flush_remote;
+
 next_batch:
 	if (!local_trylock(&s->cpu_sheaves->lock))
 		goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		goto next_batch;
 	}
 
+	if (remote_nr)
+		goto flush_remote;
+
 	return;
 
 no_empty:
Acked-by on v1 1/1
#2 lore raw
In reply to Harry Yoo
Quoted 21 lines · Harry Yoo

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Quoted 6 lines

Thanks Harry.

Quoted 40 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +6 -2
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 
 		if (unlikely(!slab_free_hook(s, p[i], init, false))) {
 			p[i] = p[--size];
-			if (!size)
-				goto flush_remote;
 			continue;
 		}
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		i++;
 	}
 
+	if (!size)
+		goto flush_remote;
+
 next_batch:
 	if (!local_trylock(&s->cpu_sheaves->lock))
 		goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		goto next_batch;
 	}
 
+	if (remote_nr)
+		goto flush_remote;
+
 	return;
 
 no_empty:
Signature · 1 line
2.43.0
#3 lore raw

Do you guys still need that debug then?
I think this is happening only when qemu vm is working.

I can get results within 1-2 days.

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

83-010 Jagatowo

NIP: 9570976234

W dniu wt., 11 lis 2025 o 16:37 Liam R. Howlett <[email protected]> napisał(a):

Quoted 80 lines · Harry Yoo
Quoted 21 lines

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Quoted 3 lines

Closes:

https://lore.kernel.org/linux-mm/[email protected]

Quoted 2 lines
Fixes 989b09b73978 ("slab: skip percpu sheaves for remote object

freeing")

Quoted 1 line

Thanks Harry.

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 9 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +0 -0
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 9 lines
mm/slub.c +0 -2
              if (unlikely(!slab_free_hook(s, p[i], init, false))) {
                      p[i] = p[--size];
-                     if (!size)
-                             goto flush_remote;
                      continue;
              }
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 10 lines
mm/slub.c +3 -0
              i++;
      }
 
+     if (!size)
+             goto flush_remote;
+
 next_batch:
      if (!local_trylock(&s->cpu_sheaves->lock))
              goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

Quoted 12 lines
mm/slub.c +3 -1
              goto next_batch;
      }
 
+     if (remote_nr)
+             goto flush_remote;
+
      return;
 
 no_empty:
--

2.43.0

author
#4 lore raw
Quoted 4 lines · Tytus Rogalewski

Do you guys still need that debug then?
I think this is happening only when qemu vm is working.

I can get results within 1-2 days.

Hi Tythus!

Really appreciate you reporting the bug and testing it.

Now that I know what went wrong, I realize that slab_debug=U parameter will hide the bug, since we disable "sheaves" feature for debug caches.

Instead of testing with slab_debug=U parameter, could you please apply this patch on top of Linux v6.18-rc5, build & install it, and verify that the memory leak is indeed resolved on your machine?

Quoted 96 lines

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

83-010 Jagatowo

NIP: 9570976234

W dniu wt., 11 lis 2025 o 16:37 Liam R. Howlett <[email protected]> napisał(a):

Quoted 80 lines · Harry Yoo
Quoted 21 lines

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Quoted 3 lines

Closes:

https://lore.kernel.org/linux-mm/[email protected]

Quoted 2 lines
Fixes 989b09b73978 ("slab: skip percpu sheaves for remote object

freeing")

Quoted 1 line

Thanks Harry.

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 9 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +0 -0
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 9 lines
mm/slub.c +0 -2
              if (unlikely(!slab_free_hook(s, p[i], init, false))) {
                      p[i] = p[--size];
-                     if (!size)
-                             goto flush_remote;
                      continue;
              }
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache *s,

Quoted 10 lines
mm/slub.c +3 -0
              i++;
      }
 
+     if (!size)
+             goto flush_remote;
+
 next_batch:
      if (!local_trylock(&s->cpu_sheaves->lock))
              goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s,

size_t size, void **p)

Quoted 12 lines
mm/slub.c +3 -1
              goto next_batch;
      }
 
+     if (remote_nr)
+             goto flush_remote;
+
      return;
 
 no_empty:
--

2.43.0

Signature · 2 lines
Cheers,
Harry / Hyeonggon
#5 lore raw

We wont make it until next week.
Maybe you guys can compile newest r5 kernel with that patch ? We are using https://prebuiltkernels.com/ and do not compiled 6.18 ourselves. We can do that next week. This week is full of emergencies lol If you can provide me two debs like prebuild kernels i could deploy it and leave for testing for 1-2 days.

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

83-010 Jagatowo

NIP: 9570976234

wt., 11 lis 2025 o 19:29 Harry Yoo <[email protected]> napisał(a):

Quoted 130 lines · Tytus Rogalewski
Quoted 4 lines

Do you guys still need that debug then?
I think this is happening only when qemu vm is working.

I can get results within 1-2 days.

Hi Tythus!

Really appreciate you reporting the bug and testing it.

Now that I know what went wrong, I realize that slab_debug=U parameter will hide the bug, since we disable "sheaves" feature for debug caches.

Instead of testing with slab_debug=U parameter, could you please apply this patch on top of Linux v6.18-rc5, build & install it, and verify that the memory leak is indeed resolved on your machine?

Quoted 8 lines

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

Quoted 12 lines

83-010 Jagatowo

NIP: 9570976234

W dniu wt., 11 lis 2025 o 16:37 Liam R. Howlett <[email protected]

napisał(a):

Quoted 3 lines · Harry Yoo
Quoted 2 lines

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk()

to

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are

leaked.

Quoted 1 line
Quoted 1 line
Quoted 1 line

This resulted in a memory leak [1], where 82 GiB of memory was

allocated

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote;

outside

Quoted 1 line
Quoted 1 line
Quoted 1 line

the while loop for readability. Let's say all objects in the array

are

Quoted 1 line
Quoted 1 line
Quoted 1 line

from a remote node: then we acquire s->cpu_sheaves->lock and try to

free

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Closes:

https://lore.kernel.org/linux-mm/[email protected]

Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
Fixes 989b09b73978 ("slab: skip percpu sheaves for remote object

freeing")

Quoted 1 line

Thanks Harry.

Quoted 4 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 5 lines

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 5 lines
mm/slub.c +0 -0
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 10 lines
Quoted 10 lines

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 9 lines
mm/slub.c +0 -2
              if (unlikely(!slab_free_hook(s, p[i], init, false))) {
                      p[i] = p[--size];
-                     if (!size)
-                             goto flush_remote;
                      continue;
              }
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 11 lines
Quoted 11 lines

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 10 lines
mm/slub.c +3 -0
              i++;
      }
 
+     if (!size)
+             goto flush_remote;
+
 next_batch:
      if (!local_trylock(&s->cpu_sheaves->lock))
              goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 9 lines
Quoted 9 lines

size_t size, void **p)

Quoted 8 lines
mm/slub.c +3 -0
              goto next_batch;
      }
 
+     if (remote_nr)
+             goto flush_remote;
+
      return;
 
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
mm/slub.c +0 -1
 no_empty:
--

2.43.0

--
Cheers,
Harry / Hyeonggon

author
#6 lore raw
Quoted 4 lines · Tytus Rogalewski

We wont make it until next week.
Maybe you guys can compile newest r5 kernel with that patch ? We are using https://prebuiltkernels.com/
ourselves. We can do that next week.

I built it and uploaded it to my personal server:
http://download.kerneltesting.org/linux-6.18.0-rc5-fix.zip

But if you prefer to test images from prebuiltkernels.com, I think it's fine to wait for a week and test 6.18.0-rc6 - I guess this will land -rc6 anyway.

Quoted 1 line

This week is full of emergencies lol

Haha I see, I can imagine what'll happen when you test latest kernels...

Quoted 2 lines

If you can provide me two debs like prebuild kernels i could deploy it and leave for testing for 1-2 days.

Thanks a lot!

Quoted 145 lines

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

83-010 Jagatowo

NIP: 9570976234

wt., 11 lis 2025 o 19:29 Harry Yoo <[email protected]> napisał(a):

Quoted 130 lines · Tytus Rogalewski
Quoted 4 lines

Do you guys still need that debug then?
I think this is happening only when qemu vm is working.

I can get results within 1-2 days.

Hi Tythus!

Really appreciate you reporting the bug and testing it.

Now that I know what went wrong, I realize that slab_debug=U parameter will hide the bug, since we disable "sheaves" feature for debug caches.

Instead of testing with slab_debug=U parameter, could you please apply this patch on top of Linux v6.18-rc5, build & install it, and verify that the memory leak is indeed resolved on your machine?

Quoted 8 lines

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

Quoted 12 lines

83-010 Jagatowo

NIP: 9570976234

W dniu wt., 11 lis 2025 o 16:37 Liam R. Howlett <[email protected]

napisał(a):

Quoted 3 lines · Harry Yoo
Quoted 2 lines

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk()

to

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are

leaked.

Quoted 1 line
Quoted 1 line
Quoted 1 line

This resulted in a memory leak [1], where 82 GiB of memory was

allocated

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote;

outside

Quoted 1 line
Quoted 1 line
Quoted 1 line

the while loop for readability. Let's say all objects in the array

are

Quoted 1 line
Quoted 1 line
Quoted 1 line

from a remote node: then we acquire s->cpu_sheaves->lock and try to

free

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Closes:

https://lore.kernel.org/linux-mm/[email protected]

Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
Fixes 989b09b73978 ("slab: skip percpu sheaves for remote object

freeing")

Quoted 1 line

Thanks Harry.

Quoted 4 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 5 lines

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 5 lines
mm/slub.c +0 -0
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 10 lines
Quoted 10 lines

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 9 lines
mm/slub.c +0 -2
              if (unlikely(!slab_free_hook(s, p[i], init, false))) {
                      p[i] = p[--size];
-                     if (!size)
-                             goto flush_remote;
                      continue;
              }
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 11 lines
Quoted 11 lines

size_t size, void **p)

mm/slub.c static void free_to_pcs_bulk(struct kmem_cache

Quoted 10 lines
mm/slub.c +3 -0
              i++;
      }
 
+     if (!size)
+             goto flush_remote;
+
 next_batch:
      if (!local_trylock(&s->cpu_sheaves->lock))
              goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache

*s,

Quoted 9 lines
Quoted 9 lines

size_t size, void **p)

Quoted 8 lines
mm/slub.c +3 -0
              goto next_batch;
      }
 
+     if (remote_nr)
+             goto flush_remote;
+
      return;
 
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
mm/slub.c +0 -1
 no_empty:
--

2.43.0

--
Cheers,
Harry / Hyeonggon

Signature · 2 lines
Cheers,
Harry / Hyeonggon
#7 lore raw
In reply to Harry Yoo
Quoted 12 lines · Harry Yoo

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Quoted 8 lines

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

I'll put this on my test fleet this evening. Thank you for the quick fix! :)

--D

Quoted 46 lines
---
 mm/slub.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slub.c +6 -2
index f1a5373eee7b..a787687a0d59 100644
@@ -6332,8 +6332,6 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 
 		if (unlikely(!slab_free_hook(s, p[i], init, false))) {
 			p[i] = p[--size];
-			if (!size)
-				goto flush_remote;
 			continue;
 		}
 
@@ -6348,6 +6346,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		i++;
 	}
 
+	if (!size)
+		goto flush_remote;
+
 next_batch:
 	if (!local_trylock(&s->cpu_sheaves->lock))
 		goto fallback;
@@ -6402,6 +6403,9 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
 		goto next_batch;
 	}
 
+	if (remote_nr)
+		goto flush_remote;
+
 	return;
 
 no_empty:
Signature · 1 line
2.43.0
author
#8 lore raw
Quoted 16 lines · Darrick J. Wong
Quoted 15 lines · Harry Yoo

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

Quoted 8 lines
Quoted 5 lines

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

I'll put this on my test fleet this evening. Thank you for the quick fix! :)

Thanks for testing, Darrick!

Signature · 2 lines
Cheers,
Harry / Hyeonggon
Tested-by
#9 lore raw
Quoted 23 lines · Harry Yoo
Quoted 22 lines · Darrick J. Wong
Quoted 20 lines · Harry Yoo

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was allocated for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to free an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

Quoted 4 lines
Quoted 2 lines

I'll put this on my test fleet this evening. Thank you for the quick fix! :)

Thanks for testing, Darrick!

Nothing OOMed overnight, so I think this patch is ok.

--D

Quoted 3 lines
Signature · 2 lines
Cheers,
Harry / Hyeonggon
#10 lore raw
In reply to Harry Yoo

Hi,
OK it seems that this in deed fixed the issue, and i do not see leak now. Thanks for fixing it :)
Btw if you guys need VPS with GPU resources, i can give you free ride on SimplePod.ai for helping fixing that issue :)

--

tel. 790 202 300

*Tytus Rogalewski*

Dolina Krzemowa 6A

83-010 Jagatowo

NIP: 9570976234

czw., 13 lis 2025 o 01:43 Harry Yoo <[email protected]> napisał(a):

Quoted 34 lines · Darrick J. Wong
Quoted 11 lines · Harry Yoo
Quoted 10 lines

The commit 989b09b73978 ("slab: skip percpu sheaves for remote object freeing") introduced the remote_objects array in free_to_pcs_bulk() to skip sheaves when objects from a remote node are freed.

However, the array is flushed only when:
1) the array becomes full (++remote_nr >= PCS_BATCH_MAX), or
2) slab_free_hook() returns false and size becomes zero.

When neither of the conditions is met, objects in the array are leaked. This resulted in a memory leak [1], where 82 GiB of memory was

allocated

Quoted 8 lines
Quoted 8 lines

for the maple_node cache.

Flush the array after successfully freeing objects to sheaves in the do_free: path.

In the meantime, move the snippet if (!size) goto flush_remote; outside the while loop for readability. Let's say all objects in the array are from a remote node: then we acquire s->cpu_sheaves->lock and try to

free

Quoted 5 lines
Quoted 2 lines

an object even when size is zero. This doesn't appear to be harmful, but isn't really readable.

I'll put this on my test fleet this evening. Thank you for the quick fix! :)

Thanks for testing, Darrick!

--
Cheers,
Harry / Hyeonggon