]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
nfsd: optimise recalculate_deny_mode() for a common case
authorNeilBrown <neilb@suse.de>
Mon, 8 Apr 2024 01:29:52 +0000 (11:29 +1000)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 6 May 2024 13:07:19 +0000 (09:07 -0400)
commitd43113fbbf79c00fe3ecd637f8cadebc4df9a63c
treeea6bcb2b3076e46a323f211bdd03730b1c5e4866
parent9320f27fda5498c80f9e0c7d8c80d50e8297d89e
nfsd: optimise recalculate_deny_mode() for a common case

recalculate_deny_mode() takes time that is linear in the number of
stateids active on the file.

When called from
  release_openowner -> free_ol_stateid_reaplist ->nfs4_free_ol_stateid
  -> release_all_access

the number of times it is called is linear in the number of stateids.
The net result is that time taken by release_openowner is quadratic in
the number of stateids.

When the nfsd server is shut down while there are many active stateids
this can result in a soft lockup. ("CPU stuck for 302s" seen in one case).

In many cases all the states have the same deny modes and there is no
need to examine the entire list in recalculate_deny_mode().  In
particular, recalculate_deny_mode() will only reduce the deny mode,
never increase it.  So if some prefix of the list causes the original
deny mode to be required, there is no need to examine the remainder of
the list.

So we can improve recalculate_deny_mode() to usually run in constant
time, so release_openowner will typically be only linear in the number
of states.

Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4state.c