From 1540b4377ebb3f46eac499e7596c3ec5be75551b Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 23 Dec 2020 14:41:00 -0500 Subject: [PATCH 7/9] btrfs: Fix 500-2000% performance regression w/ 5.10 Josef's tentative fix from https://lore.kernel.org/linux-btrfs/0382080a1836a12c2d625f8a5bf899828eba204b.1608752315.git.josef@toxicpanda.com/ With the conflict fix mentioned in the reply. For https://bugs.archlinux.org/task/69077 --- fs/btrfs/space-info.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 64099565ab8f..8a1ce11b6ed8 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -480,6 +480,28 @@ static inline u64 calc_reclaim_items_nr(struct btrfs_fs_info *fs_info, #define EXTENT_SIZE_PER_ITEM SZ_256K +static void btrfs_writeback_inodes_sb_nr(struct btrfs_fs_info *fs_info, + unsigned long nr_pages, u64 nr_items) +{ + struct super_block *sb = fs_info->sb; + + if (down_read_trylock(&sb->s_umount)) { + writeback_inodes_sb_nr(sb, nr_pages, WB_REASON_FS_FREE_SPACE); + up_read(&sb->s_umount); + } else { + /* + * We needn't worry the filesystem going from r/w to r/o though + * we don't acquire ->s_umount mutex, because the filesystem + * should guarantee the delalloc inodes list be empty after + * the filesystem is readonly(all dirty pages are written to + * the disk). + */ + btrfs_start_delalloc_roots(fs_info, nr_items); + if (!current->journal_info) + btrfs_wait_ordered_roots(fs_info, nr_items, 0, (u64)-1); + } +} + /* * shrink metadata reservation for delalloc */ @@ -532,7 +554,8 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info, loops = 0; while ((delalloc_bytes || dio_bytes) && loops < 3) { - btrfs_start_delalloc_roots(fs_info, items); + unsigned long nr_pages = min(delalloc_bytes, to_reclaim) >> PAGE_SHIFT; + btrfs_writeback_inodes_sb_nr(fs_info, nr_pages, items); loops++; if (wait_ordered && !trans) { -- 2.29.2