]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/movinggc.c
Update bcachefs sources to 8c94740b1bf8 bcachefs: Add missing vaidation for jset_entr...
[bcachefs-tools-debian] / libbcachefs / movinggc.c
index e884324bd2fa3e742e17c46522ba47b921b8e21a..d079ba7aa65349bd8c6fbe73f65dee2872a249a0 100644 (file)
@@ -91,7 +91,7 @@ static int bch2_bucket_is_movable(struct btree_trans *trans,
 
        a = bch2_alloc_to_v4(k, &_a);
        b->k.gen        = a->gen;
-       b->sectors      = a->dirty_sectors;
+       b->sectors      = bch2_bucket_sectors_dirty(*a);
 
        ret = data_type_movable(a->data_type) &&
                a->fragmentation_lru &&
@@ -149,6 +149,7 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
        struct bkey_s_c k;
        size_t nr_to_get = max_t(size_t, 16U, buckets_in_flight->nr / 4);
        size_t saw = 0, in_flight = 0, not_movable = 0, sectors = 0;
+       struct bpos last_flushed_pos = POS_MIN;
        int ret;
 
        move_buckets_wait(ctxt, buckets_in_flight, false);
@@ -165,11 +166,16 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, 0, 0),
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, U64_MAX, LRU_TIME_MAX),
                                  0, k, ({
-               struct move_bucket b = { .k.bucket = u64_to_bucket(k.k->p.offset) };
-               int ret2 = 0;
+               int ret2 = bch2_check_lru_key(trans, &iter, k, &last_flushed_pos);
+               if (ret2) {
+                       ret2 = ret2 < 0 ? ret2 : 0;
+                       goto next;
+               }
 
                saw++;
 
+               struct move_bucket b = { .k.bucket = u64_to_bucket(k.k->p.offset) };
+
                if (!bch2_bucket_is_movable(trans, &b, lru_pos_time(k.k->p)))
                        not_movable++;
                else if (bucket_in_flight(buckets_in_flight, b.k))
@@ -179,6 +185,7 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
                        if (ret2 >= 0)
                                sectors += b.sectors;
                }
+next:
                ret2;
        }));