Skip to contentSkip to conversation

slab: document SLAB_DESTROY_BY_RCU

PATCH Applied Peter Zijlstra 5 participants 9 messages Nov 13, 2008 Slab allocator

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slab: document SLAB_DESTROY_BY_RCU

Subject: slab: document SLAB_DESTROY_BY_RCU
From: Peter Zijlstra <[email protected]>
Date: Wed, 02 Apr 2008 14:13:42 +0200

Explain this SLAB_DESTROY_BY_RCU thing...

---
 include/linux/slab.h |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
include/linux/slab.h +26 -0
Index: linux-2.6/include/linux/slab.h
===================================================================
@@ -23,6 +23,32 @@
 #define SLAB_CACHE_DMA		0x00004000UL	/* Use GFP_DMA memory */
 #define SLAB_STORE_USER		0x00010000UL	/* DEBUG: Store the last owner for bug hunting */
 #define SLAB_PANIC		0x00040000UL	/* Panic if kmem_cache_create() fails */
+/*
+ * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
+ *
+ * This delays freeing the SLAB page by a grace period, it does _NOT_
+ * delay object freeing. This means that if you do kmem_cache_free()
+ * that memory location is free to be reused at any time. Thus it may
+ * be possible to see another object there in the same RCU grace period.
+ *
+ * This feature only ensures the memory location backing the object
+ * stays valid, the trick to using this is relying on an independent
+ * object validation pass. Something like:
+ *
+ *  rcu_read_lock()
+ * again:
+ *  obj = lockless_lookup(key);
+ *  if (obj) {
+ *    if (!try_get_ref(obj)) // might fail for free objects
+ *      goto again;
+ *
+ *    if (obj->key != key) { // not the object we expected
+ *      put_ref(obj);
+ *      goto again;
+ *    }
+ *  }
+ *  rcu_read_unlock();
+ */
 #define SLAB_DESTROY_BY_RCU	0x00080000UL	/* Defer freeing slabs to RCU */
 #define SLAB_MEM_SPREAD		0x00100000UL	/* Spread some memory over cpuset */
 #define SLAB_TRACE		0x00200000UL	/* Trace allocations and frees */
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Peter Zijlstra

Subject: slab: document SLAB_DESTROY_BY_RCU
From: Peter Zijlstra <[email protected]>
Date: Wed, 02 Apr 2008 14:13:42 +0200

Explain this SLAB_DESTROY_BY_RCU thing...

Quoted 48 lines
---
 include/linux/slab.h |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Index: linux-2.6/include/linux/slab.h
===================================================================

include/linux/slab.h +26 -1
@@ -23,6 +23,32 @@
 #define SLAB_CACHE_DMA         0x00004000UL    /* Use GFP_DMA memory */
 #define SLAB_STORE_USER                0x00010000UL    /* DEBUG: Store the last owner for bug hunting */
 #define SLAB_PANIC             0x00040000UL    /* Panic if kmem_cache_create() fails */
+/*
+ * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
+ *
+ * This delays freeing the SLAB page by a grace period, it does _NOT_
+ * delay object freeing. This means that if you do kmem_cache_free()
+ * that memory location is free to be reused at any time. Thus it may
+ * be possible to see another object there in the same RCU grace period.
+ *
+ * This feature only ensures the memory location backing the object
+ * stays valid, the trick to using this is relying on an independent
+ * object validation pass. Something like:
+ *
+ *  rcu_read_lock()
+ * again:
+ *  obj = lockless_lookup(key);
+ *  if (obj) {
+ *    if (!try_get_ref(obj)) // might fail for free objects
+ *      goto again;
+ *
+ *    if (obj->key != key) { // not the object we expected
+ *      put_ref(obj);
+ *      goto again;
+ *    }
+ *  }
+ *  rcu_read_unlock();
+ */
 #define SLAB_DESTROY_BY_RCU    0x00080000UL    /* Defer freeing slabs to RCU */
 #define SLAB_MEM_SPREAD                0x00100000UL    /* Spread some memory over cpuset */
 #define SLAB_TRACE             0x00200000UL    /* Trace allocations and frees */
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
Quoted 11 lines · Pekka Enberg
Quoted 1 line · Pekka Enberg
Quoted 1 line
Quoted 4 lines · Christoph Lameter

(hope Pekka is going to sign off on this and merge it instead of acking)

Sure, I can merge it but I assumed there was some reason it was sent to Andrew and not me. Peter?

I'm just having one of those days,..

Please merge ;-)

Acked-by Jens Axboe Acked-by Paul E. McKenney on v1 1/1
#5 lore raw
In reply to Peter Zijlstra
Quoted 1 line · Peter Zijlstra

Subject: slab: document SLAB_DESTROY_BY_RCU

Yes, that's good, thanks Peter. But I still think it's even better with at least a pointer to the original description in mm/slab.c: I've added one or two lines to the comment below.

From: Peter Zijlstra <[email protected]>

Explain this SLAB_DESTROY_BY_RCU thing...

---
 include/linux/slab.h |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/linux/slab.h +28 -0
Index: linux-2.6/include/linux/slab.h
===================================================================
@@ -23,6 +23,34 @@
 #define SLAB_CACHE_DMA		0x00004000UL	/* Use GFP_DMA memory */
 #define SLAB_STORE_USER		0x00010000UL	/* DEBUG: Store the last owner for bug hunting */
 #define SLAB_PANIC		0x00040000UL	/* Panic if kmem_cache_create() fails */
+/*
+ * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
+ *
+ * This delays freeing the SLAB page by a grace period, it does _NOT_
+ * delay object freeing. This means that if you do kmem_cache_free()
+ * that memory location is free to be reused at any time. Thus it may
+ * be possible to see another object there in the same RCU grace period.
+ *
+ * This feature only ensures the memory location backing the object
+ * stays valid, the trick to using this is relying on an independent
+ * object validation pass. Something like:
+ *
+ *  rcu_read_lock()
+ * again:
+ *  obj = lockless_lookup(key);
+ *  if (obj) {
+ *    if (!try_get_ref(obj)) // might fail for free objects
+ *      goto again;
+ *
+ *    if (obj->key != key) { // not the object we expected
+ *      put_ref(obj);
+ *      goto again;
+ *    }
+ *  }
+ *  rcu_read_unlock();
+ *
+ * See also the comment on struct slab_rcu in mm/slab.c.
+ */
 #define SLAB_DESTROY_BY_RCU	0x00080000UL	/* Defer freeing slabs to RCU */
 #define SLAB_MEM_SPREAD		0x00100000UL	/* Spread some memory over cpuset */
 #define SLAB_TRACE		0x00200000UL	/* Trace allocations and frees */
#6 lore raw
Quoted 6 lines · Hugh Dickins
Quoted 1 line · Peter Zijlstra

Subject: slab: document SLAB_DESTROY_BY_RCU

Yes, that's good, thanks Peter. But I still think it's even better with at least a pointer to the original description in mm/slab.c: I've added one or two lines to the comment below.

Ah, yes, I think to remember we had a similar discussion back in april.

Thanks!

Applied
#7 lore raw
In reply to Hugh Dickins
Quoted 6 lines · Hugh Dickins
Quoted 1 line · Peter Zijlstra

Subject: slab: document SLAB_DESTROY_BY_RCU

Yes, that's good, thanks Peter. But I still think it's even better with at least a pointer to the original description in mm/slab.c: I've added one or two lines to the comment below.

Applied, thanks!

#8 lore raw
In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra

Subject: slab: document SLAB_DESTROY_BY_RCU
From: Peter Zijlstra <[email protected]>
Date: Wed, 02 Apr 2008 14:13:42 +0200

Explain this SLAB_DESTROY_BY_RCU thing...

With Hugh's suggested change,

Quoted 45 lines
---
 include/linux/slab.h |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Index: linux-2.6/include/linux/slab.h
===================================================================

include/linux/slab.h +26 -0
@@ -23,6 +23,32 @@
 #define SLAB_CACHE_DMA		0x00004000UL	/* Use GFP_DMA memory */
 #define SLAB_STORE_USER		0x00010000UL	/* DEBUG: Store the last owner for bug hunting */
 #define SLAB_PANIC		0x00040000UL	/* Panic if kmem_cache_create() fails */
+/*
+ * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
+ *
+ * This delays freeing the SLAB page by a grace period, it does _NOT_
+ * delay object freeing. This means that if you do kmem_cache_free()
+ * that memory location is free to be reused at any time. Thus it may
+ * be possible to see another object there in the same RCU grace period.
+ *
+ * This feature only ensures the memory location backing the object
+ * stays valid, the trick to using this is relying on an independent
+ * object validation pass. Something like:
+ *
+ *  rcu_read_lock()
+ * again:
+ *  obj = lockless_lookup(key);
+ *  if (obj) {
+ *    if (!try_get_ref(obj)) // might fail for free objects
+ *      goto again;
+ *
+ *    if (obj->key != key) { // not the object we expected
+ *      put_ref(obj);
+ *      goto again;
+ *    }
+ *  }
+ *  rcu_read_unlock();
+ */
 #define SLAB_DESTROY_BY_RCU	0x00080000UL	/* Defer freeing slabs to RCU */
 #define SLAB_MEM_SPREAD		0x00100000UL	/* Spread some memory over cpuset */
 #define SLAB_TRACE		0x00200000UL	/* Trace allocations and frees */