MLOCK(3P)
π MLOCK(3P) π β lock or unlock a range of process address space
okay bestie, so this one is from the POSIX Programmer's Manual, and before we get into it there's a lil heads-up note you need, no skipping it π
π«Ά PROLOG π«Ά
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
literally read that twice if you're on Linux, i'm not playing π
β¨ NAME β¨
mlock, munlock β lock or unlock a range of process address space (REALTIME)
πΈ SYNOPSIS πΈ
#include <sys/mman.h>
int mlock(const void *addr, size_t len);
int munlock(const void *addr, size_t len);
π¦ DESCRIPTION π¦
So here's the tea, bestie. The mlock() function shall cause those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes to be memory-resident until unlocked or until the process exits or execs another process image. The implementation may require that addr be a multiple of {PAGESIZE}.
The munlock() function shall unlock those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes, regardless of how many times mlock() has been called by the process for any of the pages in the specified range. The implementation may require that addr be a multiple of {PAGESIZE}.
the "regardless of how many times" part is lowkey the main character of this whole page, like it does not care about your nesting, it just unlocks π
Now the messy polyamory of shared pages, okay:
- If any of the pages in the range specified to a call to
munlock()are also mapped into the address spaces of other processes, any locks established on those pages by another process are unaffected by the call of this process tomunlock(). - If any of the pages in the range specified by a call to
munlock()are also mapped into other portions of the address space of the calling process outside the range specified, any locks established on those pages via the other mappings are also unaffected by this call.
Upon successful return from mlock(), pages in the specified range shall be locked and memory-resident. Upon successful return from munlock(), pages in the specified range shall be unlocked with respect to the address space of the process. Memory residency of unlocked pages is unspecified.
Appropriate privileges are required to lock process memory with mlock(). periodt. π
π₯ RETURN VALUE π₯
Upon successful completion, the mlock() and munlock() functions shall return a value of zero. Otherwise, no change is made to any locks in the address space of the process, and the function shall return a value of -1 and set errno to indicate the error.
so if it fails, it fails clean. nothing half-locked, nothing messy. we love a function with boundaries π
π ERRORS π
The mlock() and munlock() functions shall fail if:
ENOMEMβ Some or all of the address range specified by theaddrandlenarguments does not correspond to valid mapped pages in the address space of the process.
The mlock() function shall fail if:
EAGAINβ Some or all of the memory identified by the operation could not be locked when the call was made.
The mlock() and munlock() functions may fail if:
EINVALβ Theaddrargument is not a multiple of{PAGESIZE}.
The mlock() function may fail if:
ENOMEMβ Locking the pages mapped by the specified range would exceed an implementation-defined limit on the amount of memory that the process may lock.EPERMβ The calling process does not have appropriate privileges to perform the requested operation.
note the difference between "shall fail" and "may fail", bestie β one is guaranteed, one is it depends. do not conflate them, i'm begging π
The following sections are informative.
π EXAMPLES π
None.
not a single example. the girls are NOT showing their work today π
π APPLICATION USAGE π
None.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
execexit()fork()mlockall()munmap()
The Base Definitions volume of POSIX.1β2017, <sys_mman.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie π«Ά go lock some pages (responsibly, you need privileges) π
this one came from IEEE/The Open Group, dated 2017, filed under MLOCK(3P) in the POSIX Programmer's Manual β¨ stay hydrated, stay memory-resident π π§ββοΈπΈ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms