From: Sargun Dhillon <sargun@sargun.me>
To: Omar Sandoval <osandov@osandov.com>
Cc: BTRFS ML <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] btrfs: Convert btrfs_fs_info's free_chunk_space to an atomic64_t
Date: Wed, 7 Jun 2017 11:32:04 -0700 [thread overview]
Message-ID: <CAMp4zn9J7SUETL1aEoSEUXSd+VwdAPGuKaP6j_jC2biA--Q2Fg@mail.gmail.com> (raw)
In-Reply-To: <20170607182303.GE7481@vader.DHCP.thefacebook.com>
On Wed, Jun 7, 2017 at 11:23 AM, Omar Sandoval <osandov@osandov.com> wrote:
> On Wed, Jun 07, 2017 at 06:09:33PM +0000, Sargun Dhillon wrote:
>> This patch is a small performance optimization to get rid of a spin
>> lock, where instead an atomic64_t can be used.
>>
>> Signed-off-by: Sargun Dhillon <sargun@sargun.me>
> [snip]
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index 017b67d..0123974 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -2417,9 +2417,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
>> fs_info->fs_devices->total_devices++;
>> fs_info->fs_devices->total_rw_bytes += device->total_bytes;
>>
>> - spin_lock(&fs_info->free_chunk_lock);
>> - fs_info->free_chunk_space += device->total_bytes;
>> - spin_unlock(&fs_info->free_chunk_lock);
>> + atomic64_add(device->total_bytes, &fs_info->free_chunk_space);
>>
>> if (!blk_queue_nonrot(q))
>> fs_info->fs_devices->rotating = 1;
>> @@ -2874,9 +2872,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
>> mutex_lock(&fs_info->chunk_mutex);
>> btrfs_device_set_bytes_used(device,
>> device->bytes_used - dev_extent_len);
>> - spin_lock(&fs_info->free_chunk_lock);
>> - fs_info->free_chunk_space += dev_extent_len;
>> - spin_unlock(&fs_info->free_chunk_lock);
>> + atomic64_add(dev_extent_len, &fs_info->free_chunk_space);
>> btrfs_clear_space_info_full(fs_info);
>> mutex_unlock(&fs_info->chunk_mutex);
>> }
>> @@ -4409,9 +4405,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
>> btrfs_device_set_total_bytes(device, new_size);
>> if (device->writeable) {
>> device->fs_devices->total_rw_bytes -= diff;
>> - spin_lock(&fs_info->free_chunk_lock);
>> - fs_info->free_chunk_space -= diff;
>> - spin_unlock(&fs_info->free_chunk_lock);
>> + atomic64_sub(diff, &fs_info->free_chunk_space);
>> }
>> mutex_unlock(&fs_info->chunk_mutex);
>>
>> @@ -4535,9 +4529,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
>> btrfs_device_set_total_bytes(device, old_size);
>> if (device->writeable)
>> device->fs_devices->total_rw_bytes += diff;
>> - spin_lock(&fs_info->free_chunk_lock);
>> - fs_info->free_chunk_space += diff;
>> - spin_unlock(&fs_info->free_chunk_lock);
>> + atomic64_add(diff, &fs_info->free_chunk_space);
>> mutex_unlock(&fs_info->chunk_mutex);
>> }
>> return ret;
>> @@ -4882,9 +4874,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>> btrfs_device_set_bytes_used(map->stripes[i].dev, num_bytes);
>> }
>>
>> - spin_lock(&info->free_chunk_lock);
>> - info->free_chunk_space -= (stripe_size * map->num_stripes);
>> - spin_unlock(&info->free_chunk_lock);
>> + atomic64_sub((stripe_size * map->num_stripes), &info->free_chunk_space);
>
> Can you please get rid of the extra parentheses around the
> multiplication here? Also curious if you were able to measure any sort
> of performance difference. Besides that,
Sure.
According to lock stats, this spinlock was accounting for a little bit
more than 1% of time in transactions on our workload. The latency
benefit in synthetic testing was not significant, but the fewer
spurious locks we're measuring, means that perf locks, and bpf
profiling is at a lower cost.
>
> Reviewed-by: Omar Sandoval <osandov@fb.com>
>
>>
>> free_extent_map(em);
>> check_raid56_incompat_flag(info, type);
>> @@ -6684,10 +6674,8 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
>> device->in_fs_metadata = 1;
>> if (device->writeable && !device->is_tgtdev_for_dev_replace) {
>> device->fs_devices->total_rw_bytes += device->total_bytes;
>> - spin_lock(&fs_info->free_chunk_lock);
>> - fs_info->free_chunk_space += device->total_bytes -
>> - device->bytes_used;
>> - spin_unlock(&fs_info->free_chunk_lock);
>> + atomic64_add(device->total_bytes - device->bytes_used,
>> + &fs_info->free_chunk_space);
>> }
>> ret = 0;
>> return ret;
>> --
>> 2.9.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-06-07 18:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 18:09 [PATCH] btrfs: Convert btrfs_fs_info's free_chunk_space to an atomic64_t Sargun Dhillon
2017-06-07 18:23 ` Omar Sandoval
2017-06-07 18:32 ` Sargun Dhillon [this message]
2017-06-09 6:44 ` Nikolay Borisov
2017-06-12 15:47 ` David Sterba
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=CAMp4zn9J7SUETL1aEoSEUXSd+VwdAPGuKaP6j_jC2biA--Q2Fg@mail.gmail.com \
--to=sargun@sargun.me \
--cc=linux-btrfs@vger.kernel.org \
--cc=osandov@osandov.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).