Skip to content

Commit e9f8a79

Browse files
committed
slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking
It is not obvious to the casual user why it is absolutely necessary to acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring a lock in that structure. Therefore, add a comment explaining this point. [ paulmck: Apply Vlastimil Babka feedback. ] 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: Roman Gushchin <roman.gushchin@linux.dev> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: <linux-mm@kvack.org> Acked-by: Vlastimil Babka <vbabka@suse.cz>
1 parent aba9645 commit e9f8a79

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

include/linux/slab.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@
7676
* rcu_read_lock before reading the address, then rcu_read_unlock after
7777
* taking the spinlock within the structure expected at that address.
7878
*
79+
* Note that it is not possible to acquire a lock within a structure
80+
* allocated with SLAB_TYPESAFE_BY_RCU without first acquiring a reference
81+
* as described above. The reason is that SLAB_TYPESAFE_BY_RCU pages
82+
* are not zeroed before being given to the slab, which means that any
83+
* locks must be initialized after each and every kmem_struct_alloc().
84+
* Alternatively, make the ctor passed to kmem_cache_create() initialize
85+
* the locks at page-allocation time, as is done in __i915_request_ctor(),
86+
* sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers
87+
* to safely acquire those ctor-initialized locks under rcu_read_lock()
88+
* protection.
89+
*
7990
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
8091
*/
8192
/* Defer freeing slabs to RCU */

0 commit comments

Comments
 (0)