mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-03-10 00:00:04 +03:00
minimum number of buckets now 1024
This commit is contained in:
parent
cdd61de630
commit
97de91cb58
51
libbcache.c
51
libbcache.c
@ -17,6 +17,11 @@
|
|||||||
#include "libbcache.h"
|
#include "libbcache.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
#define BCH_MIN_NR_NBUCKETS (1 << 10)
|
||||||
|
|
||||||
|
/* first bucket should start 1 mb in, in sectors: */
|
||||||
|
#define FIRST_BUCKET_OFFSET (1 << 11)
|
||||||
|
|
||||||
void __do_write_sb(int fd, void *sb, size_t bytes)
|
void __do_write_sb(int fd, void *sb, size_t bytes)
|
||||||
{
|
{
|
||||||
char zeroes[SB_SECTOR << 9] = {0};
|
char zeroes[SB_SECTOR << 9] = {0};
|
||||||
@ -67,24 +72,46 @@ void bcache_format(struct dev_opts *devs, size_t nr_devs,
|
|||||||
i->size = get_size(i->path, i->fd);
|
i->size = get_size(i->path, i->fd);
|
||||||
|
|
||||||
if (!i->bucket_size) {
|
if (!i->bucket_size) {
|
||||||
u64 bytes = i->size << 9;
|
/*
|
||||||
|
* minimum size filesystem we can create, given a bucket
|
||||||
|
* size:
|
||||||
|
*/
|
||||||
|
u64 min_size(unsigned bucket_size) {
|
||||||
|
return (DIV_ROUND_UP(FIRST_BUCKET_OFFSET, bucket_size) +
|
||||||
|
BCH_MIN_NR_NBUCKETS) * bucket_size;
|
||||||
|
}
|
||||||
|
|
||||||
if (bytes < 1 << 20) /* 1M device - 256 4k buckets*/
|
if (i->size < min_size(block_size))
|
||||||
i->bucket_size = rounddown_pow_of_two(bytes >> 17);
|
die("cannot format %s, too small (%llu sectors, min %llu)",
|
||||||
else
|
i->path, i->size, min_size(block_size));
|
||||||
/* Max 1M bucket at around 256G */
|
|
||||||
i->bucket_size = 8 << min((ilog2(bytes >> 20) / 2), 9U);
|
/* Want a bucket size of at least 128k, if possible: */
|
||||||
|
i->bucket_size = max(block_size, 256U);
|
||||||
|
|
||||||
|
if (i->size >= min_size(i->bucket_size)) {
|
||||||
|
unsigned scale = max(1U,
|
||||||
|
ilog2(i->size / min_size(i->bucket_size)) / 4);
|
||||||
|
|
||||||
|
/* max bucket size 1 mb */
|
||||||
|
i->bucket_size = min(i->bucket_size * scale, 1U << 11);
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
i->bucket_size /= 2;
|
||||||
|
} while (i->size < min_size(i->bucket_size));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* first bucket: 1 mb in */
|
||||||
|
i->first_bucket = DIV_ROUND_UP(FIRST_BUCKET_OFFSET, i->bucket_size);
|
||||||
|
i->nbuckets = i->size / i->bucket_size;
|
||||||
|
|
||||||
if (i->bucket_size < block_size)
|
if (i->bucket_size < block_size)
|
||||||
die("Bucket size cannot be smaller than block size");
|
die("Bucket size cannot be smaller than block size");
|
||||||
|
|
||||||
i->nbuckets = i->size / i->bucket_size;
|
if (i->nbuckets - i->first_bucket < BCH_MIN_NR_NBUCKETS)
|
||||||
i->first_bucket = (23 / i->bucket_size) + 3;
|
die("Not enough buckets: %llu, need %u (bucket size %u)",
|
||||||
|
i->nbuckets - i->first_bucket, BCH_MIN_NR_NBUCKETS,
|
||||||
if (i->nbuckets < 1 << 7)
|
i->bucket_size);
|
||||||
die("Not enough buckets: %llu, need %u",
|
|
||||||
i->nbuckets, 1 << 7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate btree node size: */
|
/* calculate btree node size: */
|
||||||
|
2
util.h
2
util.h
@ -20,6 +20,8 @@ typedef __s16 s16;
|
|||||||
typedef __s32 s32;
|
typedef __s32 s32;
|
||||||
typedef __s64 s64;
|
typedef __s64 s64;
|
||||||
|
|
||||||
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
||||||
|
|
||||||
#define min(x, y) ({ \
|
#define min(x, y) ({ \
|
||||||
typeof(x) _min1 = (x); \
|
typeof(x) _min1 = (x); \
|
||||||
typeof(y) _min2 = (y); \
|
typeof(y) _min2 = (y); \
|
||||||
|
Loading…
Reference in New Issue
Block a user