diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 0b841eab6169..b6abc716aff2 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5712,6 +5712,13 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans, } else { break; } + + /* + * We may process many leaves full of items for our inode, so + * avoid monopolizing a cpu for too long by rescheduling while + * not holding locks on any tree. + */ + cond_resched(); } if (ins_nr) { ret = copy_items(trans, inode, dst_path, path, ins_start_slot,