Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

slab: document SLAB_DESTROY_BY_RCU

Explain this SLAB_DESTROY_BY_RCU thing...

[hugh@veritas.com: add a pointer to comment in mm/slab.c]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

authored by

Peter Zijlstra and committed by
Pekka Enberg
d7de4c1d 02f56210

+28
+28
include/linux/slab.h
··· 23 23 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */ 24 24 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */ 25 25 #define SLAB_PANIC 0x00040000UL /* Panic if kmem_cache_create() fails */ 26 + /* 27 + * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS! 28 + * 29 + * This delays freeing the SLAB page by a grace period, it does _NOT_ 30 + * delay object freeing. This means that if you do kmem_cache_free() 31 + * that memory location is free to be reused at any time. Thus it may 32 + * be possible to see another object there in the same RCU grace period. 33 + * 34 + * This feature only ensures the memory location backing the object 35 + * stays valid, the trick to using this is relying on an independent 36 + * object validation pass. Something like: 37 + * 38 + * rcu_read_lock() 39 + * again: 40 + * obj = lockless_lookup(key); 41 + * if (obj) { 42 + * if (!try_get_ref(obj)) // might fail for free objects 43 + * goto again; 44 + * 45 + * if (obj->key != key) { // not the object we expected 46 + * put_ref(obj); 47 + * goto again; 48 + * } 49 + * } 50 + * rcu_read_unlock(); 51 + * 52 + * See also the comment on struct slab_rcu in mm/slab.c. 53 + */ 26 54 #define SLAB_DESTROY_BY_RCU 0x00080000UL /* Defer freeing slabs to RCU */ 27 55 #define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */ 28 56 #define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */