Commit a50ed7c8 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: BCH_SB_RESERVE_BYTES

Add an option, gc_reserve_bytes, to set the copygc reserve as a size
instead of a percent
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a9bec520
...@@ -1711,7 +1711,7 @@ void bch2_alloc_sectors_done(struct bch_fs *c, struct write_point *wp) ...@@ -1711,7 +1711,7 @@ void bch2_alloc_sectors_done(struct bch_fs *c, struct write_point *wp)
void bch2_recalc_capacity(struct bch_fs *c) void bch2_recalc_capacity(struct bch_fs *c)
{ {
struct bch_dev *ca; struct bch_dev *ca;
u64 capacity = 0, reserved_sectors = 0; u64 capacity = 0, reserved_sectors = 0, gc_reserve;
unsigned long ra_pages = 0; unsigned long ra_pages = 0;
unsigned i, j; unsigned i, j;
...@@ -1726,7 +1726,7 @@ void bch2_recalc_capacity(struct bch_fs *c) ...@@ -1726,7 +1726,7 @@ void bch2_recalc_capacity(struct bch_fs *c)
bch2_set_ra_pages(c, ra_pages); bch2_set_ra_pages(c, ra_pages);
for_each_rw_member(ca, c, i) { for_each_rw_member(ca, c, i) {
u64 dev_capacity, dev_reserve = 0; u64 dev_reserve = 0;
/* /*
* We need to reserve buckets (from the number * We need to reserve buckets (from the number
...@@ -1758,25 +1758,21 @@ void bch2_recalc_capacity(struct bch_fs *c) ...@@ -1758,25 +1758,21 @@ void bch2_recalc_capacity(struct bch_fs *c)
dev_reserve *= ca->mi.bucket_size; dev_reserve *= ca->mi.bucket_size;
dev_reserve *= 2; ca->copygc_threshold = dev_reserve;
dev_capacity = bucket_to_sector(ca, ca->mi.nbuckets - capacity += bucket_to_sector(ca, ca->mi.nbuckets -
ca->mi.first_bucket); ca->mi.first_bucket);
ca->copygc_threshold = reserved_sectors += dev_reserve * 2;
max(div64_u64(dev_capacity *
c->opts.gc_reserve_percent, 100),
dev_reserve) / 2;
capacity += dev_capacity;
reserved_sectors += dev_reserve;
} }
reserved_sectors = max(div64_u64(capacity * gc_reserve = c->opts.gc_reserve_bytes
c->opts.gc_reserve_percent, 100), ? c->opts.gc_reserve_bytes >> 9
reserved_sectors); : div64_u64(capacity * c->opts.gc_reserve_percent, 100);
reserved_sectors = max(gc_reserve, reserved_sectors);
BUG_ON(reserved_sectors > capacity); reserved_sectors = min(reserved_sectors, capacity);
c->capacity = capacity - reserved_sectors; c->capacity = capacity - reserved_sectors;
......
...@@ -1221,6 +1221,7 @@ LE64_BITMASK(BCH_SB_BACKGROUND_TARGET, struct bch_sb, flags[1], 52, 64); ...@@ -1221,6 +1221,7 @@ LE64_BITMASK(BCH_SB_BACKGROUND_TARGET, struct bch_sb, flags[1], 52, 64);
LE64_BITMASK(BCH_SB_BACKGROUND_COMPRESSION_TYPE, LE64_BITMASK(BCH_SB_BACKGROUND_COMPRESSION_TYPE,
struct bch_sb, flags[2], 0, 4); struct bch_sb, flags[2], 0, 4);
LE64_BITMASK(BCH_SB_GC_RESERVE_BYTES, struct bch_sb, flags[2], 4, 64);
/* Features: */ /* Features: */
enum bch_sb_features { enum bch_sb_features {
......
...@@ -114,9 +114,12 @@ enum opt_type { ...@@ -114,9 +114,12 @@ enum opt_type {
BCH_OPT(inodes_32bit, u8, OPT_RUNTIME, \ BCH_OPT(inodes_32bit, u8, OPT_RUNTIME, \
OPT_BOOL(), \ OPT_BOOL(), \
BCH_SB_INODE_32BIT, false) \ BCH_SB_INODE_32BIT, false) \
BCH_OPT(gc_reserve_percent, u8, OPT_MOUNT, \ BCH_OPT(gc_reserve_percent, u8, OPT_RUNTIME, \
OPT_UINT(5, 21), \ OPT_UINT(5, 21), \
BCH_SB_GC_RESERVE, 8) \ BCH_SB_GC_RESERVE, 8) \
BCH_OPT(gc_reserve_bytes, u64, OPT_RUNTIME, \
OPT_UINT(0, U64_MAX), \
BCH_SB_GC_RESERVE_BYTES, 0) \
BCH_OPT(root_reserve_percent, u8, OPT_MOUNT, \ BCH_OPT(root_reserve_percent, u8, OPT_MOUNT, \
OPT_UINT(0, 100), \ OPT_UINT(0, 100), \
BCH_SB_ROOT_RESERVE, 0) \ BCH_SB_ROOT_RESERVE, 0) \
......
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