From: Filipe Manana Date: Mon, 9 Dec 2024 16:43:44 +0000 (+0000) Subject: btrfs: avoid monopolizing a core when activating a swap file X-Git-Tag: v5.10.233~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1c3a19446a440c68e80e9c34c5f308ff58aac88;p=thirdparty%2Fkernel%2Fstable.git btrfs: avoid monopolizing a core when activating a swap file commit 2c8507c63f5498d4ee4af404a8e44ceae4345056 upstream. During swap activation we iterate over the extents of a file and we can have many thousands of them, so we can end up in a busy loop monopolizing a core. Avoid this by doing a voluntary reschedule after processing each extent. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index eba87f2936d2c..b9dfa1d2de254 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7128,6 +7128,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, ret = -EAGAIN; goto out; } + + cond_resched(); } btrfs_release_path(path);