]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Kill non-lru cache replacement policies
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 24 Dec 2021 07:55:11 +0000 (02:55 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:19 +0000 (17:09 -0400)
Prep work for persistent LRUs and getting rid of the in memory bucket
array.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_background.c
fs/bcachefs/bcachefs_format.h
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/super-io.h
fs/bcachefs/super_types.h
fs/bcachefs/sysfs.c

index 39538dada30168659434b3b477b6b0a2f1aec4f2..9f98860da5cc528ad7b713197c9e9e8a1a327aee 100644 (file)
@@ -628,76 +628,6 @@ static void find_reclaimable_buckets_lru(struct bch_fs *c, struct bch_dev *ca)
        up_read(&ca->bucket_lock);
 }
 
-static void find_reclaimable_buckets_fifo(struct bch_fs *c, struct bch_dev *ca)
-{
-       struct bucket_array *buckets = bucket_array(ca);
-       struct bucket_mark m;
-       size_t b, start;
-
-       if (ca->fifo_last_bucket <  ca->mi.first_bucket ||
-           ca->fifo_last_bucket >= ca->mi.nbuckets)
-               ca->fifo_last_bucket = ca->mi.first_bucket;
-
-       start = ca->fifo_last_bucket;
-
-       do {
-               ca->fifo_last_bucket++;
-               if (ca->fifo_last_bucket == ca->mi.nbuckets)
-                       ca->fifo_last_bucket = ca->mi.first_bucket;
-
-               b = ca->fifo_last_bucket;
-               m = READ_ONCE(buckets->b[b].mark);
-
-               if (bch2_can_invalidate_bucket(ca, b, m)) {
-                       struct alloc_heap_entry e = { .bucket = b, .nr = 1, };
-
-                       heap_add(&ca->alloc_heap, e, bucket_alloc_cmp, NULL);
-                       if (heap_full(&ca->alloc_heap))
-                               break;
-               }
-
-               cond_resched();
-       } while (ca->fifo_last_bucket != start);
-}
-
-static void find_reclaimable_buckets_random(struct bch_fs *c, struct bch_dev *ca)
-{
-       struct bucket_array *buckets = bucket_array(ca);
-       struct bucket_mark m;
-       size_t checked, i;
-
-       for (checked = 0;
-            checked < ca->mi.nbuckets / 2;
-            checked++) {
-               size_t b = bch2_rand_range(ca->mi.nbuckets -
-                                          ca->mi.first_bucket) +
-                       ca->mi.first_bucket;
-
-               m = READ_ONCE(buckets->b[b].mark);
-
-               if (bch2_can_invalidate_bucket(ca, b, m)) {
-                       struct alloc_heap_entry e = { .bucket = b, .nr = 1, };
-
-                       heap_add(&ca->alloc_heap, e, bucket_alloc_cmp, NULL);
-                       if (heap_full(&ca->alloc_heap))
-                               break;
-               }
-
-               cond_resched();
-       }
-
-       sort(ca->alloc_heap.data,
-            ca->alloc_heap.used,
-            sizeof(ca->alloc_heap.data[0]),
-            bucket_idx_cmp, NULL);
-
-       /* remove duplicates: */
-       for (i = 0; i + 1 < ca->alloc_heap.used; i++)
-               if (ca->alloc_heap.data[i].bucket ==
-                   ca->alloc_heap.data[i + 1].bucket)
-                       ca->alloc_heap.data[i].nr = 0;
-}
-
 static size_t find_reclaimable_buckets(struct bch_fs *c, struct bch_dev *ca)
 {
        size_t i, nr = 0;
@@ -705,17 +635,7 @@ static size_t find_reclaimable_buckets(struct bch_fs *c, struct bch_dev *ca)
        ca->inc_gen_needs_gc                    = 0;
        ca->inc_gen_really_needs_gc             = 0;
 
-       switch (ca->mi.replacement) {
-       case BCH_CACHE_REPLACEMENT_lru:
-               find_reclaimable_buckets_lru(c, ca);
-               break;
-       case BCH_CACHE_REPLACEMENT_fifo:
-               find_reclaimable_buckets_fifo(c, ca);
-               break;
-       case BCH_CACHE_REPLACEMENT_random:
-               find_reclaimable_buckets_random(c, ca);
-               break;
-       }
+       find_reclaimable_buckets_lru(c, ca);
 
        heap_resort(&ca->alloc_heap, bucket_alloc_cmp, NULL);
 
index bef924ab12a8f6567a1200b7110bf0e4ffd1c3d6..3c0ba301dad5549c7863adb7acd650e20588146c 100644 (file)
@@ -1067,8 +1067,7 @@ struct bch_member {
 };
 
 LE64_BITMASK(BCH_MEMBER_STATE,         struct bch_member, flags[0],  0,  4)
-/* 4-10 unused, was TIER, HAS_(META)DATA */
-LE64_BITMASK(BCH_MEMBER_REPLACEMENT,   struct bch_member, flags[0], 10, 14)
+/* 4-14 unused, was TIER, HAS_(META)DATA, REPLACEMENT */
 LE64_BITMASK(BCH_MEMBER_DISCARD,       struct bch_member, flags[0], 14, 15)
 LE64_BITMASK(BCH_MEMBER_DATA_ALLOWED,  struct bch_member, flags[0], 15, 20)
 LE64_BITMASK(BCH_MEMBER_GROUP,         struct bch_member, flags[0], 20, 28)
@@ -1092,18 +1091,6 @@ enum bch_member_state {
        BCH_MEMBER_STATE_NR
 };
 
-#define BCH_CACHE_REPLACEMENT_POLICIES()       \
-       x(lru,          0)                      \
-       x(fifo,         1)                      \
-       x(random,       2)
-
-enum bch_cache_replacement_policies {
-#define x(t, n) BCH_CACHE_REPLACEMENT_##t = n,
-       BCH_CACHE_REPLACEMENT_POLICIES()
-#undef x
-       BCH_CACHE_REPLACEMENT_NR
-};
-
 struct bch_sb_field_members {
        struct bch_sb_field     field;
        struct bch_member       members[0];
index 9b75c852bac87170341767f48f4cd95aa0df7428..d9ca69f2ecde91bddedccd3cccede70dc29ce7f4 100644 (file)
@@ -66,11 +66,6 @@ const char * const bch2_data_types[] = {
        NULL
 };
 
-const char * const bch2_cache_replacement_policies[] = {
-       BCH_CACHE_REPLACEMENT_POLICIES()
-       NULL
-};
-
 const char * const bch2_member_states[] = {
        BCH_MEMBER_STATES()
        NULL
index 617d9fd2ac0a2705f1baa1291725237f5865455a..af61fe588d3fd6ec626e65da9d258b15c01257af 100644 (file)
@@ -19,7 +19,6 @@ extern const char * const bch2_compression_opts[];
 extern const char * const bch2_str_hash_types[];
 extern const char * const bch2_str_hash_opts[];
 extern const char * const bch2_data_types[];
-extern const char * const bch2_cache_replacement_policies[];
 extern const char * const bch2_member_states[];
 extern const char * const bch2_d_types[];
 
index 62d040d571c086373c7f5d7d186de5f5fc37cffe..f182711cc48f1e5665bd42139e51c960a460fcef 100644 (file)
@@ -110,7 +110,6 @@ static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi)
                .bucket_size    = le16_to_cpu(mi->bucket_size),
                .group          = BCH_MEMBER_GROUP(mi),
                .state          = BCH_MEMBER_STATE(mi),
-               .replacement    = BCH_MEMBER_REPLACEMENT(mi),
                .discard        = BCH_MEMBER_DISCARD(mi),
                .data_allowed   = BCH_MEMBER_DATA_ALLOWED(mi),
                .durability     = BCH_MEMBER_DURABILITY(mi)
index b14b2d82c655a43ee2730c1368df06e26fa54602..1c0241304f32e87a0dc365d04700c64b0e06ab08 100644 (file)
@@ -30,7 +30,6 @@ struct bch_member_cpu {
        u16                     bucket_size;    /* sectors */
        u16                     group;
        u8                      state;
-       u8                      replacement;
        u8                      discard;
        u8                      data_allowed;
        u8                      durability;
index 0a0798bae4d61ad00f6b802ff9124191cec91614..341ba3fdd6fcc36c6f5eca66ce7f8af441d8eb89 100644 (file)
@@ -177,7 +177,6 @@ read_attribute(extent_migrate_done);
 read_attribute(extent_migrate_raced);
 
 rw_attribute(discard);
-rw_attribute(cache_replacement_policy);
 rw_attribute(label);
 
 rw_attribute(copy_gc_enabled);
@@ -826,14 +825,6 @@ SHOW(bch2_dev)
                return out.pos - buf;
        }
 
-       if (attr == &sysfs_cache_replacement_policy) {
-               bch2_string_opt_to_text(&out,
-                                       bch2_cache_replacement_policies,
-                                       ca->mi.replacement);
-               pr_buf(&out, "\n");
-               return out.pos - buf;
-       }
-
        if (attr == &sysfs_state_rw) {
                bch2_string_opt_to_text(&out, bch2_member_states,
                                        ca->mi.state);
@@ -893,22 +884,6 @@ STORE(bch2_dev)
                mutex_unlock(&c->sb_lock);
        }
 
-       if (attr == &sysfs_cache_replacement_policy) {
-               ssize_t v = __sysfs_match_string(bch2_cache_replacement_policies, -1, buf);
-
-               if (v < 0)
-                       return v;
-
-               mutex_lock(&c->sb_lock);
-               mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
-
-               if ((unsigned) v != BCH_MEMBER_REPLACEMENT(mi)) {
-                       SET_BCH_MEMBER_REPLACEMENT(mi, v);
-                       bch2_write_super(c);
-               }
-               mutex_unlock(&c->sb_lock);
-       }
-
        if (attr == &sysfs_label) {
                char *tmp;
                int ret;
@@ -939,7 +914,6 @@ struct attribute *bch2_dev_files[] = {
 
        /* settings: */
        &sysfs_discard,
-       &sysfs_cache_replacement_policy,
        &sysfs_state_rw,
        &sysfs_label,