The Problem
When attempting to create an LV the following error occurs.
# lvcreate -L 5G -n apps vgOS 7fa0c6cd2000-7fa0c6cd3000 r-xp 00216000 fd:00 8388746 /usr/lib64/libgcc_s-4 .8.5-20150702.so.1: mlock failed: Cannot allocate memory 7fa0c75ce000-7fa0c75cf000 r-xp 00265000 fd:00 8895769 /usr/lib64/libdevmapp er.so.1.02: mlock failed: Cannot allocate memory 7fa0c77d6000-7fa0c77d7000 r-xp 00207000 fd:00 9313347 /usr/lib64/libdevmapp er-event.so.1.02: mlock failed: Cannot allocate memory 7fa1c6f44000-7fa1c6f45000 r-xp 00203000 fd:00 8413569 /usr/lib64/libksplice _helper.so: mlock failed: Cannot allocate memory 7fa1c7161000-7fa1c7162000 r-xp 0021c000 fd:00 8455088 /usr/lib64/libpthread -2.17.so: mlock failed: Cannot allocate memory 7fa1c7466000-7fa1c7467000 r-xp 00304000 fd:00 8455032 /usr/lib64/libm-2.17. so: mlock failed: Cannot allocate memory 7fa1c7825000-7fa1c7826000 r-xp 003be000 fd:00 8455021 /usr/lib64/libc-2.17. so: mlock failed: Cannot allocate memory 7fa1c7a2e000-7fa1c7a2f000 r-xp 00208000 fd:00 8455092 /usr/lib64/librt-2.17 .so: mlock failed: Cannot allocate memory Logical volume "apps" created.
The Solution
The issue is caused by the use_mlockall paramater in the LVM configuration file /etc/lvm/lvm.conf. As shown below the /etc/lvm/lvm.conf file has below entry:
# cat /etc/lvm/lvm.conf use_mlockall = 0
Configuration option activation/use_mlockall
Prior to version 2.02.62, LVM used mlockall() to pin the whole process’s memory while activating devices, however, later versions of LVM, such as in the example above do not use this functionality. To implement the solution, please execute the following steps:
1. Log in to the server with root user.
2. Edit the /etc/lvm/lvm.conf configuration file and change the below value:
From
# vi /etc/lvm/lvm.conf use_mlockall = 0
To
# vi /etc/lvm/lvm.conf use_mlockall = 1
Note
“use_mlockall = 0” means in theory the memory used by lvm and its libs could get swapped out, but that should only affect you in low-memory situations. So, in most situations “mlock failed: Cannot allocate memory” is only informational message, unless you really have low free RAM.