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

Josef Bacik
2020-09-21T19:01:10Z

On 9/21/20 1:13 PM, David Sterba wrote:
> 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.
>

Chris and I told him to do it this way. If you have a giant FS the time is
mostly going to be spent doing the free space tree, the iputs won't add much
more time to that. We have to do this so the orphan cleanup that follows
doesn't screw up because we haven't put our inodes yet. This is one time pain
and avoids us having to figure out what to do about orphans we generate while
mounting the file system. Thanks,

Josef