Message ID | 56979ba90a8e850da85d2a246d6c10d8c45e8fa5.1628509211.git.johannes.thumshirn@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] btrfs: zoned: allow disabling of zone auto relcaim | expand |
On Mon, Aug 09, 2021 at 08:41:17PM +0900, Johannes Thumshirn wrote: > Automatically reclaiming dirty zones might not always be desired for all > workloads, especially as there are currently still some rough edges with > the relocation code on zoned filesystems. > > Allow disabling zone auto reclaim on a per filesystem basis. > > Cc: Naohiro Aota <naohiro.aota@wdc.com> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Looks good to me. Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com> > --- > Changes to v1: > - Use READ_ONCE/WRITE_ONCE > --- > fs/btrfs/free-space-cache.c | 7 ++++--- > fs/btrfs/sysfs.c | 10 +++++++--- > 2 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index 8eeb65278ac0..05336630cb9f 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -2538,6 +2538,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, > struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; > u64 offset = bytenr - block_group->start; > u64 to_free, to_unusable; > + int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold); > > spin_lock(&ctl->tree_lock); > if (!used) > @@ -2567,9 +2568,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, > /* All the region is now unusable. Mark it as unused and reclaim */ > if (block_group->zone_unusable == block_group->length) { > btrfs_mark_bg_unused(block_group); > - } else if (block_group->zone_unusable >= > - div_factor_fine(block_group->length, > - fs_info->bg_reclaim_threshold)) { > + } else if (bg_reclaim_threshold && > + block_group->zone_unusable >= > + div_factor_fine(block_group->length, bg_reclaim_threshold)) { > btrfs_mark_bg_to_reclaim(block_group); > } > > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c > index bfe5e27617b0..7ba09991aa23 100644 > --- a/fs/btrfs/sysfs.c > +++ b/fs/btrfs/sysfs.c > @@ -984,7 +984,8 @@ static ssize_t btrfs_bg_reclaim_threshold_show(struct kobject *kobj, > struct btrfs_fs_info *fs_info = to_fs_info(kobj); > ssize_t ret; > > - ret = scnprintf(buf, PAGE_SIZE, "%d\n", fs_info->bg_reclaim_threshold); > + ret = scnprintf(buf, PAGE_SIZE, "%d\n", > + READ_ONCE(fs_info->bg_reclaim_threshold)); > > return ret; > } > @@ -1001,10 +1002,13 @@ static ssize_t btrfs_bg_reclaim_threshold_store(struct kobject *kobj, > if (ret) > return ret; > > - if (thresh <= 50 || thresh > 100) > + if (thresh != 0 && (thresh <= 50 || thresh > 100)) > return -EINVAL; > > - fs_info->bg_reclaim_threshold = thresh; > + WRITE_ONCE(fs_info->bg_reclaim_threshold, thresh); > + > + if (thresh == 0) > + btrfs_info(fs_info, "disabling auto reclaim"); > > return len; > } > -- > 2.32.0 >
On Mon, Aug 09, 2021 at 08:41:17PM +0900, Johannes Thumshirn wrote: > Automatically reclaiming dirty zones might not always be desired for all > workloads, especially as there are currently still some rough edges with > the relocation code on zoned filesystems. > > Allow disabling zone auto reclaim on a per filesystem basis. > > Cc: Naohiro Aota <naohiro.aota@wdc.com> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > --- > Changes to v1: > - Use READ_ONCE/WRITE_ONCE > --- > fs/btrfs/free-space-cache.c | 7 ++++--- > fs/btrfs/sysfs.c | 10 +++++++--- > 2 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index 8eeb65278ac0..05336630cb9f 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -2538,6 +2538,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, > struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; > u64 offset = bytenr - block_group->start; > u64 to_free, to_unusable; > + int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold); > > spin_lock(&ctl->tree_lock); > if (!used) > @@ -2567,9 +2568,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, > /* All the region is now unusable. Mark it as unused and reclaim */ > if (block_group->zone_unusable == block_group->length) { > btrfs_mark_bg_unused(block_group); > - } else if (block_group->zone_unusable >= > - div_factor_fine(block_group->length, > - fs_info->bg_reclaim_threshold)) { > + } else if (bg_reclaim_threshold && > + block_group->zone_unusable >= > + div_factor_fine(block_group->length, bg_reclaim_threshold)) { > btrfs_mark_bg_to_reclaim(block_group); > } > > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c > index bfe5e27617b0..7ba09991aa23 100644 > --- a/fs/btrfs/sysfs.c > +++ b/fs/btrfs/sysfs.c > @@ -984,7 +984,8 @@ static ssize_t btrfs_bg_reclaim_threshold_show(struct kobject *kobj, > struct btrfs_fs_info *fs_info = to_fs_info(kobj); > ssize_t ret; > > - ret = scnprintf(buf, PAGE_SIZE, "%d\n", fs_info->bg_reclaim_threshold); > + ret = scnprintf(buf, PAGE_SIZE, "%d\n", > + READ_ONCE(fs_info->bg_reclaim_threshold)); > > return ret; > } > @@ -1001,10 +1002,13 @@ static ssize_t btrfs_bg_reclaim_threshold_store(struct kobject *kobj, > if (ret) > return ret; > > - if (thresh <= 50 || thresh > 100) > + if (thresh != 0 && (thresh <= 50 || thresh > 100)) > return -EINVAL; > > - fs_info->bg_reclaim_threshold = thresh; > + WRITE_ONCE(fs_info->bg_reclaim_threshold, thresh); > + > + if (thresh == 0) > + btrfs_info(fs_info, "disabling auto reclaim"); There's no message for adjusting/enabling the reclaim, so either there should be both or none. I'm not sure we need the messages though, for sysfs files in general.
On Mon, Aug 09, 2021 at 08:41:17PM +0900, Johannes Thumshirn wrote: > Automatically reclaiming dirty zones might not always be desired for all > workloads, especially as there are currently still some rough edges with > the relocation code on zoned filesystems. > > Allow disabling zone auto reclaim on a per filesystem basis. > > Cc: Naohiro Aota <naohiro.aota@wdc.com> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > --- > Changes to v1: > - Use READ_ONCE/WRITE_ONCE I've removed the message about disabling for now, we may add it later if desired, perhaps consistenly with the rest of sysfs files.
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 8eeb65278ac0..05336630cb9f 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2538,6 +2538,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; u64 offset = bytenr - block_group->start; u64 to_free, to_unusable; + int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold); spin_lock(&ctl->tree_lock); if (!used) @@ -2567,9 +2568,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, /* All the region is now unusable. Mark it as unused and reclaim */ if (block_group->zone_unusable == block_group->length) { btrfs_mark_bg_unused(block_group); - } else if (block_group->zone_unusable >= - div_factor_fine(block_group->length, - fs_info->bg_reclaim_threshold)) { + } else if (bg_reclaim_threshold && + block_group->zone_unusable >= + div_factor_fine(block_group->length, bg_reclaim_threshold)) { btrfs_mark_bg_to_reclaim(block_group); } diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index bfe5e27617b0..7ba09991aa23 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -984,7 +984,8 @@ static ssize_t btrfs_bg_reclaim_threshold_show(struct kobject *kobj, struct btrfs_fs_info *fs_info = to_fs_info(kobj); ssize_t ret; - ret = scnprintf(buf, PAGE_SIZE, "%d\n", fs_info->bg_reclaim_threshold); + ret = scnprintf(buf, PAGE_SIZE, "%d\n", + READ_ONCE(fs_info->bg_reclaim_threshold)); return ret; } @@ -1001,10 +1002,13 @@ static ssize_t btrfs_bg_reclaim_threshold_store(struct kobject *kobj, if (ret) return ret; - if (thresh <= 50 || thresh > 100) + if (thresh != 0 && (thresh <= 50 || thresh > 100)) return -EINVAL; - fs_info->bg_reclaim_threshold = thresh; + WRITE_ONCE(fs_info->bg_reclaim_threshold, thresh); + + if (thresh == 0) + btrfs_info(fs_info, "disabling auto reclaim"); return len; }
Automatically reclaiming dirty zones might not always be desired for all workloads, especially as there are currently still some rough edges with the relocation code on zoned filesystems. Allow disabling zone auto reclaim on a per filesystem basis. Cc: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> --- Changes to v1: - Use READ_ONCE/WRITE_ONCE --- fs/btrfs/free-space-cache.c | 7 ++++--- fs/btrfs/sysfs.c | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-)