Commit ec4edd7b authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Prep work for variable size btree node buffers



bcachefs btree nodes are big - typically 256k - and btree roots are
pinned in memory. As we're now up to 18 btrees, we now have significant
memory overhead in mostly empty btree roots.

And in the future we're going to start enforcing that certain btree node
boundaries exist, to solve lock contention issues - analagous to XFS's
AGIs.

Thus, we need to start allocating smaller btree node buffers when we
can. This patch changes code that refers to the filesystem constant
c->opts.btree_node_size to refer to the btree node buffer size -
btree_buf_bytes() - where appropriate.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 2acc59dd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ static size_t btree_nodes_fit_in_ram(struct bch_fs *c)

	si_meminfo(&i);
	mem_bytes = i.totalram * i.mem_unit;
	return div_u64(mem_bytes >> 1, btree_bytes(c));
	return div_u64(mem_bytes >> 1, c->opts.btree_node_size);
}

static int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#ifndef _BCACHEFS_BACKPOINTERS_BACKGROUND_H
#define _BCACHEFS_BACKPOINTERS_BACKGROUND_H

#include "btree_cache.h"
#include "btree_iter.h"
#include "btree_update.h"
#include "buckets.h"
+0 −5
Original line number Diff line number Diff line
@@ -1204,11 +1204,6 @@ static inline unsigned block_sectors(const struct bch_fs *c)
	return c->opts.block_size >> 9;
}

static inline size_t btree_sectors(const struct bch_fs *c)
{
	return c->opts.btree_node_size >> 9;
}

static inline bool btree_id_cached(const struct bch_fs *c, enum btree_id btree)
{
	return c->btree_key_cache_btrees & (1U << btree);
+2 −3
Original line number Diff line number Diff line
@@ -823,13 +823,12 @@ void bch2_bset_init_first(struct btree *b, struct bset *i)
	set_btree_bset(b, t, i);
}

void bch2_bset_init_next(struct bch_fs *c, struct btree *b,
			 struct btree_node_entry *bne)
void bch2_bset_init_next(struct btree *b, struct btree_node_entry *bne)
{
	struct bset *i = &bne->keys;
	struct bset_tree *t;

	BUG_ON(bset_byte_offset(b, bne) >= btree_bytes(c));
	BUG_ON(bset_byte_offset(b, bne) >= btree_buf_bytes(b));
	BUG_ON((void *) bne < (void *) btree_bkey_last(b, bset_tree_last(b)));
	BUG_ON(b->nsets >= MAX_BSETS);

+1 −2
Original line number Diff line number Diff line
@@ -264,8 +264,7 @@ static inline struct bset *bset_next_set(struct btree *b,
void bch2_btree_keys_init(struct btree *);

void bch2_bset_init_first(struct btree *, struct bset *);
void bch2_bset_init_next(struct bch_fs *, struct btree *,
			 struct btree_node_entry *);
void bch2_bset_init_next(struct btree *, struct btree_node_entry *);
void bch2_bset_build_aux_tree(struct btree *, struct bset_tree *, bool);

void bch2_bset_insert(struct btree *, struct btree_node_iter *,
Loading