Re: [PATCH v3 3/4] btrfs: remove free space items when creating free space tree

David Sterba
2020-09-21T17:14:22Z

On Thu, Sep 17, 2020 at 11:13:40AM -0700, Boris Burkov wrote:
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3333,6 +3333,15 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
> close_ctree(fs_info);
> return ret;
> }
> + /*
> + * Creating the free space tree creates inode orphan items and
> + * delayed iputs when it deletes the free space inodes. Later in
> + * open_ctree, we run btrfs_orphan_cleanup which tries to clean
> + * up the orphan items. However, the outstanding references on
> + * the inodes from the delayed iputs causes the cleanup to fail.
> + * To fix it, force going through the delayed iputs here.
> + */
> + btrfs_run_delayed_iputs(fs_info);

This is called from open_ctree, so this is mount context and the free
space tree creation is called before that. That will schedule all free
space inodes for deletion and waits here. This takes time proportional
to the filesystem size.

We've had reports that this takes a lot of time already, so I wonder if
the delayed iputs can be avoided here.