mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-24 17:57:48 +03:00
cache: use same alg for cache size calc
Use the same algorithm for cache metadata size as the cache tool is using.
This commit is contained in:
parent
d46c2f1c94
commit
f76f2ce1df
@ -22,6 +22,12 @@
|
||||
#include "activate.h"
|
||||
#include "defaults.h"
|
||||
|
||||
/* https://github.com/jthornber/thin-provisioning-tools/blob/master/caching/cache_metadata_size.cc */
|
||||
#define DM_TRANSACTION_OVERHEAD 4096 /* KiB */
|
||||
#define DM_BYTES_PER_BLOCK 16 /* bytes */
|
||||
#define DM_HINT_OVERHEAD_PER_BLOCK 8 /* bytes */
|
||||
#define DM_MAX_HINT_WIDTH (4+16) /* bytes, TODO: configurable ?? */
|
||||
|
||||
const char *get_cachepool_cachemode_name(const struct lv_segment *seg)
|
||||
{
|
||||
if (seg->feature_flags & DM_CACHE_FEATURE_WRITEBACK)
|
||||
@ -39,6 +45,7 @@ int update_cache_pool_params(struct volume_group *vg, unsigned attr,
|
||||
int *chunk_size_calc_method, uint32_t *chunk_size)
|
||||
{
|
||||
uint64_t min_meta_size;
|
||||
uint32_t extent_size = vg->extent_size;
|
||||
|
||||
if (!(passed_args & PASS_ARG_CHUNK_SIZE))
|
||||
*chunk_size = DEFAULT_CACHE_POOL_CHUNK_SIZE * 2;
|
||||
@ -59,15 +66,16 @@ int update_cache_pool_params(struct volume_group *vg, unsigned attr,
|
||||
|
||||
/*
|
||||
* Default meta size is:
|
||||
* (4MiB + (16 Bytes for each chunk-sized block))
|
||||
* ... plus a good amount of padding (2x) to cover any
|
||||
* policy hint data that may be added in the future.
|
||||
* (Overhead + mapping size + hint size)
|
||||
*/
|
||||
min_meta_size = (uint64_t)data_extents * vg->extent_size * 16;
|
||||
min_meta_size /= *chunk_size; /* # of Bytes we need */
|
||||
min_meta_size *= 2; /* plus some padding */
|
||||
min_meta_size /= 512; /* in sectors */
|
||||
min_meta_size += 4*1024*2; /* plus 4MiB */
|
||||
min_meta_size = (uint64_t) data_extents * extent_size / *chunk_size; /* nr_chunks */
|
||||
min_meta_size *= (DM_BYTES_PER_BLOCK + DM_MAX_HINT_WIDTH + DM_HINT_OVERHEAD_PER_BLOCK);
|
||||
min_meta_size = (min_meta_size + (SECTOR_SIZE - 1)) >> SECTOR_SHIFT; /* in sectors */
|
||||
min_meta_size += DM_TRANSACTION_OVERHEAD * (1024 >> SECTOR_SHIFT);
|
||||
|
||||
/* Round up to extent size */
|
||||
if (min_meta_size % extent_size)
|
||||
min_meta_size += extent_size - min_meta_size % extent_size;
|
||||
|
||||
if (!*pool_metadata_size)
|
||||
*pool_metadata_size = min_meta_size;
|
||||
@ -79,7 +87,7 @@ int update_cache_pool_params(struct volume_group *vg, unsigned attr,
|
||||
display_size(vg->cmd, *pool_metadata_size));
|
||||
} else if (*pool_metadata_size < min_meta_size) {
|
||||
if (passed_args & PASS_ARG_POOL_METADATA_SIZE)
|
||||
log_warn("WARNING: Minimum supported pool metadata size is %s "
|
||||
log_warn("WARNING: Minimum required pool metadata size is %s "
|
||||
"(needs extra %s).",
|
||||
display_size(vg->cmd, min_meta_size),
|
||||
display_size(vg->cmd, min_meta_size - *pool_metadata_size));
|
||||
|
Loading…
x
Reference in New Issue
Block a user