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))