Commit f41320c4 authored by Liu Bo's avatar Liu Bo Committed by Luis Henriques

Btrfs: fix loop writing of async reclaim

commit 25ce459c upstream.

One of my tests shows that when we really don't have space to reclaim via
flush_space and also run out of space, this async reclaim work loops on adding
itself into the workqueue and keeps writing something to disk according to
iostat's results, and these writes mainly comes from commit_transaction which
writes super_block.  This's unacceptable as it can be bad to disks, especially
memeory storages.

This adds a check to avoid the above situation.
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
Cc: Alexander E. Patrakov <patrakov@gmail.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 76b04f0e
...@@ -4349,11 +4349,21 @@ static inline int need_do_async_reclaim(struct btrfs_space_info *space_info, ...@@ -4349,11 +4349,21 @@ static inline int need_do_async_reclaim(struct btrfs_space_info *space_info,
} }
static int btrfs_need_do_async_reclaim(struct btrfs_space_info *space_info, static int btrfs_need_do_async_reclaim(struct btrfs_space_info *space_info,
struct btrfs_fs_info *fs_info) struct btrfs_fs_info *fs_info,
int flush_state)
{ {
u64 used; u64 used;
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
/*
* We run out of space and have not got any free space via flush_space,
* so don't bother doing async reclaim.
*/
if (flush_state > COMMIT_TRANS && space_info->full) {
spin_unlock(&space_info->lock);
return 0;
}
used = space_info->bytes_used + space_info->bytes_reserved + used = space_info->bytes_used + space_info->bytes_reserved +
space_info->bytes_pinned + space_info->bytes_readonly + space_info->bytes_pinned + space_info->bytes_readonly +
space_info->bytes_may_use; space_info->bytes_may_use;
...@@ -4386,11 +4396,12 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) ...@@ -4386,11 +4396,12 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
flush_space(fs_info->fs_root, space_info, to_reclaim, flush_space(fs_info->fs_root, space_info, to_reclaim,
to_reclaim, flush_state); to_reclaim, flush_state);
flush_state++; flush_state++;
if (!btrfs_need_do_async_reclaim(space_info, fs_info)) if (!btrfs_need_do_async_reclaim(space_info, fs_info,
flush_state))
return; return;
} while (flush_state <= COMMIT_TRANS); } while (flush_state <= COMMIT_TRANS);
if (btrfs_need_do_async_reclaim(space_info, fs_info)) if (btrfs_need_do_async_reclaim(space_info, fs_info, flush_state))
queue_work(system_unbound_wq, work); queue_work(system_unbound_wq, work);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment