Messages in this thread Patch in this message | | | From | "Paul E. McKenney" <> | Subject | [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking | Date | Wed, 19 Oct 2022 15:46:56 -0700 |
| |
It is not obvious to the casual user why it is absolutely necessary to acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring a lock in that structure. Therefore, add a comment explaining this point.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: <linux-mm@kvack.org> --- include/linux/slab.h | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/include/linux/slab.h b/include/linux/slab.h index 90877fcde70bd..446303e385265 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -76,6 +76,12 @@ * rcu_read_lock before reading the address, then rcu_read_unlock after * taking the spinlock within the structure expected at that address. * + * Note that it is not possible to acquire a lock within a structure + * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference + * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are + * not zeroed before being given to the slab, which means that any locks + * must be initialized after each and every kmem_struct_alloc(). + * * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. */ /* Defer freeing slabs to RCU */ -- 2.31.1.189.g2e36527f23
| |