Updated: 28 September 2026 · Applies to: LVM 2.03 on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13

While LVM changes device-mapper devices, it locks its own memory in RAM with the mlock() system call, so that it can never be swapped out while disk I/O is paused. The message

mlock failed: Cannot allocate memory

means the kernel refused that lock. According to the mlock manual page, this happens when the process may not lock that much memory (its locked-memory limit) or when the kernel cannot lock the pages for other reasons, such as the system running out of memory or of memory mappings. The checks below go through these causes in order.

1. Is the server short of memory?

free -h
journalctl -k -b | grep -i -E 'out of memory|oom'

If free memory is nearly zero, stop or restart the process that uses it, then run the LVM command again.

2. Check the locked-memory limit

ulimit -l
grep -i 'locked memory' /proc/self/limits

Root normally has the CAP_IPC_LOCK capability, which ignores this limit. It matters when LVM commands run in a restricted environment: inside a container, from a systemd service with LimitMEMLOCK or dropped capabilities, or through a tool that does not run them as full root. Run the command from a normal root shell on the host, or raise the limit for that session: ulimit -l unlimited.

3. Check the number of memory mappings

cat /proc/sys/vm/max_map_count

Locking can also fail if a process would exceed this limit. The default (65530) is normally enough for LVM; if it was lowered on purpose, restore it.

4. LVM's own reserve

In the activation section of /etc/lvm/lvm.conf, reserved_memory (default 8192 KiB) and reserved_stack (default 64 KiB) set how much memory LVM pre-allocates and locks. Change these only as a last resort and restore them afterwards.

After the error

Check that the command did what you wanted: lvs, vgs and lsblk. If a volume was created but not activated, activate it with lvchange -ay vgname/lvname.

Official documentation: mlock manual page and lvm.conf manual page.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)