diff options
author | Jacob Malevich <jam@daterainc.com> | 2014-10-13 15:21:09 -0700 |
---|---|---|
committer | Jacob Malevich <jam@daterainc.com> | 2014-10-27 12:14:38 -0700 |
commit | ee44c4f509667aa1bce20b44dcd459b1bc3eea99 (patch) | |
tree | 21e27c3d2bd2d5e74dd22954782b0ba4b9174247 | |
parent | e8c1cee578e3911ea95c3f063234f7bf271b17dd (diff) |
set btree_node_size for the cache_sb based on bucket_size
Change-Id: I98dab6e9a221cd8781095039d653ace84ffae806
Signed-off-by: Jacob Malevich <jam@daterainc.com>
-rw-r--r-- | bcache.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -530,12 +530,34 @@ int dev_open(const char *dev, bool wipe_bcache) return fd; } +static unsigned min_bucket_size(int num_bucket_sizes, unsigned *bucket_sizes) +{ + int i; + unsigned min = bucket_sizes[0]; + + for (i = 0; i < num_bucket_sizes; i++) + min = bucket_sizes[i] < min ? bucket_sizes[i] : min; + + return min; +} + +static unsigned node_size(unsigned bucket_size) { + + if (bucket_size <= 256) + return bucket_size; + else if (bucket_size <= 512) + return bucket_size / 2; + else + return bucket_size / 4; +} + void write_cache_sbs(int *fds, struct cache_sb *sb, unsigned block_size, unsigned *bucket_sizes, int num_bucket_sizes) { char uuid_str[40], set_uuid_str[40]; size_t i; + unsigned min_size = min_bucket_size(num_bucket_sizes, bucket_sizes); sb->offset = SB_SECTOR; sb->version = BCACHE_SB_VERSION_CDEV_V3; @@ -552,11 +574,13 @@ void write_cache_sbs(int *fds, struct cache_sb *sb, for (i = 0; i < sb->nr_in_set; i++) { struct cache_member *m = sb->members + i; - sb->uuid = m->uuid; - if(num_bucket_sizes <= 1) + if (num_bucket_sizes <= 1) sb->bucket_size = bucket_sizes[0]; else sb->bucket_size = bucket_sizes[i]; + SET_CACHE_BTREE_NODE_SIZE(sb, node_size(min_size)); + + sb->uuid = m->uuid; sb->nbuckets = getblocks(fds[i]) / sb->bucket_size; sb->nr_this_dev = i; sb->first_bucket = (23 / sb->bucket_size) + 1; |