Skip to contentSkip to conversation

slub: Introduce 'alternate' per cpu partial lists

RFC PATCH In review Laura Abbott 3 participants 5 messages Jun 8, 2017 – Jul 12, 2017

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

RFC PATCH 1/1 slub: Introduce 'alternate' per cpu partial lists

SLUB debugging features (poisoning, red zoning etc.) skip the fast path completely. This ensures there is a single place to do all checks and take any locks that may be necessary for debugging. The overhead of some of the debugging features (e.g. poisoning) ends up being comparatively small vs the overhead of not using the fast path.

We don't want to impose any kind of overhead on the fast path so introduce the notion of an alternate fast path. This is essentially the same idea as the existing fast path (store partially used pages on the per-cpu list) but it happens after the real fast path. Debugging that doesn't require locks (poisoning/red zoning) can happen on this path to avoid the penalty of always needing to go for the slow path.

---
This is a follow up to my previous proposal to speed up slub_debug=P
https://marc.info/?l=linux-mm&m=145920558822958&w=2 . The current approach is hopelessly slow and can't really be used outside of limited debugging. The goal is to make slub_debug=P more usable for general use.

Joonsoo Kim pointed out that my previous attempt still wouldn't scale as it still involved taking the list_lock for every allocation. He suggested adding per-cpu support, as did Christoph Lameter in a separate thread. This proposal adds a separate per-cpu list for use when poisoning is enabled. For this version, I'm mostly looking for general feedback about how reasonable this approach is before trying to clean it up more.

- Some of this code is redundant and can probably be combined.
- The fast path is very sensitive and it was suggested I leave it alone. The approach I took means the fastpath cmpxchg always fails before trying the alternate cmpxchg. From some of my profiling, the cmpxchg seemed to be fairly expensive.
- The flow for ___slab_free is ugly and should really be reworked.
- The poisoning is now scattered around in a few places. Ideally there would be a single path for this to happen. If the fast path free fails we end up doing an extra initialization of the object.
- I don't care about the name, feel free to suggest something better.

For some performance numbers, I used hackbench -g 20 -l 1000. There does not seem to be an impact with slub_debug=- with this series. For slub_debug=P, I get ~2 second drop with a UP system and almost a 10 second drop with a 4 core system as run with QEMU.

---
 include/linux/slub_def.h |   8 ++
 mm/slub.c                | 263 ++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 244 insertions(+), 27 deletions(-)
include/linux/slub_def.h +8 -0
index 07ef550..d582101 100644
@@ -10,8 +10,10 @@
 
 enum stat_item {
 	ALLOC_FASTPATH,		/* Allocation from cpu slab */
+	ALLOC_ALT_FASTPATH,	/* Allocation from alternate cpu slab */
 	ALLOC_SLOWPATH,		/* Allocation by getting a new cpu slab */
 	FREE_FASTPATH,		/* Free to cpu slab */
+	FREE_ALT_FASTPATH,	/* Free to alternate cpu slab */
 	FREE_SLOWPATH,		/* Freeing not to cpu slab */
 	FREE_FROZEN,		/* Freeing to frozen slab */
 	FREE_ADD_PARTIAL,	/* Freeing moves slab to partial list */
@@ -42,6 +44,12 @@ struct kmem_cache_cpu {
 	unsigned long tid;	/* Globally unique transaction id */
 	struct page *page;	/* The slab from which we are allocating */
 	struct page *partial;	/* Partially allocated frozen slabs */
+	/*
+	 * The following fields have identical uses to those above */
+	void **alt_freelist;
+	unsigned long alt_tid;
+	struct page *alt_partial;
+	struct page *alt_page;
 #ifdef CONFIG_SLUB_STATS
 	unsigned stat[NR_SLUB_STAT_ITEMS];
 #endif
mm/slub.c +236 -27

420 lines not on this page · raw message

Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 27 lines · Laura Abbott

SLUB debugging features (poisoning, red zoning etc.) skip the fast path completely. This ensures there is a single place to do all checks and take any locks that may be necessary for debugging. The overhead of some of the debugging features (e.g. poisoning) ends up being comparatively small vs the overhead of not using the fast path.

We don't want to impose any kind of overhead on the fast path so introduce the notion of an alternate fast path. This is essentially the same idea as the existing fast path (store partially used pages on the per-cpu list) but it happens after the real fast path. Debugging that doesn't require locks (poisoning/red zoning) can happen on this path to avoid the penalty of always needing to go for the slow path.

---
This is a follow up to my previous proposal to speed up slub_debug=P
https://marc.info/?l=linux-mm&m=145920558822958&w=2 . The current approach is hopelessly slow and can't really be used outside of limited debugging. The goal is to make slub_debug=P more usable for general use.

Joonsoo Kim pointed out that my previous attempt still wouldn't scale as it still involved taking the list_lock for every allocation. He suggested adding per-cpu support, as did Christoph Lameter in a separate thread. This proposal adds a separate per-cpu list for use when poisoning is enabled. For this version, I'm mostly looking for general feedback about how reasonable this approach is before trying to clean it up more.

Quoted 5 lines

- Some of this code is redundant and can probably be combined.
- The fast path is very sensitive and it was suggested I leave it alone. The approach I took means the fastpath cmpxchg always fails before trying the alternate cmpxchg. From some of my profiling, the cmpxchg seemed to be fairly expensive.

It looks better to modify the fastpath for non-debuging poisoning. If we use the jump label, it doesn't cause any overhead to the fastpath for the user who doesn't use this feature. It really makes thing simpler. Only a few more lines will be needed in the fastpath.

Christoph, any opinion?

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 34 lines · Joonsoo Kim
Quoted 27 lines · Laura Abbott

SLUB debugging features (poisoning, red zoning etc.) skip the fast path completely. This ensures there is a single place to do all checks and take any locks that may be necessary for debugging. The overhead of some of the debugging features (e.g. poisoning) ends up being comparatively small vs the overhead of not using the fast path.

We don't want to impose any kind of overhead on the fast path so introduce the notion of an alternate fast path. This is essentially the same idea as the existing fast path (store partially used pages on the per-cpu list) but it happens after the real fast path. Debugging that doesn't require locks (poisoning/red zoning) can happen on this path to avoid the penalty of always needing to go for the slow path.

---
This is a follow up to my previous proposal to speed up slub_debug=P
https://marc.info/?l=linux-mm&m=145920558822958&w=2 . The current approach is hopelessly slow and can't really be used outside of limited debugging. The goal is to make slub_debug=P more usable for general use.

Joonsoo Kim pointed out that my previous attempt still wouldn't scale as it still involved taking the list_lock for every allocation. He suggested adding per-cpu support, as did Christoph Lameter in a separate thread. This proposal adds a separate per-cpu list for use when poisoning is enabled. For this version, I'm mostly looking for general feedback about how reasonable this approach is before trying to clean it up more.

Quoted 5 lines

- Some of this code is redundant and can probably be combined.
- The fast path is very sensitive and it was suggested I leave it alone. The approach I took means the fastpath cmpxchg always fails before trying the alternate cmpxchg. From some of my profiling, the cmpxchg seemed to be fairly expensive.

Quoted 5 lines

It looks better to modify the fastpath for non-debuging poisoning. If we use the jump label, it doesn't cause any overhead to the fastpath for the user who doesn't use this feature. It really makes thing simpler. Only a few more lines will be needed in the fastpath.

When I initially tried something like that with the first version I still saw an increase in the fast path even with slub_debug=-. I might not have been testing with jump labels though and I didn't spend that much time trying to narrow down the issue.

Thanks,
Laura

Quoted 4 lines

Christoph, any opinion?

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Joonsoo Kim
Quoted 6 lines · Joonsoo Kim
Quoted 5 lines

- Some of this code is redundant and can probably be combined.
- The fast path is very sensitive and it was suggested I leave it alone. The approach I took means the fastpath cmpxchg always fails before trying the alternate cmpxchg. From some of my profiling, the cmpxchg seemed to be fairly expensive.

Quoted 6 lines

It looks better to modify the fastpath for non-debuging poisoning. If we use the jump label, it doesn't cause any overhead to the fastpath for the user who doesn't use this feature. It really makes thing simpler. Only a few more lines will be needed in the fastpath.

Christoph, any opinion?

Just looked through it. Sorry was on vacation in Europe for awhile.

The duplication in kmem_cache_cpu is not good performance wise. Maybe just keep the single per cpu partial list and depending on a kmem_cache flag change the locking semantics in order to allow for faster debugging?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Laura Abbott
Quoted 5 lines · Laura Abbott

- Some of this code is redundant and can probably be combined.
- The fast path is very sensitive and it was suggested I leave it alone. The approach I took means the fastpath cmpxchg always fails before trying the alternate cmpxchg. From some of my profiling, the cmpxchg seemed to be fairly expensive.

I think its better to change the fast path. Just make sure that the hot path is as unencumbered as possible. There are already slow pieces in the hotpath. If you modifications are similar then it would work.

Quoted 7 lines
include/linux/slub_def.h +0 -0
index 07ef550..d582101 100644
@@ -42,6 +44,12 @@ struct kmem_cache_cpu {
 	unsigned long tid;	/* Globally unique transaction id */
 	struct page *page;	/* The slab from which we are allocating */

include/linux/slub_def.h struct kmem_cache_cpu { · line 55

Quoted 10 lines
include/linux/slub_def.h +6 -0
 	struct page *partial;	/* Partially allocated frozen slabs */
+	/*
+	 * The following fields have identical uses to those above */
+	void **alt_freelist;
+	unsigned long alt_tid;
+	struct page *alt_partial;
+	struct page *alt_page;
 #ifdef CONFIG_SLUB_STATS
 	unsigned stat[NR_SLUB_STAT_ITEMS];
 #endif

I would rather avoid duplication here. Use the regular entries and modify the flow depending on a flag.

Quoted 31 lines
mm/slub.c +15 -1
index 7449593..b1fc4c6 100644
@@ -132,10 +132,24 @@ void *fixup_red_left(struct kmem_cache *s, void *p)
 	return p;
 }
 
+#define SLAB_NO_PARTIAL (SLAB_CONSISTENCY_CHECKS | SLAB_STORE_USER | \
+                               SLAB_TRACE)
+
+
+static inline bool kmem_cache_use_alt_partial(struct kmem_cache *s)
+{
+#ifdef CONFIG_SLUB_CPU_PARTIAL
+	return s->flags & (SLAB_RED_ZONE | SLAB_POISON) &&
+		!(s->flags & SLAB_NO_PARTIAL);
+#else
+	return false;
+#endif
+}
+
 static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s)
 {
 #ifdef CONFIG_SLUB_CPU_PARTIAL
-	return !kmem_cache_debug(s);
+	return !(s->flags & SLAB_NO_PARTIAL);
 #else
 	return false;
 #endif

mm/slub.c static inline void *acquire_slab(struct kmem_cache *s, · line 1800

Quoted 1 line
mm/slub.c +0 -0
@@ -1786,6 +1800,7 @@ static inline void *acquire_slab(struct kmem_cache *s,
 }

Hmmm... Looks like the inversion would be better

SLAB_PARTIAL?

...

Lots of duplication. I think that can be avoided by rearranging the fast path depending on a flag.

Maybe make the fast poisoning the default? If you can keep the performance of the fast path for regular use then this may be best. You can then avoid adding the additional flag as well as the additional debug counters.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>