Commit 8e992c6c authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_btree_bit_mod()

New helper for bitset btrees.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4dc5bb9a
...@@ -72,6 +72,8 @@ int bch2_btree_delete_range_trans(struct btree_trans *, enum btree_id, ...@@ -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, int bch2_btree_delete_range(struct bch_fs *, enum btree_id,
struct bpos, struct bpos, unsigned, u64 *); 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 *, int bch2_btree_node_rewrite(struct btree_trans *, struct btree_iter *,
struct btree *, unsigned); struct btree *, unsigned);
void bch2_btree_node_rewrite_async(struct bch_fs *, struct btree *); 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, ...@@ -1996,6 +1996,24 @@ int bch2_btree_delete_range(struct bch_fs *c, enum btree_id id,
return ret; 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) static int __bch2_trans_log_msg(darray_u64 *entries, const char *fmt, va_list args)
{ {
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
......
...@@ -41,28 +41,12 @@ void bch2_lru_pos_to_text(struct printbuf *out, struct bpos lru) ...@@ -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, 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; return time
int ret = 0; ? bch2_btree_bit_mod(trans, BTREE_ID_lru,
lru_pos(lru_id, dev_bucket, time), set)
if (!time) : 0;
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);
} }
int bch2_lru_del(struct btree_trans *trans, u16 lru_id, u64 dev_bucket, u64 time) int bch2_lru_del(struct btree_trans *trans, u16 lru_id, u64 dev_bucket, u64 time)
......
...@@ -5,13 +5,6 @@ ...@@ -5,13 +5,6 @@
#define LRU_TIME_BITS 48 #define LRU_TIME_BITS 48
#define LRU_TIME_MAX ((1ULL << LRU_TIME_BITS) - 1) #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) static inline u64 lru_pos_id(struct bpos pos)
{ {
return pos.inode >> LRU_TIME_BITS; return pos.inode >> LRU_TIME_BITS;
...@@ -22,6 +15,18 @@ static inline u64 lru_pos_time(struct bpos pos) ...@@ -22,6 +15,18 @@ static inline u64 lru_pos_time(struct bpos pos)
return pos.inode & ~(~0ULL << LRU_TIME_BITS); 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() \ #define BCH_LRU_TYPES() \
x(read) \ x(read) \
x(fragmentation) x(fragmentation)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment