3
3
#include "bbpos.h"
4
4
#include "alloc_background.h"
5
5
#include "backpointers.h"
6
+ #include "bbpos.h"
6
7
#include "bkey_buf.h"
7
8
#include "btree_cache.h"
8
9
#include "btree_update.h"
9
10
#include "btree_update_interior.h"
10
11
#include "btree_write_buffer.h"
11
12
#include "checksum.h"
13
+ #include "disk_accounting.h"
12
14
#include "error.h"
13
15
14
16
#include <linux/mm.h>
@@ -782,12 +784,80 @@ static int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
782
784
return ret ;
783
785
}
784
786
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
+
785
852
static int bch2_check_extents_to_backpointers_pass (struct btree_trans * trans ,
786
853
struct extents_to_bp_state * s )
787
854
{
788
855
struct bch_fs * c = trans -> c ;
856
+ struct progress_indicator_state progress ;
789
857
int ret = 0 ;
790
858
859
+ progress_init (& progress , trans -> c , BIT_ULL (BTREE_ID_extents )|BIT_ULL (BTREE_ID_reflink ));
860
+
791
861
for (enum btree_id btree_id = 0 ;
792
862
btree_id < btree_id_nr_alive (c );
793
863
btree_id ++ ) {
@@ -805,6 +875,7 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
805
875
BTREE_ITER_prefetch );
806
876
807
877
ret = for_each_btree_key_continue (trans , iter , 0 , k , ({
878
+ progress_update_iter (trans , & progress , & iter , "extents_to_backpointers" );
808
879
check_extent_to_backpointers (trans , s , btree_id , level , k ) ?:
809
880
bch2_trans_commit (trans , NULL , NULL , BCH_TRANS_COMMIT_no_enospc );
810
881
}));
@@ -920,19 +991,24 @@ static int bch2_check_backpointers_to_extents_pass(struct btree_trans *trans,
920
991
struct bbpos start ,
921
992
struct bbpos end )
922
993
{
994
+ struct bch_fs * c = trans -> c ;
923
995
struct bkey_buf last_flushed ;
996
+ struct progress_indicator_state progress ;
924
997
925
998
bch2_bkey_buf_init (& last_flushed );
926
999
bkey_init (& last_flushed .k -> k );
1000
+ progress_init (& progress , trans -> c , BIT_ULL (BTREE_ID_backpointers ));
927
1001
928
1002
int ret = for_each_btree_key_commit (trans , iter , BTREE_ID_backpointers ,
929
1003
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 );
936
1012
return ret ;
937
1013
}
938
1014
0 commit comments