From 78dd9d820da44c6b9907b481231745590e94613d Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 28 Jan 2019 19:50:41 +0100 Subject: [PATCH] thin: select chunk size as power of 2 Whenever thin-pool chunk size is unspecified and left for lvm calculation try to select the size as nearest highest power-of-2 instead of just being a multiple of 64KiB. --- WHATS_NEW | 1 + lib/metadata/thin_manip.c | 17 +++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 90739c9cc..29ade9935 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.03.02 - =================================== + Thin-pool selects power-of-2 chunk size by default. Cache selects power-of-2 chunk size by default. Support reszing for VDOPoolLV and VDOLV. Improve -lXXX%VG modifier which improves cache segment estimation. diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c index 6b2b1e794..e1b317953 100644 --- a/lib/metadata/thin_manip.c +++ b/lib/metadata/thin_manip.c @@ -580,20 +580,9 @@ static uint32_t _estimate_chunk_size(uint32_t data_extents, uint32_t extent_size { uint32_t chunk_size = _estimate_size(data_extents, extent_size, metadata_size); - if (attr & THIN_FEATURE_BLOCK_SIZE) { - /* Round up to 64KB */ - chunk_size += DM_THIN_MIN_DATA_BLOCK_SIZE - 1; - chunk_size &= ~(uint32_t)(DM_THIN_MIN_DATA_BLOCK_SIZE - 1); - } else { - /* Round up to nearest power of 2 */ - chunk_size--; - chunk_size |= chunk_size >> 1; - chunk_size |= chunk_size >> 2; - chunk_size |= chunk_size >> 4; - chunk_size |= chunk_size >> 8; - chunk_size |= chunk_size >> 16; - chunk_size++; - } + /* Always round up to nearest power of 2 of 32-bit, + * even when pool supports multiple of 64KiB */ + chunk_size = 1 << (32 - clz(chunk_size - 1)); if (chunk_size < DM_THIN_MIN_DATA_BLOCK_SIZE) chunk_size = DM_THIN_MIN_DATA_BLOCK_SIZE;