]> www.infradead.org Git - users/hch/misc.git/commit
sunrpc: fix race in cache cleanup causing stale nextcheck time
authorLong Li <leo.lilong@huawei.com>
Sat, 1 Mar 2025 06:48:36 +0000 (14:48 +0800)
committerChuck Lever <chuck.lever@oracle.com>
Sun, 11 May 2025 23:48:22 +0000 (19:48 -0400)
commit2298abcbe11e9b553d03c0f1d084da786f7eff88
tree846c70211a1e6b189384535ae058cc8c660968c6
parent5ca00634c8bbb2979c73465588f486b9632f5ed5
sunrpc: fix race in cache cleanup causing stale nextcheck time

When cache cleanup runs concurrently with cache entry removal, a race
condition can occur that leads to incorrect nextcheck times. This can
delay cache cleanup for the cache_detail by up to 1800 seconds:

1. cache_clean() sets nextcheck to current time plus 1800 seconds
2. While scanning a non-empty bucket, concurrent cache entry removal can
   empty that bucket
3. cache_clean() finds no cache entries in the now-empty bucket to update
   the nextcheck time
4. This maybe delays the next scan of the cache_detail by up to 1800
   seconds even when it should be scanned earlier based on remaining
   entries

Fix this by moving the hash_lock acquisition earlier in cache_clean().
This ensures bucket emptiness checks and nextcheck updates happen
atomically, preventing the race between cleanup and entry removal.

Signed-off-by: Long Li <leo.lilong@huawei.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
net/sunrpc/cache.c