mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-12 21:44:06 +08:00
bcachefs: bch2_btree_bit_mod()
New helper for bitset btrees. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
4dc5bb9adf
commit
8e992c6c1f
@ -72,6 +72,8 @@ int bch2_btree_delete_range_trans(struct btree_trans *, enum btree_id,
|
||||
int bch2_btree_delete_range(struct bch_fs *, enum btree_id,
|
||||
struct bpos, struct bpos, unsigned, u64 *);
|
||||
|
||||
int bch2_btree_bit_mod(struct btree_trans *, enum btree_id, struct bpos, bool);
|
||||
|
||||
int bch2_btree_node_rewrite(struct btree_trans *, struct btree_iter *,
|
||||
struct btree *, unsigned);
|
||||
void bch2_btree_node_rewrite_async(struct bch_fs *, struct btree *);
|
||||
|
@ -1996,6 +1996,24 @@ int bch2_btree_delete_range(struct bch_fs *c, enum btree_id id,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bch2_btree_bit_mod(struct btree_trans *trans, enum btree_id btree,
|
||||
struct bpos pos, bool set)
|
||||
{
|
||||
struct bkey_i *k;
|
||||
int ret = 0;
|
||||
|
||||
k = bch2_trans_kmalloc_nomemzero(trans, sizeof(*k));
|
||||
ret = PTR_ERR_OR_ZERO(k);
|
||||
if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
bkey_init(&k->k);
|
||||
k->k.type = set ? KEY_TYPE_set : KEY_TYPE_deleted;
|
||||
k->k.p = pos;
|
||||
|
||||
return bch2_trans_update_buffered(trans, btree, k);
|
||||
}
|
||||
|
||||
static int __bch2_trans_log_msg(darray_u64 *entries, const char *fmt, va_list args)
|
||||
{
|
||||
struct printbuf buf = PRINTBUF;
|
||||
|
@ -41,28 +41,12 @@ void bch2_lru_pos_to_text(struct printbuf *out, struct bpos lru)
|
||||
}
|
||||
|
||||
static int __bch2_lru_set(struct btree_trans *trans, u16 lru_id,
|
||||
u64 dev_bucket, u64 time, unsigned key_type)
|
||||
u64 dev_bucket, u64 time, bool set)
|
||||
{
|
||||
struct bkey_i *k;
|
||||
int ret = 0;
|
||||
|
||||
if (!time)
|
||||
return 0;
|
||||
|
||||
k = bch2_trans_kmalloc_nomemzero(trans, sizeof(*k));
|
||||
ret = PTR_ERR_OR_ZERO(k);
|
||||
if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
bkey_init(&k->k);
|
||||
k->k.type = key_type;
|
||||
k->k.p = lru_pos(lru_id, dev_bucket, time);
|
||||
|
||||
EBUG_ON(lru_pos_id(k->k.p) != lru_id);
|
||||
EBUG_ON(lru_pos_time(k->k.p) != time);
|
||||
EBUG_ON(k->k.p.offset != dev_bucket);
|
||||
|
||||
return bch2_trans_update_buffered(trans, BTREE_ID_lru, k);
|
||||
return time
|
||||
? bch2_btree_bit_mod(trans, BTREE_ID_lru,
|
||||
lru_pos(lru_id, dev_bucket, time), set)
|
||||
: 0;
|
||||
}
|
||||
|
||||
int bch2_lru_del(struct btree_trans *trans, u16 lru_id, u64 dev_bucket, u64 time)
|
||||
|
@ -5,13 +5,6 @@
|
||||
#define LRU_TIME_BITS 48
|
||||
#define LRU_TIME_MAX ((1ULL << LRU_TIME_BITS) - 1)
|
||||
|
||||
static inline struct bpos lru_pos(u16 lru_id, u64 dev_bucket, u64 time)
|
||||
{
|
||||
EBUG_ON(time > LRU_TIME_MAX);
|
||||
|
||||
return POS(((u64) lru_id << LRU_TIME_BITS)|time, dev_bucket);
|
||||
}
|
||||
|
||||
static inline u64 lru_pos_id(struct bpos pos)
|
||||
{
|
||||
return pos.inode >> LRU_TIME_BITS;
|
||||
@ -22,6 +15,18 @@ static inline u64 lru_pos_time(struct bpos pos)
|
||||
return pos.inode & ~(~0ULL << LRU_TIME_BITS);
|
||||
}
|
||||
|
||||
static inline struct bpos lru_pos(u16 lru_id, u64 dev_bucket, u64 time)
|
||||
{
|
||||
struct bpos pos = POS(((u64) lru_id << LRU_TIME_BITS)|time, dev_bucket);
|
||||
|
||||
EBUG_ON(time > LRU_TIME_MAX);
|
||||
EBUG_ON(lru_pos_id(pos) != lru_id);
|
||||
EBUG_ON(lru_pos_time(pos) != time);
|
||||
EBUG_ON(pos.offset != dev_bucket);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
#define BCH_LRU_TYPES() \
|
||||
x(read) \
|
||||
x(fragmentation)
|
||||
|
Loading…
Reference in New Issue
Block a user