Skip to content

Commit d43113f

Browse files
neilbrownchucklever
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 9320f27 commit d43113f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/nfsd/nfs4state.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,11 +1397,16 @@ static void
13971397
recalculate_deny_mode(struct nfs4_file *fp)
13981398
{
13991399
struct nfs4_ol_stateid *stp;
1400+
u32 old_deny;
14001401

14011402
spin_lock(&fp->fi_lock);
1403+
old_deny = fp->fi_share_deny;
14021404
fp->fi_share_deny = 0;
1403-
list_for_each_entry(stp, &fp->fi_stateids, st_perfile)
1405+
list_for_each_entry(stp, &fp->fi_stateids, st_perfile) {
14041406
fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap);
1407+
if (fp->fi_share_deny == old_deny)
1408+
break;
1409+
}
14051410
spin_unlock(&fp->fi_lock);
14061411
}
14071412

0 commit comments

Comments
 (0)