]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: balance btree dirty pages and delayed items after a rename
authorFilipe Manana <fdmanana@suse.com>
Tue, 31 May 2022 15:06:32 +0000 (16:06 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Jul 2022 15:44:35 +0000 (17:44 +0200)
A rename operation modifies a subvolume's btree, to remove the old dir
item, add the new dir item, remove an inode ref and add a new inode ref.
It can also create the delayed inode for the inodes involved in the
operation, and it creates two delayed dir index items, one to delete
the old name and another one to add the new name.

However we are neither balancing the btree dirty pages nor the delayed
items after a rename, which can result in accumulation of too many
btree dirty pages and delayed items, specially if a task is doing a
series of rename operations (for example it can happen for package
installations/upgrades through the zypper tool).

So just call btrfs_btree_balance_dirty() after a rename, just like we
do for every other system call that results on modifying a btree and
adding delayed items.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index f96e332bfe963d4de934cc0d69cd60a743a0aac6..419bae723890cb686d0a4b649fde1920f1c843dd 100644 (file)
@@ -9557,15 +9557,21 @@ static int btrfs_rename2(struct user_namespace *mnt_userns, struct inode *old_di
                         struct dentry *old_dentry, struct inode *new_dir,
                         struct dentry *new_dentry, unsigned int flags)
 {
+       int ret;
+
        if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
                return -EINVAL;
 
        if (flags & RENAME_EXCHANGE)
-               return btrfs_rename_exchange(old_dir, old_dentry, new_dir,
-                                         new_dentry);
+               ret = btrfs_rename_exchange(old_dir, old_dentry, new_dir,
+                                           new_dentry);
+       else
+               ret = btrfs_rename(mnt_userns, old_dir, old_dentry, new_dir,
+                                  new_dentry, flags);
 
-       return btrfs_rename(mnt_userns, old_dir, old_dentry, new_dir,
-                           new_dentry, flags);
+       btrfs_btree_balance_dirty(BTRFS_I(new_dir)->root->fs_info);
+
+       return ret;
 }
 
 struct btrfs_delalloc_work {