Skip to content

Commit 8fc0585

Browse files
isilencekdave
authored andcommitted
btrfs: merge critical sections of discard lock in workfn
btrfs_discard_workfn() drops discard_ctl->lock just to take it again in a moment in btrfs_discard_schedule_work(). Avoid that and also reuse ktime. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1ea2872 commit 8fc0585

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

fs/btrfs/discard.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,28 +328,15 @@ void btrfs_discard_queue_work(struct btrfs_discard_ctl *discard_ctl,
328328
btrfs_discard_schedule_work(discard_ctl, false);
329329
}
330330

331-
/**
332-
* btrfs_discard_schedule_work - responsible for scheduling the discard work
333-
* @discard_ctl: discard control
334-
* @override: override the current timer
335-
*
336-
* Discards are issued by a delayed workqueue item. @override is used to
337-
* update the current delay as the baseline delay interval is reevaluated on
338-
* transaction commit. This is also maxed with any other rate limit.
339-
*/
340-
void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
341-
bool override)
331+
static void __btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
332+
u64 now, bool override)
342333
{
343334
struct btrfs_block_group *block_group;
344-
const u64 now = ktime_get_ns();
345-
346-
spin_lock(&discard_ctl->lock);
347335

348336
if (!btrfs_run_discard_work(discard_ctl))
349-
goto out;
350-
337+
return;
351338
if (!override && delayed_work_pending(&discard_ctl->work))
352-
goto out;
339+
return;
353340

354341
block_group = find_next_block_group(discard_ctl, now);
355342
if (block_group) {
@@ -391,7 +378,24 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
391378
mod_delayed_work(discard_ctl->discard_workers,
392379
&discard_ctl->work, nsecs_to_jiffies(delay));
393380
}
394-
out:
381+
}
382+
383+
/*
384+
* btrfs_discard_schedule_work - responsible for scheduling the discard work
385+
* @discard_ctl: discard control
386+
* @override: override the current timer
387+
*
388+
* Discards are issued by a delayed workqueue item. @override is used to
389+
* update the current delay as the baseline delay interval is reevaluated on
390+
* transaction commit. This is also maxed with any other rate limit.
391+
*/
392+
void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
393+
bool override)
394+
{
395+
const u64 now = ktime_get_ns();
396+
397+
spin_lock(&discard_ctl->lock);
398+
__btrfs_discard_schedule_work(discard_ctl, now, override);
395399
spin_unlock(&discard_ctl->lock);
396400
}
397401

@@ -497,9 +501,8 @@ static void btrfs_discard_workfn(struct work_struct *work)
497501
discard_ctl->prev_discard = trimmed;
498502
discard_ctl->prev_discard_time = now;
499503
discard_ctl->block_group = NULL;
504+
__btrfs_discard_schedule_work(discard_ctl, now, false);
500505
spin_unlock(&discard_ctl->lock);
501-
502-
btrfs_discard_schedule_work(discard_ctl, false);
503506
}
504507

505508
/**

0 commit comments

Comments
 (0)