mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_184-config-add-new-setting-io_memory_size.patch

f8f52d
 lib/commands/toolcontext.c   |  2 ++
f8f52d
 lib/config/config_settings.h |  8 ++++++++
f8f52d
 lib/config/defaults.h        |  2 ++
f8f52d
 lib/label/label.c            | 40 ++++++++++++++++++++--------------------
f8f52d
 lib/misc/lvm-globals.c       | 10 ++++++++++
f8f52d
 lib/misc/lvm-globals.h       |  3 +++
f8f52d
 6 files changed, 45 insertions(+), 20 deletions(-)
f8f52d
f8f52d
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
f8f52d
index 4d3f744..95b2317 100644
f8f52d
--- a/lib/commands/toolcontext.c
f8f52d
+++ b/lib/commands/toolcontext.c
f8f52d
@@ -693,6 +693,8 @@ static int _process_config(struct cmd_context *cmd)
f8f52d
 	if (!_init_system_id(cmd))
f8f52d
 		return_0;
f8f52d
 
f8f52d
+	init_io_memory_size(find_config_tree_int(cmd, global_io_memory_size_CFG, NULL));
f8f52d
+
f8f52d
 	return 1;
f8f52d
 }
f8f52d
 
f8f52d
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
f8f52d
index 2de3fd4..c3e9600 100644
f8f52d
--- a/lib/config/config_settings.h
f8f52d
+++ b/lib/config/config_settings.h
f8f52d
@@ -1138,6 +1138,14 @@ cfg(global_notify_dbus_CFG, "notify_dbus", global_CFG_SECTION, 0, CFG_TYPE_BOOL,
f8f52d
 	"When enabled, an LVM command that changes PVs, changes VG metadata,\n"
f8f52d
 	"or changes the activation state of an LV will send a notification.\n")
f8f52d
 
f8f52d
+cfg(global_io_memory_size_CFG, "io_memory_size", global_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_INT, DEFAULT_IO_MEMORY_SIZE_KB, vsn(2, 2, 184), NULL, 0, NULL,
f8f52d
+	"The amount of memory in KiB that LVM allocates to perform disk io.\n"
f8f52d
+	"LVM performance may benefit from more io memory when there are many\n"
f8f52d
+	"disks or VG metadata is large. Increasing this size may be necessary\n"
f8f52d
+	"when a single copy of VG metadata is larger than the current setting.\n"
f8f52d
+	"This value should usually not be decreased from the default; setting\n"
f8f52d
+	"it too low can result in lvm failing to read VGs.\n")
f8f52d
+
f8f52d
 cfg(activation_udev_sync_CFG, "udev_sync", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_UDEV_SYNC, vsn(2, 2, 51), NULL, 0, NULL,
f8f52d
 	"Use udev notifications to synchronize udev and LVM.\n"
f8f52d
 	"The --nodevsync option overrides this setting.\n"
f8f52d
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
f8f52d
index b3e6c34..690bf56 100644
f8f52d
--- a/lib/config/defaults.h
f8f52d
+++ b/lib/config/defaults.h
f8f52d
@@ -267,4 +267,6 @@
f8f52d
 #define DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD 100
f8f52d
 #define DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT 20
f8f52d
 
f8f52d
+#define DEFAULT_IO_MEMORY_SIZE_KB 4096
f8f52d
+
f8f52d
 #endif				/* _LVM_DEFAULTS_H */
f8f52d
diff --git a/lib/label/label.c b/lib/label/label.c
f8f52d
index 03726d0..4ec7d9b 100644
f8f52d
--- a/lib/label/label.c
f8f52d
+++ b/lib/label/label.c
f8f52d
@@ -772,33 +772,33 @@ out:
f8f52d
 }
f8f52d
 
f8f52d
 /*
f8f52d
- * How many blocks to set up in bcache?  Is 1024 a good max?
f8f52d
+ * num_devs is the number of devices the caller is going to scan.
f8f52d
+ * When 0 the caller doesn't know, and we use the default cache size.
f8f52d
+ * When non-zero, allocate at least num_devs bcache blocks.
f8f52d
+ * num_devs doesn't really tell us how many bcache blocks we'll use
f8f52d
+ * because it includes lvm devs and non-lvm devs, and each lvm dev
f8f52d
+ * will often use a number of bcache blocks.
f8f52d
  *
f8f52d
- * Currently, we tell bcache to set up N blocks where N
f8f52d
- * is the number of devices that are going to be scanned.
f8f52d
- * Reasons why this number may not be be a good choice:
f8f52d
- *
f8f52d
- * - there may be a lot of non-lvm devices, which
f8f52d
- *   would make this number larger than necessary
f8f52d
- *
f8f52d
- * - each lvm device may use more than one cache
f8f52d
- *   block if the metadata is large enough or it
f8f52d
- *   uses more than one metadata area, which
f8f52d
- *   would make this number smaller than it
f8f52d
- *   should be for the best performance.
f8f52d
- *
f8f52d
- * This is even more tricky to estimate when lvmetad
f8f52d
- * is used, because it's hard to predict how many
f8f52d
- * devs might need to be scanned when using lvmetad.
f8f52d
- * This currently just sets up bcache with MIN blocks.
f8f52d
+ * We don't know ahead of time if we will find some VG metadata 
f8f52d
+ * that is larger than the total size of the bcache, which would
f8f52d
+ * prevent us from reading/writing the VG since we do not dynamically
f8f52d
+ * increase the bcache size when we find it's too small.  In these
f8f52d
+ * cases the user would need to set io_memory_size to be larger
f8f52d
+ * than the max VG metadata size (lvm does not impose any limit on
f8f52d
+ * the metadata size.)
f8f52d
  */
f8f52d
 
f8f52d
-#define MIN_BCACHE_BLOCKS 32
f8f52d
+#define MIN_BCACHE_BLOCKS 32    /* 4MB, currently matches DEFAULT_IO_MEMORY_SIZE_KB */
f8f52d
 #define MAX_BCACHE_BLOCKS 1024
f8f52d
 
f8f52d
-static int _setup_bcache(int cache_blocks)
f8f52d
+static int _setup_bcache(int num_devs)
f8f52d
 {
f8f52d
 	struct io_engine *ioe = NULL;
f8f52d
+	int iomem_kb = io_memory_size();
f8f52d
+	int block_size_kb = (BCACHE_BLOCK_SIZE_IN_SECTORS * 512) / 1024;
f8f52d
+	int cache_blocks;
f8f52d
+
f8f52d
+	cache_blocks = iomem_kb / block_size_kb;
f8f52d
 
f8f52d
 	if (cache_blocks < MIN_BCACHE_BLOCKS)
f8f52d
 		cache_blocks = MIN_BCACHE_BLOCKS;
f8f52d
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
f8f52d
index 82c5706..3bd5cac 100644
f8f52d
--- a/lib/misc/lvm-globals.c
f8f52d
+++ b/lib/misc/lvm-globals.c
f8f52d
@@ -54,6 +54,7 @@ static char _sysfs_dir_path[PATH_MAX] = "";
f8f52d
 static int _dev_disable_after_error_count = DEFAULT_DISABLE_AFTER_ERROR_COUNT;
f8f52d
 static uint64_t _pv_min_size = (DEFAULT_PV_MIN_SIZE_KB * 1024L >> SECTOR_SHIFT);
f8f52d
 static const char *_unknown_device_name = DEFAULT_UNKNOWN_DEVICE_NAME;
f8f52d
+static int _io_memory_size_kb = DEFAULT_IO_MEMORY_SIZE_KB;
f8f52d
 
f8f52d
 void init_verbose(int level)
f8f52d
 {
f8f52d
@@ -387,3 +388,12 @@ void init_unknown_device_name(const char *name)
f8f52d
 	_unknown_device_name = name;
f8f52d
 }
f8f52d
 
f8f52d
+int io_memory_size(void)
f8f52d
+{
f8f52d
+	return _io_memory_size_kb;
f8f52d
+}
f8f52d
+
f8f52d
+void init_io_memory_size(int val)
f8f52d
+{
f8f52d
+	_io_memory_size_kb = val;
f8f52d
+}
f8f52d
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
f8f52d
index f985cfa..3007cc5 100644
f8f52d
--- a/lib/misc/lvm-globals.h
f8f52d
+++ b/lib/misc/lvm-globals.h
f8f52d
@@ -53,6 +53,7 @@ void init_pv_min_size(uint64_t sectors);
f8f52d
 void init_activation_checks(int checks);
f8f52d
 void init_retry_deactivation(int retry);
f8f52d
 void init_unknown_device_name(const char *name);
f8f52d
+void init_io_memory_size(int val);
f8f52d
 
f8f52d
 void set_cmd_name(const char *cmd_name);
f8f52d
 const char *get_cmd_name(void);
f8f52d
@@ -86,6 +87,7 @@ uint64_t pv_min_size(void);
f8f52d
 int activation_checks(void);
f8f52d
 int retry_deactivation(void);
f8f52d
 const char *unknown_device_name(void);
f8f52d
+int io_memory_size(void);
f8f52d
 
f8f52d
 #define DMEVENTD_MONITOR_IGNORE -1
f8f52d
 int dmeventd_monitor_mode(void);
f8f52d
@@ -93,4 +95,5 @@ int dmeventd_monitor_mode(void);
f8f52d
 #define NO_DEV_ERROR_COUNT_LIMIT 0
f8f52d
 int dev_disable_after_error_count(void);
f8f52d
 
f8f52d
+
f8f52d
 #endif