Whamcloud - gitweb
LU-4801 ldlm: discard l_lock from struct ldlm_lock. 11/39811/4
authorNeilBrown <neilb@suse.com>
Tue, 27 Aug 2019 16:13:50 +0000 (12:13 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 21 Apr 2021 03:14:50 +0000 (03:14 +0000)
commitbb6edb7b8eeec65f46f8eaeb135e5dde13bf7ad8
treefd5b696ce7ee058d6264832096d0b8f4218e7de6
parentcc21e6dadb91dd135dbbc810f60fba2c6ccc579d
LU-4801 ldlm: discard l_lock from struct ldlm_lock.

This spinlock (l_lock) is only used to stablise the l_resource
pointer while taking a spinlock on the resource.

This is not necessary - it is sufficient to take the resource
spinlock, and then check if l_resource has changed or not.  If it
hasn't then it cannot change until the resource spinlock is dropped.

We must ensure this is safe even if the resource is freed before
lock_res_and_lock() managed to get the lock.  To do this we use
call_rcu() to free the resource.  This means that if we find a
resource after taking the RCU read lock, then it is always safe to
take and then drop the spinlock.  After taking the spinlock, we can
check if it is more generally safe to use.

Discarding l_lock shrinks 'struct ldlm_lock' which helps save memory.

Note that it would be cleaner to use SLAB_TYPESAFE_BY_RCU instead of
call_rcu(), but this is not correctly supported on all platforms that
lustre supports.  To simplify a transition to SLAB_TYPESAFE_BY_RCU
once that is usable, an 'init_once' function is used to initialize the
spinlock as would be needed in that case.

Signed-off-by: Mr NeilBrown <neilb@suse.com>
Change-Id: Ief5af0b3bc9bed0cd32673e4d62ce51c83846418
Reviewed-on: https://review.whamcloud.com/39811
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_dlm.h
lustre/ldlm/l_lock.c
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_resource.c