$RodHat_/search
resource limits reference

RLIMIT_MEMLOCK

Maximum bytes the process may lock into RAM.

Resource number
8
Row in /proc/PID/limits
Max locked memory
bash ulimit flag
ulimit -l
Unit in /proc/PID/limits
bytes
Group
Memory

What happens at the limit

mlock(2) and mlockall(2) fail with ENOMEM, or with EPERM when the soft limit is 0 and the caller lacks CAP_IPC_LOCK. mmap(2) with MAP_LOCKED fails with EAGAIN. shmctl(2) SHM_LOCK is limited too, counted separately per real user ID.

Error names: ENOMEM, EAGAIN, EPERM.

A process with CAP_IPC_LOCK is exempt. Before Linux 2.6.9 this limit governed how much a privileged process could lock; since then it governs unprivileged ones. Anything that pins memory, RDMA registration for one, tends to run into it first, and the usual symptom is an ENOMEM on a box with plenty of free memory.

Check a running process with grep -i "Max locked memory" /proc/PID/limits, or paste the whole file into the limits reader. Inspect or change one on a live process with prlimit --pid PID(util-linux).

Syscall cards that mention it

  • memfd_secret(2)Linux · Memory

    Create memory removed from the kernel's direct map, mapped only by fd holders.

  • mlock(2)Linux · Memory

    Lock pages into RAM so they can't be swapped out; mlockall() does the whole address space.

Rod on this

Sources

  1. getrlimit(2), Linux man-pages
  2. proc_pid_limits(5), Linux man-pages

Resource numbers are from asm-generic/resource.h; a few architectures (Alpha, MIPS, SPARC) number some limits differently. The list of syscall cards is matched by name from the card text on this site, not from the kernel source. Spot one that's wrong? Tell Rod.