From: Josef Bacik <josef@toxicpanda.com>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, Pankaj Raghav <p.raghav@samsung.com>
Subject: Re: [PATCH 1/5] btrfs: make the bg_reclaim_threshold per-space info
Date: Tue, 22 Mar 2022 13:32:45 -0400 [thread overview]
Message-ID: <YjoIPZtKly5+jBfV@localhost.localdomain> (raw)
In-Reply-To: <63d4d206dd2e652aa968ab0fa30dd9aab98a666b.1647878642.git.johannes.thumshirn@wdc.com>
On Mon, Mar 21, 2022 at 09:14:10AM -0700, Johannes Thumshirn wrote:
> From: Josef Bacik <josef@toxicpanda.com>
>
> For !zoned file systems it's useful to have the auto reclaim feature,
> however there are different use cases for !zoned, for example we may not
> want to reclaim metadata chunks ever, only data chunks. Move this sysfs
> flag to per-space_info. This won't affect current users because this
> tunable only ever did anything for zoned, and that is currently hidden
> behind BTRFS_CONFIG_DEBUG.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> [ jth restore global bg_reclaim_threshold ]
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> fs/btrfs/free-space-cache.c | 7 +++++--
> fs/btrfs/space-info.c | 9 +++++++++
> fs/btrfs/space-info.h | 6 ++++++
> fs/btrfs/sysfs.c | 37 +++++++++++++++++++++++++++++++++++++
> fs/btrfs/zoned.h | 6 +-----
> 5 files changed, 58 insertions(+), 7 deletions(-)
>
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 01a408db5683..ef84bc5030cd 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -2630,16 +2630,19 @@ int __btrfs_add_free_space(struct btrfs_block_group *block_group,
> static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
> u64 bytenr, u64 size, bool used)
> {
> - struct btrfs_fs_info *fs_info = block_group->fs_info;
> + struct btrfs_space_info *sinfo = block_group->space_info;
> struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
> u64 offset = bytenr - block_group->start;
> u64 to_free, to_unusable;
> - const int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold);
> + int bg_reclaim_threshold = 0;
> bool initial = (size == block_group->length);
> u64 reclaimable_unusable;
>
> WARN_ON(!initial && offset + size > block_group->zone_capacity);
>
> + if (!initial)
> + bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
> +
> spin_lock(&ctl->tree_lock);
> if (!used)
> to_free = size;
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index b87931a458eb..60d0a58c4644 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -181,6 +181,12 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
> found->full = 0;
> }
>
> +/*
> + * Block groups with more than this value (percents) of unusable space will be
> + * scheduled for background reclaim.
> + */
> +#define BTRFS_DEFAULT_ZONED_RECLAIM_THRESH 75
> +
> static int create_space_info(struct btrfs_fs_info *info, u64 flags)
> {
>
> @@ -203,6 +209,9 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
> INIT_LIST_HEAD(&space_info->priority_tickets);
> space_info->clamp = 1;
>
> + if (btrfs_is_zoned(info))
> + space_info->bg_reclaim_threshold = BTRFS_DEFAULT_ZONED_RECLAIM_THRESH;
> +
> ret = btrfs_sysfs_add_space_info_type(info, space_info);
> if (ret)
> return ret;
> diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
> index d841fed73492..0c45f539e3cf 100644
> --- a/fs/btrfs/space-info.h
> +++ b/fs/btrfs/space-info.h
> @@ -24,6 +24,12 @@ struct btrfs_space_info {
> the space info if we had an ENOSPC in the
> allocator. */
>
> + /*
> + * Once a block group drops below this threshold we'll schedule it for
> + * reclaim.
> + */
> + int bg_reclaim_threshold;
> +
> int clamp; /* Used to scale our threshold for preemptive
> flushing. The value is >> clamp, so turns
> out to be a 2^clamp divisor. */
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 17389a42a3ab..90da1ea0cae0 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -722,6 +722,42 @@ SPACE_INFO_ATTR(bytes_zone_unusable);
> SPACE_INFO_ATTR(disk_used);
> SPACE_INFO_ATTR(disk_total);
>
> +static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj,
> + struct kobj_attribute *a,
> + char *buf)
> +{
> + struct btrfs_space_info *space_info = to_space_info(kobj);
> + ssize_t ret;
> +
> + ret = sysfs_emit(buf, "%d\n", READ_ONCE(space_info->bg_reclaim_threshold));
> +
> + return ret;
> +}
> +
> +static ssize_t btrfs_sinfo_bg_reclaim_threshold_store(struct kobject *kobj,
> + struct kobj_attribute *a,
> + const char *buf, size_t len)
> +{
> + struct btrfs_space_info *space_info = to_space_info(kobj);
> + int thresh;
> + int ret;
> +
> + ret = kstrtoint(buf, 10, &thresh);
> + if (ret)
> + return ret;
> +
> + if (thresh != 0 && (thresh <= 50 || thresh > 100))
> + return -EINVAL;
> +
> + WRITE_ONCE(space_info->bg_reclaim_threshold, thresh);
> +
> + return len;
> +}
> +
> +BTRFS_ATTR_RW(space_info, bg_reclaim_threshold,
> + btrfs_sinfo_bg_reclaim_threshold_show,
> + btrfs_sinfo_bg_reclaim_threshold_store);
> +
> /*
> * Allocation information about block group types.
> *
> @@ -738,6 +774,7 @@ static struct attribute *space_info_attrs[] = {
> BTRFS_ATTR_PTR(space_info, bytes_zone_unusable),
> BTRFS_ATTR_PTR(space_info, disk_used),
> BTRFS_ATTR_PTR(space_info, disk_total),
> + BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold),
> NULL,
> };
> ATTRIBUTE_GROUPS(space_info);
> diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
> index cbf016a7bb5d..c489c08d7fd5 100644
> --- a/fs/btrfs/zoned.h
> +++ b/fs/btrfs/zoned.h
> @@ -10,11 +10,7 @@
> #include "block-group.h"
> #include "btrfs_inode.h"
>
> -/*
> - * Block groups with more than this value (percents) of unusable space will be
> - * scheduled for background reclaim.
> - */
> -#define BTRFS_DEFAULT_RECLAIM_THRESH 75
> +#define BTRFS_DEFAULT_RECLAIM_THRESH 75
>
Looks like you added this back by accident?
Josef
next prev parent reply other threads:[~2022-03-22 17:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 16:14 [PATCH 0/5] btrfs: rework background block group relocation Johannes Thumshirn
2022-03-21 16:14 ` [PATCH 1/5] btrfs: make the bg_reclaim_threshold per-space info Johannes Thumshirn
2022-03-22 17:32 ` Josef Bacik [this message]
2022-03-22 17:34 ` Johannes Thumshirn
2022-03-21 16:14 ` [PATCH 2/5] btrfs: allow block group background reclaim for !zoned fs'es Johannes Thumshirn
2022-03-22 17:38 ` Josef Bacik
2022-03-22 17:40 ` Johannes Thumshirn
2022-03-21 16:14 ` [PATCH 3/5] btrfs: change the bg_reclaim_threshold valid region from 0 to 100 Johannes Thumshirn
2022-03-21 16:14 ` [PATCH 4/5] btrfs: make calc_available_free_space available outside of space-info Johannes Thumshirn
2022-03-22 17:34 ` Josef Bacik
2022-03-21 16:14 ` [PATCH 5/5] btrfs: zoned: make auto-reclaim less aggressive Johannes Thumshirn
2022-03-23 9:08 ` Pankaj Raghav
2022-03-23 9:11 ` Johannes Thumshirn
2022-03-23 9:14 ` Pankaj Raghav
2022-03-23 10:39 ` Johannes Thumshirn
2022-03-23 11:24 ` Pankaj Raghav
2022-03-23 11:52 ` Johannes Thumshirn
2022-03-23 19:37 ` Pankaj Raghav
2022-03-24 0:06 ` Damien Le Moal
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=YjoIPZtKly5+jBfV@localhost.localdomain \
--to=josef@toxicpanda.com \
--cc=dsterba@suse.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=p.raghav@samsung.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