mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 15:29:16 +00:00
bcachefs: Kill non-lru cache replacement policies
Prep work for persistent LRUs and getting rid of the in memory bucket array. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
73b460977e
commit
7243498de7
@ -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);
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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
|
||||
|
@ -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[];
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user