Skip to contentSkip to conversation

mm, slab: periodically resched in drain_freelist()

PATCH In review David Rientjes 3 participants 3 messages Dec 28, 2022 – Jan 2, 2023 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, slab: periodically resched in drain_freelist()

drain_freelist() can be called with a very large number of slabs to free, such as for kmem_cache_shrink(), or depending on various settings of the slab cache when doing periodic reaping.

If there is a potentially long list of slabs to drain, periodically schedule to ensure we aren't saturating the cpu for too long.

---
 mm/slab.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slab.c +2 -0
@@ -2211,6 +2211,8 @@ static int drain_freelist(struct kmem_cache *cache,
 		raw_spin_unlock_irq(&n->list_lock);
 		slab_destroy(cache, slab);
 		nr_freed++;
+
+		cond_resched();
 	}
 out:
 	return nr_freed;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · David Rientjes

drain_freelist() can be called with a very large number of slabs to free, such as for kmem_cache_shrink(), or depending on various settings of the slab cache when doing periodic reaping.

If there is a potentially long list of slabs to drain, periodically schedule to ensure we aren't saturating the cpu for too long.

---
 mm/slab.c | 2 ++
 1 file changed, 2 insertions(+)

mm/slab.c static int drain_freelist(struct kmem_cache *cache, · line 2218

Quoted 8 lines
mm/slab.c +2 -0
@@ -2211,6 +2211,8 @@ static int drain_freelist(struct kmem_cache *cache,
 		raw_spin_unlock_irq(&n->list_lock);
 		slab_destroy(cache, slab);
 		nr_freed++;
+
+		cond_resched();
 	}
 out:
 	return nr_freed;

Looks good to me,

Signature · 2 lines
Thanks,
Hyeonggon
#2 lore raw
In reply to David Rientjes
Quoted 8 lines · David Rientjes

drain_freelist() can be called with a very large number of slabs to free, such as for kmem_cache_shrink(), or depending on various settings of the slab cache when doing periodic reaping.

If there is a potentially long list of slabs to drain, periodically schedule to ensure we aren't saturating the cpu for too long.

Thanks, added to slab/for-6.2-rc3/fixes

Quoted 16 lines
---
 mm/slab.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slab.c +2 -0
@@ -2211,6 +2211,8 @@ static int drain_freelist(struct kmem_cache *cache,
 		raw_spin_unlock_irq(&n->list_lock);
 		slab_destroy(cache, slab);
 		nr_freed++;
+
+		cond_resched();
 	}
 out:
 	return nr_freed;