Skip to content

Commit b99a94f

Browse files
author
Kent Overstreet
committed
bcachefs: Progress indicator for extents_to_backpointers
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 3621ecc commit b99a94f

File tree

1 file changed

+82
-6
lines changed

1 file changed

+82
-6
lines changed

fs/bcachefs/backpointers.c

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include "bbpos.h"
44
#include "alloc_background.h"
55
#include "backpointers.h"
6+
#include "bbpos.h"
67
#include "bkey_buf.h"
78
#include "btree_cache.h"
89
#include "btree_update.h"
910
#include "btree_update_interior.h"
1011
#include "btree_write_buffer.h"
1112
#include "checksum.h"
13+
#include "disk_accounting.h"
1214
#include "error.h"
1315

1416
#include <linux/mm.h>
@@ -782,12 +784,80 @@ static int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
782784
return ret;
783785
}
784786

787+
struct progress_indicator_state {
788+
unsigned long next_print;
789+
u64 nodes_seen;
790+
u64 nodes_total;
791+
struct btree *last_node;
792+
};
793+
794+
static inline void progress_init(struct progress_indicator_state *s,
795+
struct bch_fs *c,
796+
u64 btree_id_mask)
797+
{
798+
memset(s, 0, sizeof(*s));
799+
800+
s->next_print = jiffies + HZ * 10;
801+
802+
for (unsigned i = 0; i < BTREE_ID_NR; i++) {
803+
if (!(btree_id_mask & BIT_ULL(i)))
804+
continue;
805+
806+
struct disk_accounting_pos acc = {
807+
.type = BCH_DISK_ACCOUNTING_btree,
808+
.btree.id = i,
809+
};
810+
811+
u64 v;
812+
bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc), &v, 1);
813+
s->nodes_total += div64_ul(v, btree_sectors(c));
814+
}
815+
}
816+
817+
static inline bool progress_update_p(struct progress_indicator_state *s)
818+
{
819+
bool ret = time_after_eq(jiffies, s->next_print);
820+
821+
if (ret)
822+
s->next_print = jiffies + HZ * 10;
823+
return ret;
824+
}
825+
826+
static void progress_update_iter(struct btree_trans *trans,
827+
struct progress_indicator_state *s,
828+
struct btree_iter *iter,
829+
const char *msg)
830+
{
831+
struct bch_fs *c = trans->c;
832+
struct btree *b = path_l(btree_iter_path(trans, iter))->b;
833+
834+
s->nodes_seen += b != s->last_node;
835+
s->last_node = b;
836+
837+
if (progress_update_p(s)) {
838+
struct printbuf buf = PRINTBUF;
839+
unsigned percent = s->nodes_total
840+
? div64_u64(s->nodes_seen * 100, s->nodes_total)
841+
: 0;
842+
843+
prt_printf(&buf, "%s: %d%%, done %llu/%llu nodes, at ",
844+
msg, percent, s->nodes_seen, s->nodes_total);
845+
bch2_bbpos_to_text(&buf, BBPOS(iter->btree_id, iter->pos));
846+
847+
bch_info(c, "%s", buf.buf);
848+
printbuf_exit(&buf);
849+
}
850+
}
851+
785852
static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
786853
struct extents_to_bp_state *s)
787854
{
788855
struct bch_fs *c = trans->c;
856+
struct progress_indicator_state progress;
789857
int ret = 0;
790858

859+
progress_init(&progress, trans->c, BIT_ULL(BTREE_ID_extents)|BIT_ULL(BTREE_ID_reflink));
860+
791861
for (enum btree_id btree_id = 0;
792862
btree_id < btree_id_nr_alive(c);
793863
btree_id++) {
@@ -805,6 +875,7 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
805875
BTREE_ITER_prefetch);
806876

807877
ret = for_each_btree_key_continue(trans, iter, 0, k, ({
878+
progress_update_iter(trans, &progress, &iter, "extents_to_backpointers");
808879
check_extent_to_backpointers(trans, s, btree_id, level, k) ?:
809880
bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc);
810881
}));
@@ -920,19 +991,24 @@ static int bch2_check_backpointers_to_extents_pass(struct btree_trans *trans,
920991
struct bbpos start,
921992
struct bbpos end)
922993
{
994+
struct bch_fs *c = trans->c;
923995
struct bkey_buf last_flushed;
996+
struct progress_indicator_state progress;
924997

925998
bch2_bkey_buf_init(&last_flushed);
926999
bkey_init(&last_flushed.k->k);
1000+
progress_init(&progress, trans->c, BIT_ULL(BTREE_ID_backpointers));
9271001

9281002
int ret = for_each_btree_key_commit(trans, iter, BTREE_ID_backpointers,
9291003
POS_MIN, BTREE_ITER_prefetch, k,
930-
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
931-
check_one_backpointer(trans, start, end,
932-
bkey_s_c_to_backpointer(k),
933-
&last_flushed));
934-
935-
bch2_bkey_buf_exit(&last_flushed, trans->c);
1004+
NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
1005+
progress_update_iter(trans, &progress, &iter, "backpointers_to_extents");
1006+
check_one_backpointer(trans, start, end,
1007+
bkey_s_c_to_backpointer(k),
1008+
&last_flushed);
1009+
}));
1010+
1011+
bch2_bkey_buf_exit(&last_flushed, c);
9361012
return ret;
9371013
}
9381014

0 commit comments

Comments
 (0)