Skip to content

Commit

Permalink
btrfs: don't hold CPU for too long when defragging a file
Browse files Browse the repository at this point in the history
commit ea0eba6 upstream.

There is a user report about "btrfs filesystem defrag" causing 120s
timeout problem.

For btrfs_defrag_file() it will iterate all file extents if called from
defrag ioctl, thus it can take a long time.

There is no reason not to release the CPU during such a long operation.

Add cond_resched() after defragged one cluster.

CC: stable@vger.kernel.org # 5.16
Link: https://lore.kernel.org/linux-btrfs/10e51417-2203-f0a4-2021-86c8511cc367@gmx.com
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
adam900710 authored and gregkh committed Feb 23, 2022
1 parent 3b4ff4e commit 4c784cf
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions fs/btrfs/ioctl.c
Expand Up @@ -1603,6 +1603,7 @@ int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
ret = 0;
break;
}
cond_resched();
}

if (ra_allocated)
Expand Down

0 comments on commit 4c784cf

Please sign in to comment.