From 964012fdb924076e9ab97fabe00e759ddbf7c3bd Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 24 Sep 2024 16:04:53 +0200 Subject: [PATCH] memlock: use value of 0 to disable memory locking In cases user is sure he is not using his 'rootfs' or 'swap' on LVs managed with his command - it possible to completely bypass pinning process to RAM which may eventually slightly speedup command execution, (however at the risk the process can be eventually delayed by swapping). Basicaly use this only at your risk... TODO: add some dmeventd support for this. --- lib/config/config_settings.h | 7 +++++-- lib/mm/memlock.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h index 5bc7bf45d..f782c482a 100644 --- a/lib/config/config_settings.h +++ b/lib/config/config_settings.h @@ -1424,11 +1424,14 @@ cfg(activation_use_linear_target_CFG, "use_linear_target", activation_CFG_SECTIO cfg(activation_reserved_stack_CFG, "reserved_stack", activation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_INT, DEFAULT_RESERVED_STACK, vsn(1, 0, 0), NULL, 0, NULL, "Stack size in KiB to reserve for use while devices are suspended.\n" - "Insufficient reserve risks I/O deadlock during device suspension.\n") + "Insufficient reserve risks I/O deadlock during device suspension.\n" + "Value 0 disables memory locking.\n") cfg(activation_reserved_memory_CFG, "reserved_memory", activation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_INT, DEFAULT_RESERVED_MEMORY, vsn(1, 0, 0), NULL, 0, NULL, "Memory size in KiB to reserve for use while devices are suspended.\n" - "Insufficient reserve risks I/O deadlock during device suspension.\n") + "Insufficient reserve risks I/O deadlock during device suspension.\n" + "Value 0 disables memory locking.\n") + cfg(activation_process_priority_CFG, "process_priority", activation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_INT, DEFAULT_PROCESS_PRIORITY, vsn(1, 0, 0), NULL, 0, NULL, "Nice value used while devices are suspended.\n" diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c index a7c227ae7..e28044df6 100644 --- a/lib/mm/memlock.c +++ b/lib/mm/memlock.c @@ -517,6 +517,13 @@ static void _restore_priority_if_possible(struct cmd_context *cmd) /* Stop memory getting swapped out */ static void _lock_mem(struct cmd_context *cmd) { + if (!_size_stack || _size_malloc_tmp) { + log_debug_mem("Skipping memory locking (reserved memory: " + FMTsize_t " stack: " FMTsize_t ").", + _size_malloc_tmp, _size_stack); + return; + } + if (!cmd->running_on_valgrind) _allocate_memory(); (void)strerror(0); /* Force libc.mo load */ @@ -557,6 +564,13 @@ static void _unlock_mem(struct cmd_context *cmd) { size_t unlock_mstats = 0; + if (!_size_stack || _size_malloc_tmp) { + log_debug_mem("Skipping memory unlocking (reserved memory: " + FMTsize_t " stack: " FMTsize_t ").", + _size_malloc_tmp, _size_stack); + return; + } + log_very_verbose("Unlocking memory"); if (!_memlock_maps(cmd, LVM_MUNLOCK, &unlock_mstats))