]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Improve trace_rebalance_extent
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 26 Oct 2024 05:42:57 +0000 (01:42 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:16 +0000 (01:36 -0500)
We now say explicitly which pointers are being moved or compressed

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/extents.c
fs/bcachefs/rebalance.c
fs/bcachefs/rebalance.h

index bee083d787f210c6afcadf7f464cf7f9dced7485..6f9514c19b2fbf2ec99cbc4a75f3504c6f912c3e 100644 (file)
@@ -21,6 +21,7 @@
 #include "extents.h"
 #include "inode.h"
 #include "journal.h"
+#include "rebalance.h"
 #include "replicas.h"
 #include "super.h"
 #include "super-io.h"
@@ -1452,39 +1453,9 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c,
                                       struct bkey_s_c k)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       unsigned rewrite_ptrs = 0;
 
-       if (opts->background_compression) {
-               unsigned compression_type = bch2_compression_opt_to_type(opts->background_compression);
-               const union bch_extent_entry *entry;
-               struct extent_ptr_decoded p;
-               unsigned ptr_bit = 1;
-
-               bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
-                       if (p.crc.compression_type == BCH_COMPRESSION_TYPE_incompressible ||
-                           p.ptr.unwritten) {
-                               rewrite_ptrs = 0;
-                               goto incompressible;
-                       }
-
-                       if (!p.ptr.cached && p.crc.compression_type != compression_type)
-                               rewrite_ptrs |= ptr_bit;
-                       ptr_bit <<= 1;
-               }
-       }
-incompressible:
-       if (opts->background_target &&
-           bch2_target_accepts_data(c, BCH_DATA_user, opts->background_target)) {
-               unsigned ptr_bit = 1;
-
-               bkey_for_each_ptr(ptrs, ptr) {
-                       if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, opts->background_target))
-                               rewrite_ptrs |= ptr_bit;
-                       ptr_bit <<= 1;
-               }
-       }
-
-       return rewrite_ptrs;
+       return bch2_bkey_ptrs_need_compress(c, opts, k, ptrs) |
+               bch2_bkey_ptrs_need_move(c, opts, ptrs);
 }
 
 u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k)
index 3be9c85dd55dcb339428944e8ed406ad086b3d5a..124da250cbe75f436156ef067c3d98d6c8348480 100644 (file)
@@ -177,12 +177,28 @@ static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
        if (trace_rebalance_extent_enabled()) {
                struct printbuf buf = PRINTBUF;
 
-               prt_str(&buf, "target=");
-               bch2_target_to_text(&buf, c, io_opts->background_target);
-               prt_str(&buf, " compression=");
-               bch2_compression_opt_to_text(&buf, io_opts->background_compression);
-               prt_str(&buf, " ");
                bch2_bkey_val_to_text(&buf, c, k);
+               prt_newline(&buf);
+
+               struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
+
+               unsigned p = bch2_bkey_ptrs_need_compress(c, io_opts, k, ptrs);
+               if (p) {
+                       prt_str(&buf, "compression=");
+                       bch2_compression_opt_to_text(&buf, io_opts->background_compression);
+                       prt_str(&buf, " ");
+                       bch2_prt_u64_base2(&buf, p);
+                       prt_newline(&buf);
+               }
+
+               p = bch2_bkey_ptrs_need_move(c, io_opts, ptrs);
+               if (p) {
+                       prt_str(&buf, "move=");
+                       bch2_target_to_text(&buf, c, io_opts->background_target);
+                       prt_str(&buf, " ");
+                       bch2_prt_u64_base2(&buf, p);
+                       prt_newline(&buf);
+               }
 
                trace_rebalance_extent(c, buf.buf);
                printbuf_exit(&buf);
index 791649c04ff5de2a1013655893eff15abe7c860c..606c88f49f7f4b52979f86a8ecfe342ae438ba08 100644 (file)
@@ -2,8 +2,57 @@
 #ifndef _BCACHEFS_REBALANCE_H
 #define _BCACHEFS_REBALANCE_H
 
+#include "compress.h"
+#include "disk_groups.h"
 #include "rebalance_types.h"
 
+static inline unsigned bch2_bkey_ptrs_need_compress(struct bch_fs *c,
+                                          struct bch_io_opts *opts,
+                                          struct bkey_s_c k,
+                                          struct bkey_ptrs_c ptrs)
+{
+       if (!opts->background_compression)
+               return 0;
+
+       unsigned compression_type = bch2_compression_opt_to_type(opts->background_compression);
+       const union bch_extent_entry *entry;
+       struct extent_ptr_decoded p;
+       unsigned ptr_bit = 1;
+       unsigned rewrite_ptrs = 0;
+
+       bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
+               if (p.crc.compression_type == BCH_COMPRESSION_TYPE_incompressible ||
+                   p.ptr.unwritten)
+                       return 0;
+
+               if (!p.ptr.cached && p.crc.compression_type != compression_type)
+                       rewrite_ptrs |= ptr_bit;
+               ptr_bit <<= 1;
+       }
+
+       return rewrite_ptrs;
+}
+
+static inline unsigned bch2_bkey_ptrs_need_move(struct bch_fs *c,
+                                      struct bch_io_opts *opts,
+                                      struct bkey_ptrs_c ptrs)
+{
+       if (!opts->background_target ||
+           !bch2_target_accepts_data(c, BCH_DATA_user, opts->background_target))
+               return 0;
+
+       unsigned ptr_bit = 1;
+       unsigned rewrite_ptrs = 0;
+
+       bkey_for_each_ptr(ptrs, ptr) {
+               if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, opts->background_target))
+                       rewrite_ptrs |= ptr_bit;
+               ptr_bit <<= 1;
+       }
+
+       return rewrite_ptrs;
+}
+
 int bch2_set_rebalance_needs_scan_trans(struct btree_trans *, u64);
 int bch2_set_rebalance_needs_scan(struct bch_fs *, u64 inum);
 int bch2_set_fs_needs_rebalance(struct bch_fs *);