Skip to content

Commit 2fb98e4

Browse files
bjohnstoMikulas Patocka
authored andcommitted
dm vdo: add formatting parameters to table line
Extend the dm table line with three new optional parameters: indexMemory (UDS index memory size), indexSparse (dense vs sparse index), and slabSize (blocks per allocation slab). These values are parsed, validated, and stored in the device configuration for use during formatting. Rework the slab size constants from the single MAX_VDO_SLAB_BITS into explicit MIN_VDO_SLAB_BLOCKS, MAX_VDO_SLAB_BLOCKS, and DEFAULT_VDO_SLAB_BLOCKS values. Bump the target version from 9.1.0 to 9.2.0 to reflect this table line change. Signed-off-by: Bruce Johnston <bjohnsto@redhat.com> Reviewed-by: Matthew Sakai <msakai@redhat.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent e073bb0 commit 2fb98e4

5 files changed

Lines changed: 111 additions & 17 deletions

File tree

drivers/md/dm-vdo/constants.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ enum {
6060
/* The maximum number of physical zones */
6161
MAX_VDO_PHYSICAL_ZONES = 16,
6262

63-
/* The base-2 logarithm of the maximum blocks in one slab */
64-
MAX_VDO_SLAB_BITS = 23,
63+
/* The default blocks in one slab */
64+
DEFAULT_VDO_SLAB_BLOCKS = 1U << 19,
65+
66+
/* The minimum blocks in one slab */
67+
MIN_VDO_SLAB_BLOCKS = 1U << 13,
68+
69+
/* The maximum blocks in one slab */
70+
MAX_VDO_SLAB_BLOCKS = 1U << 23,
6571

6672
/* The maximum number of slabs the slab depot supports */
6773
MAX_VDO_SLABS = 8192,

drivers/md/dm-vdo/dm-vdo-target.c

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/delay.h>
1010
#include <linux/device-mapper.h>
1111
#include <linux/err.h>
12+
#include <linux/log2.h>
1213
#include <linux/module.h>
1314
#include <linux/mutex.h>
1415
#include <linux/spinlock.h>
@@ -377,6 +378,75 @@ static inline int __must_check parse_bool(const char *bool_str, const char *true
377378
return VDO_SUCCESS;
378379
}
379380

381+
/**
382+
* parse_memory() - Parse a string into an index memory value.
383+
* @memory_str: The string value to convert to a memory value.
384+
* @memory_ptr: A pointer to return the memory value in.
385+
*
386+
* Return: VDO_SUCCESS or an error
387+
*/
388+
static int __must_check parse_memory(const char *memory_str,
389+
uds_memory_config_size_t *memory_ptr)
390+
{
391+
uds_memory_config_size_t memory;
392+
393+
if (strcmp(memory_str, "0.25") == 0) {
394+
memory = UDS_MEMORY_CONFIG_256MB;
395+
} else if ((strcmp(memory_str, "0.5") == 0) || (strcmp(memory_str, "0.50") == 0)) {
396+
memory = UDS_MEMORY_CONFIG_512MB;
397+
} else if (strcmp(memory_str, "0.75") == 0) {
398+
memory = UDS_MEMORY_CONFIG_768MB;
399+
} else {
400+
unsigned int value;
401+
int result;
402+
403+
result = kstrtouint(memory_str, 10, &value);
404+
if (result) {
405+
vdo_log_error("optional parameter error: invalid memory size, must be a postive integer");
406+
return -EINVAL;
407+
}
408+
409+
if (value > UDS_MEMORY_CONFIG_MAX) {
410+
vdo_log_error("optional parameter error: invalid memory size, must not be greater than %d",
411+
UDS_MEMORY_CONFIG_MAX);
412+
return -EINVAL;
413+
}
414+
415+
memory = value;
416+
}
417+
418+
*memory_ptr = memory;
419+
return VDO_SUCCESS;
420+
}
421+
422+
/**
423+
* parse_slab_size() - Parse a string option into a slab size value.
424+
* @slab_str: The string value representing slab size.
425+
* @slab_size_ptr: A pointer to return the slab size in.
426+
*
427+
* Return: VDO_SUCCESS or an error
428+
*/
429+
static int __must_check parse_slab_size(const char *slab_str, block_count_t *slab_size_ptr)
430+
{
431+
block_count_t value;
432+
int result;
433+
434+
result = kstrtoull(slab_str, 10, &value);
435+
if (result) {
436+
vdo_log_error("optional parameter error: invalid slab size, must be a postive integer");
437+
return -EINVAL;
438+
}
439+
440+
if (value < MIN_VDO_SLAB_BLOCKS || value > MAX_VDO_SLAB_BLOCKS || (!is_power_of_2(value))) {
441+
vdo_log_error("optional parameter error: invalid slab size, must be a power of two between %u and %u",
442+
MIN_VDO_SLAB_BLOCKS, MAX_VDO_SLAB_BLOCKS);
443+
return -EINVAL;
444+
}
445+
446+
*slab_size_ptr = value;
447+
return VDO_SUCCESS;
448+
}
449+
380450
/**
381451
* process_one_thread_config_spec() - Process one component of a thread parameter configuration
382452
* string and update the configuration data structure.
@@ -566,7 +636,7 @@ static int process_one_key_value_pair(const char *key, unsigned int value,
566636
}
567637
/* Max discard sectors in blkdev_issue_discard is UINT_MAX >> 9 */
568638
if (value > (UINT_MAX / VDO_BLOCK_SIZE)) {
569-
vdo_log_error("optional parameter error: at most %d max discard blocks are allowed",
639+
vdo_log_error("optional parameter error: at most %d max discard blocks are allowed",
570640
UINT_MAX / VDO_BLOCK_SIZE);
571641
return -EINVAL;
572642
}
@@ -598,7 +668,16 @@ static int parse_one_key_value_pair(const char *key, const char *value,
598668
if (strcmp(key, "compression") == 0)
599669
return parse_bool(value, "on", "off", &config->compression);
600670

601-
/* The remaining arguments must have integral values. */
671+
if (strcmp(key, "indexSparse") == 0)
672+
return parse_bool(value, "on", "off", &config->index_sparse);
673+
674+
if (strcmp(key, "indexMemory") == 0)
675+
return parse_memory(value, &config->index_memory);
676+
677+
if (strcmp(key, "slabSize") == 0)
678+
return parse_slab_size(value, &config->slab_blocks);
679+
680+
/* The remaining arguments must have non-negative integral values. */
602681
result = kstrtouint(value, 10, &count);
603682
if (result) {
604683
vdo_log_error("optional config string error: integer value needed, found \"%s\"",
@@ -756,6 +835,9 @@ static int parse_device_config(int argc, char **argv, struct dm_target *ti,
756835
config->max_discard_blocks = 1;
757836
config->deduplication = true;
758837
config->compression = false;
838+
config->index_memory = UDS_MEMORY_CONFIG_256MB;
839+
config->index_sparse = false;
840+
config->slab_blocks = DEFAULT_VDO_SLAB_BLOCKS;
759841

760842
arg_set.argc = argc;
761843
arg_set.argv = argv;
@@ -781,7 +863,7 @@ static int parse_device_config(int argc, char **argv, struct dm_target *ti,
781863
/* Get the physical blocks, if known. */
782864
if (config->version >= 1) {
783865
result = kstrtoull(dm_shift_arg(&arg_set), 10, &config->physical_blocks);
784-
if (result != VDO_SUCCESS) {
866+
if (result) {
785867
handle_parse_error(config, error_ptr,
786868
"Invalid physical block count");
787869
return VDO_BAD_CONFIGURATION;
@@ -802,15 +884,15 @@ static int parse_device_config(int argc, char **argv, struct dm_target *ti,
802884

803885
/* Get the page cache size. */
804886
result = kstrtouint(dm_shift_arg(&arg_set), 10, &config->cache_size);
805-
if (result != VDO_SUCCESS) {
887+
if (result) {
806888
handle_parse_error(config, error_ptr,
807889
"Invalid block map page cache size");
808890
return VDO_BAD_CONFIGURATION;
809891
}
810892

811893
/* Get the block map era length. */
812894
result = kstrtouint(dm_shift_arg(&arg_set), 10, &config->block_map_maximum_age);
813-
if (result != VDO_SUCCESS) {
895+
if (result) {
814896
handle_parse_error(config, error_ptr, "Invalid block map maximum age");
815897
return VDO_BAD_CONFIGURATION;
816898
}
@@ -1457,10 +1539,13 @@ static int vdo_initialize(struct dm_target *ti, unsigned int instance,
14571539
vdo_log_debug("Logical blocks = %llu", logical_blocks);
14581540
vdo_log_debug("Physical block size = %llu", (u64) block_size);
14591541
vdo_log_debug("Physical blocks = %llu", config->physical_blocks);
1542+
vdo_log_debug("Slab size = %llu", config->slab_blocks);
14601543
vdo_log_debug("Block map cache blocks = %u", config->cache_size);
14611544
vdo_log_debug("Block map maximum age = %u", config->block_map_maximum_age);
14621545
vdo_log_debug("Deduplication = %s", (config->deduplication ? "on" : "off"));
14631546
vdo_log_debug("Compression = %s", (config->compression ? "on" : "off"));
1547+
vdo_log_debug("Index memory = %u", config->index_memory);
1548+
vdo_log_debug("Index sparse = %s", (config->index_sparse ? "on" : "off"));
14641549

14651550
vdo = vdo_find_matching(vdo_uses_device, config);
14661551
if (vdo != NULL) {
@@ -2856,7 +2941,7 @@ static void vdo_resume(struct dm_target *ti)
28562941
static struct target_type vdo_target_bio = {
28572942
.features = DM_TARGET_SINGLETON,
28582943
.name = "vdo",
2859-
.version = { 9, 1, 0 },
2944+
.version = { 9, 2, 0 },
28602945
.module = THIS_MODULE,
28612946
.ctr = vdo_ctr,
28622947
.dtr = vdo_dtr,

drivers/md/dm-vdo/encodings.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
#include "status-codes.h"
1717
#include "types.h"
1818

19-
/** The maximum logical space is 4 petabytes, which is 1 terablock. */
20-
static const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS = 1024ULL * 1024 * 1024 * 1024;
21-
22-
/** The maximum physical space is 256 terabytes, which is 64 gigablocks. */
23-
static const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS = 1024ULL * 1024 * 1024 * 64;
24-
2519
struct geometry_block {
2620
char magic_number[VDO_GEOMETRY_MAGIC_NUMBER_SIZE];
2721
struct packed_header header;
@@ -1220,9 +1214,9 @@ int vdo_validate_config(const struct vdo_config *config,
12201214
if (result != VDO_SUCCESS)
12211215
return result;
12221216

1223-
result = VDO_ASSERT(config->slab_size <= (1 << MAX_VDO_SLAB_BITS),
1224-
"slab size must be less than or equal to 2^%d",
1225-
MAX_VDO_SLAB_BITS);
1217+
result = VDO_ASSERT(config->slab_size <= MAX_VDO_SLAB_BLOCKS,
1218+
"slab size must be a power of two less than or equal to %d",
1219+
MAX_VDO_SLAB_BLOCKS);
12261220
if (result != VDO_SUCCESS)
12271221
return result;
12281222

drivers/md/dm-vdo/encodings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ struct vdo_config {
608608
block_count_t slab_journal_blocks; /* number of slab journal blocks */
609609
};
610610

611+
/** The maximum logical space is 4 petabytes, which is 1 terablock. */
612+
#define MAXIMUM_VDO_LOGICAL_BLOCKS ((block_count_t)(1024ULL * 1024 * 1024 * 1024))
613+
614+
/** The maximum physical space is 256 terabytes, which is 64 gigablocks. */
615+
#define MAXIMUM_VDO_PHYSICAL_BLOCKS ((block_count_t)(1024ULL * 1024 * 1024 * 64))
616+
611617
/* This is the structure that captures the vdo fields saved as a super block component. */
612618
struct vdo_component {
613619
enum vdo_state state;

drivers/md/dm-vdo/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ struct device_config {
227227
bool compression;
228228
struct thread_count_config thread_counts;
229229
block_count_t max_discard_blocks;
230+
block_count_t slab_blocks;
231+
int index_memory;
232+
bool index_sparse;
230233
};
231234

232235
enum vdo_completion_type {

0 commit comments

Comments
 (0)