fuse: wake one waiter per freed slot when raising max_background
Subsystems (2)
PATCH 1/1 fuse: wake one waiter per freed slot when raising max_background
fuse_get_req() parks background allocations on fch->blocked_waitq via wait_event_state_exclusive(), so each wakeup releases exactly one waiter. fuse_chan_max_background_set() clears fch->blocked when the new limit exceeds num_background, but the accompanying wake_up() releases a single waiter regardless of how many slots just became available. Raising max_background from 10 to 100 therefore admits one request instead of ninety.
The remaining waiters are not permanently stranded — the "else if (!fch->blocked)" branch in fuse_request_end() wakes one more per completion — but that only helps while requests keep completing. Consider a fixed pool of threads doing readahead or async direct I/O with the quota exhausted: every thread is either in flight or parked, and each completion wakes one waiter while freeing one slot, a net change of zero. num_background oscillates around the old limit and the added quota is never taken up.
Waking one waiter per freed slot also preserves submission order:
once fch->blocked is clear, new callers of fuse_get_req() skip the waitqueue entirely, overtaking waiters that parked before the limit was raised.
Use wake_up_nr() with the number of slots that just became available. Since the wakeup is guarded by !fch->blocked, num_background is strictly below max_background, so the count is at least 1 and never degenerates into wake_up_all().
--- fs/fuse/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/dev.c +2 -1
@@ -397,7 +397,8 @@ void fuse_chan_max_background_set(struct fuse_chan *fch, unsigned int val) fch->max_background = val; fch->blocked = fch->num_background >= fch->max_background;if (!fch->blocked) -wake_up (&fch->blocked_waitq); +wake_up_nr (&fch->blocked_waitq, + fch->max_background - fch->num_background);spin_unlock (&fch->bg_lock); }
Signature · 1 line
2.43.7
Quoted 50 lines · Baokun Li
fuse_get_req()parks background allocations onfch->blocked_waitqviawait_event_state_exclusive(), so each wakeup releases exactly one waiter.fuse_chan_max_background_set()clearsfch->blockedwhen the new limit exceedsnum_background, but the accompanyingwake_up()releases a single waiter regardless of how many slots just became available. Raisingmax_backgroundfrom 10 to 100 therefore admits one request instead of ninety.The remaining waiters are not permanently stranded — the "else if (!fch->blocked)" branch in
fuse_request_end()wakes one more per completion — but that only helps while requests keep completing. Consider a fixed pool of threads doing readahead or async direct I/O with the quota exhausted: every thread is either in flight or parked, and each completion wakes one waiter while freeing one slot, a net change of zero.num_backgroundoscillates around the old limit and the added quota is never taken up.Waking one waiter per freed slot also preserves submission order:
oncefch->blockedis clear, new callers offuse_get_req()skip the waitqueue entirely, overtaking waiters that parked before the limit was raised.Use
wake_up_nr()with the number of slots that just became available. Since the wakeup is guarded by !fch->blocked,num_backgroundis strictly belowmax_background, so the count is at least 1 and never degenerates intowake_up_all().Signed-off-by Baokun Li <[email protected]>--- fs/fuse/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/fuse/dev.c +2
-1@@ -397,7 +397,8 @@ void fuse_chan_max_background_set(struct fuse_chan *fch, unsigned int val) fch->max_background = val; fch->blocked = fch->num_background >= fch->max_background;if (!fch->blocked) -wake_up (&fch->blocked_waitq); +wake_up_nr (&fch->blocked_waitq, + fch->max_background - fch->num_background);spin_unlock (&fch->bg_lock); }Signature · 1 line
2.43.7
LGTM
Quoted 4 lines · Baokun Li
Use
wake_up_nr()with the number of slots that just became available. Since the wakeup is guarded by !fch->blocked,num_backgroundis strictly belowmax_background, so the count is at least 1 and never degenerates intowake_up_all().
Applied, thanks.
Miklos