summaryrefslogtreecommitdiff
path: root/drivers/md/bcache/btree_cache.h
blob: e3950bf4cfb3a38d8c907a2ec60d27f8ce56c7ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _BCACHE_BTREE_CACHE_H
#define _BCACHE_BTREE_CACHE_H

#include "bcache.h"
#include "btree_types.h"

struct btree_iter;

extern const char *bch_btree_id_names[BTREE_ID_NR];

void bch_recalc_btree_reserve(struct cache_set *);

void mca_hash_remove(struct cache_set *, struct btree *);
int mca_hash_insert(struct cache_set *, struct btree *,
		    unsigned, enum btree_id);

void mca_cannibalize_unlock(struct cache_set *);
int mca_cannibalize_lock(struct cache_set *, struct closure *);

struct btree *mca_alloc(struct cache_set *, struct closure *);

struct btree *bch_btree_node_get(struct btree_iter *,
				 const struct bkey_i *, unsigned,
				 struct closure *);

void bch_btree_cache_free(struct cache_set *);
int bch_btree_cache_alloc(struct cache_set *);

#define for_each_cached_btree(_b, _c, _tbl, _iter, _pos)		\
	for ((_tbl) = rht_dereference_rcu((_c)->btree_cache_table.tbl,	\
					  &(_c)->btree_cache_table),	\
	     _iter = 0;	_iter < (_tbl)->size; _iter++)			\
		rht_for_each_entry_rcu((_b), (_pos), _tbl, _iter, hash)

static inline size_t btree_bytes(struct cache_set *c)
{
	return c->sb.btree_node_size << 9;
}

static inline size_t btree_pages(struct cache_set *c)
{
	return c->sb.btree_node_size >> (PAGE_SHIFT - 9);
}

static inline unsigned btree_blocks(struct cache_set *c)
{
	return c->sb.btree_node_size >> c->block_bits;
}

#define btree_node_root(_b)	((_b)->c->btree_roots[(_b)->btree_id].b)

#endif /* _BCACHE_BTREE_CACHE_H */