On 13.03.20 г. 23:23 ч., Josef Bacik wrote:
> For very large file systems we cannot rely on the space reservation
> system to provide enough pressure to flush delayed refs in a timely
> manner. We have the infrastructure in place to keep track of how much
> theoretical time it'll take to run our outstanding delayed refs, but
> unfortunately I ripped all of that out when I added the delayed refs
> rsv. This code originally was added to address the problem of too many
> delayed refs building up and thus causing transaction commits to take
> several minutes to finish.
>
> Fix this by adding back the ability to flush delayed refs based on the
> time budget for them. We want to limit to around 1 seconds worth of
> delayed refs to be pending at any given time. In order to keep up with
> demand we will start the async flusher once we are at the 500ms mark,
> and the async flusher will attempt to keep us in this ballpark.
>
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> ---
> fs/btrfs/ctree.h | 4 ++++
> fs/btrfs/disk-io.c | 3 +++
> fs/btrfs/extent-tree.c | 44 ++++++++++++++++++++++++++++++++++++++++++
> fs/btrfs/transaction.c | 8 ++++++++
> 4 files changed, 59 insertions(+)
>
<snip>
>
> +static void btrfs_async_run_delayed_refs(struct work_struct *work)
> +{
> + struct btrfs_fs_info *fs_info;
> + struct btrfs_trans_handle *trans;
> +
> + fs_info = container_of(work, struct btrfs_fs_info,
> + async_delayed_ref_work);
> +
> + while (!btrfs_fs_closing(fs_info)) {
> + unsigned long count;
> + int ret;
> +
> + trans = btrfs_attach_transaction(fs_info->extent_root);
> + if (IS_ERR(trans))
> + break;
> +
> + smp_rmb();
> + if (trans->transaction->delayed_refs.flushing) {
> + btrfs_end_transaction(trans);
> + break;
> + }
> +
> + /* No longer over our threshold, lets bail. */
> + if (!btrfs_should_throttle_delayed_refs(trans, true)) {
> + btrfs_end_transaction(trans);
> + break;
> + }
> +
> + count = atomic_read(&trans->transaction->delayed_refs.num_entries);
Don't you want to actually read num_heads_ready rather than num_entries,
i.e isn't this introducing the same issues as the one fixed by:
[PATCH 2/5] btrfs: delayed refs pre-flushing should only run the heads
we have
> + count >>= 2;
> +
> + ret = btrfs_run_delayed_refs(trans, count);
> + btrfs_end_transaction(trans);
> + if (ret < 0)
> + break;
> + }
> +}
<snip>