@@ -259,6 +259,14 @@ int bch2_alloc_v4_invalid(struct bch_fs *c, struct bkey_s_c k,
259259 "invalid data type (got %u should be %u)" ,
260260 a .v -> data_type , alloc_data_type (* a .v , a .v -> data_type ));
261261
262+ for (unsigned i = 0 ; i < 2 ; i ++ )
263+ bkey_fsck_err_on (a .v -> io_time [i ] > LRU_TIME_MAX ,
264+ c , err ,
265+ alloc_key_io_time_bad ,
266+ "invalid io_time[%s]: %llu, max %llu" ,
267+ i == READ ? "read" : "write" ,
268+ a .v -> io_time [i ], LRU_TIME_MAX );
269+
262270 switch (a .v -> data_type ) {
263271 case BCH_DATA_free :
264272 case BCH_DATA_need_gc_gens :
@@ -757,8 +765,8 @@ int bch2_trigger_alloc(struct btree_trans *trans,
757765 alloc_data_type_set (new_a , new_a -> data_type );
758766
759767 if (bch2_bucket_sectors_total (* new_a ) > bch2_bucket_sectors_total (* old_a )) {
760- new_a -> io_time [READ ] = max_t ( u64 , 1 , atomic64_read ( & c -> io_clock [ READ ]. now ) );
761- new_a -> io_time [WRITE ]= max_t ( u64 , 1 , atomic64_read ( & c -> io_clock [ WRITE ]. now ) );
768+ new_a -> io_time [READ ] = bch2_current_io_time ( c , READ );
769+ new_a -> io_time [WRITE ]= bch2_current_io_time ( c , WRITE );
762770 SET_BCH_ALLOC_V4_NEED_INC_GEN (new_a , true);
763771 SET_BCH_ALLOC_V4_NEED_DISCARD (new_a , true);
764772 }
@@ -781,7 +789,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
781789
782790 if (new_a -> data_type == BCH_DATA_cached &&
783791 !new_a -> io_time [READ ])
784- new_a -> io_time [READ ] = max_t ( u64 , 1 , atomic64_read ( & c -> io_clock [ READ ]. now ) );
792+ new_a -> io_time [READ ] = bch2_current_io_time ( c , READ );
785793
786794 u64 old_lru = alloc_lru_idx_read (* old_a );
787795 u64 new_lru = alloc_lru_idx_read (* new_a );
@@ -1579,7 +1587,7 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
15791587 if (ret )
15801588 goto err ;
15811589
1582- a_mut -> v .io_time [READ ] = atomic64_read ( & c -> io_clock [ READ ]. now );
1590+ a_mut -> v .io_time [READ ] = bch2_current_io_time ( c , READ );
15831591 ret = bch2_trans_update (trans , alloc_iter ,
15841592 & a_mut -> k_i , BTREE_TRIGGER_norun );
15851593 if (ret )
@@ -1975,8 +1983,8 @@ static int invalidate_one_bucket(struct btree_trans *trans,
19751983 a -> v .data_type = 0 ;
19761984 a -> v .dirty_sectors = 0 ;
19771985 a -> v .cached_sectors = 0 ;
1978- a -> v .io_time [READ ] = atomic64_read ( & c -> io_clock [ READ ]. now );
1979- a -> v .io_time [WRITE ] = atomic64_read ( & c -> io_clock [ WRITE ]. now );
1986+ a -> v .io_time [READ ] = bch2_current_io_time ( c , READ );
1987+ a -> v .io_time [WRITE ] = bch2_current_io_time ( c , WRITE );
19801988
19811989 ret = bch2_trans_commit (trans , NULL , NULL ,
19821990 BCH_WATERMARK_btree |
@@ -2204,7 +2212,7 @@ int bch2_bucket_io_time_reset(struct btree_trans *trans, unsigned dev,
22042212 if (ret )
22052213 return ret ;
22062214
2207- now = atomic64_read ( & c -> io_clock [ rw ]. now );
2215+ now = bch2_current_io_time ( c , rw );
22082216 if (a -> v .io_time [rw ] == now )
22092217 goto out ;
22102218
0 commit comments