From: Filipe Manana Date: Thu, 6 Feb 2025 16:22:17 +0000 (+0900) Subject: btrfs: avoid monopolizing a core when activating a swap file X-Git-Tag: v6.12.14~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=926a16e39d8672cb57d52586e16cd67094fa6fa3;p=thirdparty%2Fkernel%2Fstable.git btrfs: avoid monopolizing a core when activating a swap file commit 2c8507c63f5498d4ee4af404a8e44ceae4345056 upstream. This commit re-attempts the backport of the change to the linux-6.12.y branch. Commit 9f372e86b9bd ("btrfs: avoid monopolizing a core when activating a swap file") on this branch was reverted. 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: Koichiro Den Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 197ba9be97187..f7e7d864f4144 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10142,6 +10142,8 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, ret = -EINTR; goto out; } + + cond_resched(); } if (bsi.block_len)