Skip to contentSkip to conversation

btrfs: zoned: replace active_total_bytes system

RFC PATCH New Naohiro Aota 2 participants 5 messages Mar 3, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: zoned: replace active_total_bytes system

This series is still not well tested. Please don't merge right now.

The space_info->active_total_bytes is misleading. It counts not only active block groups but also previously active but now inactive (full BGs, due to fully written) ones. That results in a bug not counting the full BGs into active_total_bytes.

Instead, we can count a newly allocated block group's region as zone_unusable. Then, once that block group is activated, subtract [0 .. zone_capcity] from the zone_unusable counters. With this, the regualr space_info's accounting code will align naturally for zone activation support.

Naohiro Aota (2):
btrfs: zoned: count fresh BG region as zone unusable
btrfs: zoned: drop space_info->active_total_bytes

 fs/btrfs/block-group.c      |  6 ------
 fs/btrfs/free-space-cache.c |  8 +++++++-
 fs/btrfs/space-info.c       | 40 +++++++++----------------------------
 fs/btrfs/space-info.h       |  2 --
 fs/btrfs/zoned.c            | 26 ++++++++++++++++--------
 5 files changed, 34 insertions(+), 48 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

RFC PATCH 1/2 btrfs: zoned: count fresh BG region as zone unusable

The space_info->active_total_bytes is misleading. It counts not only active block groups but also previously active but now inactive (full BGs, due to fully written) ones. That results in a bug not counting the full BGs into active_total_bytes.

Instead, we can count a newly allocated block group's region as zone_unusable. Then, once that block group is activated, subtract [0 .. zone_capcity] from the zone_unusable counters. With this, the regualr space_info's accounting code will align naturally for zone activation support.

---
 fs/btrfs/free-space-cache.c |  8 +++++++-
 fs/btrfs/zoned.c            | 22 ++++++++++++++++++----
 2 files changed, 25 insertions(+), 5 deletions(-)
fs/btrfs/free-space-cache.c +7 -1
index 0d250d052487..4962d7bf1e3a 100644
@@ -2693,8 +2693,13 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
 		bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
 
 	spin_lock(&ctl->tree_lock);
+	/* Count initial region as zone_unusable until it gets activated. */
 	if (!used)
 		to_free = size;
+	else if (initial &&
+		 test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&
+		 block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))
+		to_free = 0;
 	else if (initial)
 		to_free = block_group->zone_capacity;
 	else if (offset >= block_group->alloc_offset)
@@ -2722,7 +2727,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
 	reclaimable_unusable = block_group->zone_unusable -
 			       (block_group->length - block_group->zone_capacity);
 	/* All the region is now unusable. Mark it as unused and reclaim */
-	if (block_group->zone_unusable == block_group->length) {
+	if (block_group->zone_unusable == block_group->length &&
+	    block_group->alloc_offset) {
 		btrfs_mark_bg_unused(block_group);
 	} else if (bg_reclaim_threshold &&
 		   reclaimable_unusable >=
fs/btrfs/zoned.c +18 -4
index 808cfa3091c5..848d53b1f9d5 100644
@@ -1580,9 +1580,19 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache)
 		return;
 
 	WARN_ON(cache->bytes_super != 0);
-	unusable = (cache->alloc_offset - cache->used) +
-		   (cache->length - cache->zone_capacity);
-	free = cache->zone_capacity - cache->alloc_offset;
+
+	/* Check for block groups never get activated */
+	if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &cache->fs_info->flags) &&
+	    cache->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM) &&
+	    !test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags) &&
+	    cache->alloc_offset == 0) {
+		unusable = cache->length;
+		free = 0;
+	} else {
+		unusable = (cache->alloc_offset - cache->used) +
+			   (cache->length - cache->zone_capacity);
+		free = cache->zone_capacity - cache->alloc_offset;
+	}
 
 	/* We only need ->free_space in ALLOC_SEQ block groups */
 	cache->cached = BTRFS_CACHE_FINISHED;
@@ -1901,7 +1911,11 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
 
 	/* Successfully activated all the zones */
 	set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
-	space_info->active_total_bytes += block_group->length;
+	WARN_ON(block_group->alloc_offset != 0);
+	if (block_group->zone_unusable == block_group->length) {
+		block_group->zone_unusable = block_group->length - block_group->zone_capacity;
+		space_info->bytes_zone_unusable -= block_group->zone_capacity;
+	}
 	spin_unlock(&block_group->lock);
 	btrfs_try_granting_tickets(fs_info, space_info);
 	spin_unlock(&space_info->lock);
Signature · 1 line
2.39.2
#2 lore raw

Re: [RFC PATCH 1/2] btrfs: zoned: count fresh BG region as zone unusable

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…

Hi Naohiro,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on kdave/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Naohiro-Aota/btrfs-zoned-count-fresh-BG-region-as-zone-unusable/20230303-163006
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/ae5d21d50546abaedd89d52cefdd1c61c9018ec2.1677831912.git.naohiro.aota%40wdc.com
patch subject: [RFC PATCH 1/2] btrfs: zoned: count fresh BG region as zone unusable
config: hexagon-randconfig-r002-20230303 (https://download.01.org/0day-ci/archive/20230303/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/aef11808b70bc7a53270e26eef4c73ae8a1de4a8
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Naohiro-Aota/btrfs-zoned-count-fresh-BG-region-as-zone-unusable/20230303-163006 git checkout aef11808b70bc7a53270e26eef4c73ae8a1de4a8
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from fs/btrfs/free-space-cache.c:6:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from fs/btrfs/free-space-cache.c:6:
   In file included from include/linux/pagemap.h:11:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from fs/btrfs/free-space-cache.c:6:
   In file included from include/linux/pagemap.h:11:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
                    test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&
                             ^
>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'

6 warnings and 3 errors generated.

vim +/BTRFS_FS_ACTIVE_ZONE_TRACKING +2700 fs/btrfs/free-space-cache.c

2678
2679 static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
2680 u64 bytenr, u64 size, bool used)
2681 {
2682 struct btrfs_space_info *sinfo = block_group->space_info;
2683 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2684 u64 offset = bytenr - block_group->start;
2685 u64 to_free, to_unusable;
2686 int bg_reclaim_threshold = 0;
2687 bool initial = (size == block_group->length);
2688 u64 reclaimable_unusable;
2689
2690 WARN_ON(!initial && offset + size > block_group->zone_capacity);
2691
2692 if (!initial)
2693 bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
2694
2695 spin_lock(&ctl->tree_lock);
2696 /* Count initial region as zone_unusable until it gets activated. */
2697 if (!used)
2698 to_free = size;
2699 else if (initial &&

> 2700			 test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&

2701 block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))
2702 to_free = 0;
2703 else if (initial)
2704 to_free = block_group->zone_capacity;
2705 else if (offset >= block_group->alloc_offset)
2706 to_free = size;
2707 else if (offset + size <= block_group->alloc_offset)
2708 to_free = 0;
2709 else
2710 to_free = offset + size - block_group->alloc_offset;
2711 to_unusable = size - to_free;
2712
2713 ctl->free_space += to_free;
2714 /*
2715 * If the block group is read-only, we should account freed space into
2716 * bytes_readonly.
2717 */
2718 if (!block_group->ro)
2719 block_group->zone_unusable += to_unusable;
2720 spin_unlock(&ctl->tree_lock);
2721 if (!used) {
2722 spin_lock(&block_group->lock);
2723 block_group->alloc_offset -= size;
2724 spin_unlock(&block_group->lock);
2725 }
2726
2727 reclaimable_unusable = block_group->zone_unusable -
2728 (block_group->length - block_group->zone_capacity);
2729 /* All the region is now unusable. Mark it as unused and reclaim */
2730 if (block_group->zone_unusable == block_group->length &&
2731 block_group->alloc_offset) {
2732 btrfs_mark_bg_unused(block_group);
2733 } else if (bg_reclaim_threshold &&
2734 reclaimable_unusable >=
2735 mult_perc(block_group->zone_capacity, bg_reclaim_threshold)) {
2736 btrfs_mark_bg_to_reclaim(block_group);
2737 }
2738
2739 return 0;
2740 }
2741

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#3 lore raw

Re: [RFC PATCH 1/2] btrfs: zoned: count fresh BG region as zone unusable

In reply to Naohiro Aota
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…

Hi Naohiro,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on kdave/for-next]
[also build test ERROR on linus/master v6.2 next-20230303] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Naohiro-Aota/btrfs-zoned-count-fresh-BG-region-as-zone-unusable/20230303-163006
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/ae5d21d50546abaedd89d52cefdd1c61c9018ec2.1677831912.git.naohiro.aota%40wdc.com
patch subject: [RFC PATCH 1/2] btrfs: zoned: count fresh BG region as zone unusable
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20230303/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/aef11808b70bc7a53270e26eef4c73ae8a1de4a8
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Naohiro-Aota/btrfs-zoned-count-fresh-BG-region-as-zone-unusable/20230303-163006 git checkout aef11808b70bc7a53270e26eef4c73ae8a1de4a8
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
                    test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&
                             ^
>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
>> fs/btrfs/free-space-cache.c:2700:13: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
   3 errors generated.
--
>> fs/btrfs/zoned.c:1586:15: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
           if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &cache->fs_info->flags) &&
                        ^
>> fs/btrfs/zoned.c:1586:15: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'
>> fs/btrfs/zoned.c:1586:15: error: use of undeclared identifier 'BTRFS_FS_ACTIVE_ZONE_TRACKING'

3 errors generated.

vim +/BTRFS_FS_ACTIVE_ZONE_TRACKING +2700 fs/btrfs/free-space-cache.c

2678
2679 static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
2680 u64 bytenr, u64 size, bool used)
2681 {
2682 struct btrfs_space_info *sinfo = block_group->space_info;
2683 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2684 u64 offset = bytenr - block_group->start;
2685 u64 to_free, to_unusable;
2686 int bg_reclaim_threshold = 0;
2687 bool initial = (size == block_group->length);
2688 u64 reclaimable_unusable;
2689
2690 WARN_ON(!initial && offset + size > block_group->zone_capacity);
2691
2692 if (!initial)
2693 bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold);
2694
2695 spin_lock(&ctl->tree_lock);
2696 /* Count initial region as zone_unusable until it gets activated. */
2697 if (!used)
2698 to_free = size;
2699 else if (initial &&

> 2700			 test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) &&

2701 block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))
2702 to_free = 0;
2703 else if (initial)
2704 to_free = block_group->zone_capacity;
2705 else if (offset >= block_group->alloc_offset)
2706 to_free = size;
2707 else if (offset + size <= block_group->alloc_offset)
2708 to_free = 0;
2709 else
2710 to_free = offset + size - block_group->alloc_offset;
2711 to_unusable = size - to_free;
2712
2713 ctl->free_space += to_free;
2714 /*
2715 * If the block group is read-only, we should account freed space into
2716 * bytes_readonly.
2717 */
2718 if (!block_group->ro)
2719 block_group->zone_unusable += to_unusable;
2720 spin_unlock(&ctl->tree_lock);
2721 if (!used) {
2722 spin_lock(&block_group->lock);
2723 block_group->alloc_offset -= size;
2724 spin_unlock(&block_group->lock);
2725 }
2726
2727 reclaimable_unusable = block_group->zone_unusable -
2728 (block_group->length - block_group->zone_capacity);
2729 /* All the region is now unusable. Mark it as unused and reclaim */
2730 if (block_group->zone_unusable == block_group->length &&
2731 block_group->alloc_offset) {
2732 btrfs_mark_bg_unused(block_group);
2733 } else if (bg_reclaim_threshold &&
2734 reclaimable_unusable >=
2735 mult_perc(block_group->zone_capacity, bg_reclaim_threshold)) {
2736 btrfs_mark_bg_to_reclaim(block_group);
2737 }
2738
2739 return 0;
2740 }
2741

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#4 lore raw

RFC PATCH 2/2 btrfs: zoned: drop space_info->active_total_bytes

In reply to Naohiro Aota

The space_info->active_total_bytes is no longer necessary as we now count the region of newly allocated block group as zone_unusable. Drop its usage.

---
 fs/btrfs/block-group.c |  6 ------
 fs/btrfs/space-info.c  | 40 +++++++++-------------------------------
 fs/btrfs/space-info.h  |  2 --
 fs/btrfs/zoned.c       |  4 ----
 4 files changed, 9 insertions(+), 43 deletions(-)
fs/btrfs/block-group.c +0 -6
index fdbbf4b3ddd3..1dd88107b98f 100644
@@ -1175,14 +1175,8 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
 			< block_group->zone_unusable);
 		WARN_ON(block_group->space_info->disk_total
 			< block_group->length * factor);
-		WARN_ON(test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE,
-				 &block_group->runtime_flags) &&
-			block_group->space_info->active_total_bytes
-			< block_group->length);
 	}
 	block_group->space_info->total_bytes -= block_group->length;
-	if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags))
-		block_group->space_info->active_total_bytes -= block_group->length;
 	block_group->space_info->bytes_readonly -=
 		(block_group->length - block_group->zone_unusable);
 	block_group->space_info->bytes_zone_unusable -=
fs/btrfs/space-info.c +9 -31
index 2237685d1ed0..3eecce86f63f 100644
@@ -308,8 +308,6 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
 	ASSERT(found);
 	spin_lock(&found->lock);
 	found->total_bytes += block_group->length;
-	if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags))
-		found->active_total_bytes += block_group->length;
 	found->disk_total += block_group->length * factor;
 	found->bytes_used += block_group->used;
 	found->disk_used += block_group->used * factor;
@@ -379,22 +377,6 @@ static u64 calc_available_free_space(struct btrfs_fs_info *fs_info,
 	return avail;
 }
 
-static inline u64 writable_total_bytes(struct btrfs_fs_info *fs_info,
-				       struct btrfs_space_info *space_info)
-{
-	/*
-	 * On regular filesystem, all total_bytes are always writable. On zoned
-	 * filesystem, there may be a limitation imposed by max_active_zones.
-	 * For metadata allocation, we cannot finish an existing active block
-	 * group to avoid a deadlock. Thus, we need to consider only the active
-	 * groups to be writable for metadata space.
-	 */
-	if (!btrfs_is_zoned(fs_info) || (space_info->flags & BTRFS_BLOCK_GROUP_DATA))
-		return space_info->total_bytes;
-
-	return space_info->active_total_bytes;
-}
-
 int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
 			 struct btrfs_space_info *space_info, u64 bytes,
 			 enum btrfs_reserve_flush_enum flush)
@@ -413,7 +395,7 @@ int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
 	else
 		avail = calc_available_free_space(fs_info, space_info, flush);
 
-	if (used + bytes < writable_total_bytes(fs_info, space_info) + avail)
+	if (used + bytes < space_info->total_bytes + avail)
 		return 1;
 	return 0;
 }
@@ -449,7 +431,7 @@ void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
 		ticket = list_first_entry(head, struct reserve_ticket, list);
 
 		/* Check and see if our ticket can be satisfied now. */
-		if ((used + ticket->bytes <= writable_total_bytes(fs_info, space_info)) ||
+		if ((used + ticket->bytes <= space_info->total_bytes) ||
 		    btrfs_can_overcommit(fs_info, space_info, ticket->bytes,
 					 flush)) {
 			btrfs_space_info_update_bytes_may_use(fs_info,
@@ -829,7 +811,6 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
 {
 	u64 used;
 	u64 avail;
-	u64 total;
 	u64 to_reclaim = space_info->reclaim_size;
 
 	lockdep_assert_held(&space_info->lock);
@@ -844,9 +825,8 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
 	 * space.  If that's the case add in our overage so we make sure to put
 	 * appropriate pressure on the flushing state machine.
 	 */
-	total = writable_total_bytes(fs_info, space_info);
-	if (total + avail < used)
-		to_reclaim += used - (total + avail);
+	if (space_info->total_bytes + avail < used)
+		to_reclaim += used - (space_info->total_bytes + avail);
 
 	return to_reclaim;
 }
@@ -856,11 +836,10 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
 {
 	u64 global_rsv_size = fs_info->global_block_rsv.reserved;
 	u64 ordered, delalloc;
-	u64 total = writable_total_bytes(fs_info, space_info);
 	u64 thresh;
 	u64 used;
 
-	thresh = mult_perc(total, 90);
+	thresh = mult_perc(space_info->total_bytes, 90);
 
 	lockdep_assert_held(&space_info->lock);
 
@@ -923,8 +902,8 @@ static bool need_preemptive_reclaim(struct btrfs_fs_info *fs_info,
 					   BTRFS_RESERVE_FLUSH_ALL);
 	used = space_info->bytes_used + space_info->bytes_reserved +
 	       space_info->bytes_readonly + global_rsv_size;
-	if (used < total)
-		thresh += total - used;
+	if (used < space_info->total_bytes)
+		thresh += space_info->total_bytes - used;
 	thresh >>= space_info->clamp;
 
 	used = space_info->bytes_pinned;
@@ -1651,7 +1630,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
 	 * can_overcommit() to ensure we can overcommit to continue.
 	 */
 	if (!pending_tickets &&
-	    ((used + orig_bytes <= writable_total_bytes(fs_info, space_info)) ||
+	    ((used + orig_bytes <= space_info->total_bytes) ||
 	     btrfs_can_overcommit(fs_info, space_info, orig_bytes, flush))) {
 		btrfs_space_info_update_bytes_may_use(fs_info, space_info,
 						      orig_bytes);
@@ -1665,8 +1644,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
 	 */
 	if (ret && unlikely(flush == BTRFS_RESERVE_FLUSH_EMERGENCY)) {
 		used = btrfs_space_info_used(space_info, false);
-		if (used + orig_bytes <=
-		    writable_total_bytes(fs_info, space_info)) {
+		if (used + orig_bytes <= space_info->total_bytes) {
 			btrfs_space_info_update_bytes_may_use(fs_info, space_info,
 							      orig_bytes);
 			ret = 0;
fs/btrfs/space-info.h +0 -2
index fc99ea2b0c34..2033b71b18ce 100644
@@ -96,8 +96,6 @@ struct btrfs_space_info {
 	u64 bytes_may_use;	/* number of bytes that may be used for
 				   delalloc/allocations */
 	u64 bytes_readonly;	/* total bytes that are read only */
-	/* Total bytes in the space, but only accounts active block groups. */
-	u64 active_total_bytes;
 	u64 bytes_zone_unusable;	/* total bytes that are unusable until
 					   resetting the device zone */
 
fs/btrfs/zoned.c +0 -4
index 848d53b1f9d5..50140109a079 100644
@@ -2306,10 +2306,6 @@ int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info,
 	if (!btrfs_is_zoned(fs_info) || (space_info->flags & BTRFS_BLOCK_GROUP_DATA))
 		return 0;
 
-	/* No more block groups to activate */
-	if (space_info->active_total_bytes == space_info->total_bytes)
-		return 0;
-
 	for (;;) {
 		int ret;
 		bool need_finish = false;
Signature · 1 line
2.39.2