Skip to content

Commit fd340d0

Browse files
josefbacikkdave
authored andcommitted
btrfs: wakeup cleaner thread when adding delayed iput
The cleaner thread usually takes care of delayed iputs, with the exception of the btrfs_end_transaction_throttle path. Delaying iputs means we are potentially delaying the eviction of an inode and it's respective space. The cleaner thread only gets woken up every 30 seconds, or when we require space. If there are a lot of inodes that need to be deleted we could induce a serious amount of latency while we wait for these inodes to be evicted. So instead wakeup the cleaner if it's not already awake to process any new delayed iputs we add to the list. If we suddenly need space we will less likely be backed up behind a bunch of inodes that are waiting to be deleted, and we could possibly free space before we need to get into the flushing logic which will save us some latency. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3ec9a4c commit fd340d0

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

fs/btrfs/ctree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ enum {
787787
* main phase. The fs_info::balance_ctl is initialized.
788788
*/
789789
BTRFS_FS_BALANCE_RUNNING,
790+
791+
/* Indicate that the cleaner thread is awake and doing something. */
792+
BTRFS_FS_CLEANER_RUNNING,
790793
};
791794

792795
struct btrfs_fs_info {

fs/btrfs/disk-io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,8 @@ static int cleaner_kthread(void *arg)
16821682
while (1) {
16831683
again = 0;
16841684

1685+
set_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags);
1686+
16851687
/* Make the cleaner go to sleep early. */
16861688
if (btrfs_need_cleaner_sleep(fs_info))
16871689
goto sleep;
@@ -1728,6 +1730,7 @@ static int cleaner_kthread(void *arg)
17281730
*/
17291731
btrfs_delete_unused_bgs(fs_info);
17301732
sleep:
1733+
clear_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags);
17311734
if (kthread_should_park())
17321735
kthread_parkme();
17331736
if (kthread_should_stop())

fs/btrfs/inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,8 @@ void btrfs_add_delayed_iput(struct inode *inode)
32513251
ASSERT(list_empty(&binode->delayed_iput));
32523252
list_add_tail(&binode->delayed_iput, &fs_info->delayed_iputs);
32533253
spin_unlock(&fs_info->delayed_iput_lock);
3254+
if (!test_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags))
3255+
wake_up_process(fs_info->cleaner_kthread);
32543256
}
32553257

32563258
void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)