From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Nikolay Borisov <nborisov@suse.com>, Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>
Subject: Re: [PATCH v7 1/5] btrfs: Introduce per-profile available space facility
Date: Fri, 21 Feb 2020 13:16:26 +0800 [thread overview]
Message-ID: <9da38175-637b-b758-0c09-518123c796d5@gmx.com> (raw)
In-Reply-To: <329cf703-f3f2-4583-73bf-c90c9e001956@suse.com>
On 2020/2/20 下午8:49, Nikolay Borisov wrote:
> <snip>
>
>>
>> Suggested-by: Josef Bacik <josef@toxicpanda.com>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> fs/btrfs/volumes.c | 216 ++++++++++++++++++++++++++++++++++++++++-----
>> fs/btrfs/volumes.h | 11 +++
>> 2 files changed, 207 insertions(+), 20 deletions(-)
>>
>
> <snip>
>
>> +
>> +/*
>> + * Return 0 if we allocated any virtual(*) chunk, and restore the size to
>> + * @allocated_size
>> + * Return -ENOSPC if we have no more space to allocate virtual chunk
>> + *
>> + * *: virtual chunk is a space holder for per-profile available space
>> + * calculator.
>> + * Such virtual chunks won't take on-disk space, thus called virtual, and
>> + * only affects per-profile available space calulation.
>> + */
>
> Document that the last parameter is an output value which contains the
> size of the allocated virtual chunk.
Isn't that mentioned in the 3rd line of the comment? (Although the
parameter name doesn't match after some updates).
...
> lockdep assert that chunk mutex is held since you access alloc_list.
>
>> + ASSERT(type >= 0 && type < BTRFS_NR_RAID_TYPES);
>> +
>> + /* Not enough devices, quick exit, just update the result */
>> + if (fs_devices->rw_devices < btrfs_raid_array[type].devs_min)
>> + goto out;
>
> You can directly return.
Then you won't update the @result_ret.
And don't forget that, @result_ret is from an uninitialized local array.
Thus we must go out tag.
>
>> +
>> + devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info),
>> + GFP_NOFS);
>> + if (!devices_info) {
>> + ret = -ENOMEM;
>> + goto out;
>
> Same here.
Same as above.
>
>> + }
>> + /* Clear virtual chunk used space for each device */
>> + list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)
>> + device->virtual_allocated = 0;
>> + while (ret == 0) {
>> + ret = alloc_virtual_chunk(fs_info, devices_info, type,
>> + &allocated);
> The 'allocated' variable is used only in this loop so declare it in the
> loop. Ideally we want variables to have the shortest possible lifecycle.
Then your new while() loop idea will still need @allocated declared at
at the beginning of the function.
Thanks,
Qu
>
>> + if (ret == 0)
>> + result += allocated;
>> + }
>
> Why do you need to call this in a loop calling alloc_virtual_chunk once
> simply calculate the available space for the given raid type.
>
>> + list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)
>> + device->virtual_allocated = 0;
>> +out:
>> + kfree(devices_info);
>> + if (ret < 0 && ret != -ENOSPC)
>> + return ret;
>> + *result_ret = result;
>> + return 0;
>> +}
>
> <snip>
>
>> @@ -259,6 +266,10 @@ struct btrfs_fs_devices {
>> struct kobject fsid_kobj;
>> struct kobject *devices_kobj;
>> struct completion kobj_unregister;
>> +
>> + /* Records per-type available space */
>> + spinlock_t per_profile_lock;
>> + u64 per_profile_avail[BTRFS_NR_RAID_TYPES];
>
> Since every avail quantity is independent of any other, can you turn
> this into an array of atomic64 values and get rid of the spinlock? My
> head spins how many locks we have in btrfs.
>
>> };
>>
>> #define BTRFS_BIO_INLINE_CSUM_SIZE 64
>>
next prev parent reply other threads:[~2020-02-21 5:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 5:11 [PATCH v7 0/5] Introduce per-profile available space array to avoid over-confident can_overcommit() Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 1/5] btrfs: Introduce per-profile available space facility Qu Wenruo
2020-02-13 17:12 ` kbuild test robot
2020-02-20 12:49 ` Nikolay Borisov
2020-02-20 12:59 ` Qu Wenruo
2020-02-20 13:19 ` Nikolay Borisov
2020-02-21 5:16 ` Qu Wenruo [this message]
2020-02-11 5:11 ` [PATCH v7 2/5] btrfs: space-info: Use per-profile available space in can_overcommit() Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 3/5] btrfs: statfs: Use pre-calculated per-profile available space Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 4/5] btrfs: Reset device size when btrfs_update_device() failed in btrfs_grow_device() Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 5/5] btrfs: volumes: Revert device used bytes when calc_per_profile_avail() failed Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9da38175-637b-b758-0c09-518123c796d5@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).