AIO_MLOCK(2)
β¨ aio_mlock β asynchronous mlock(2) operation β¨
okay bestie, welcome to aio_mlock(2), the FreeBSD system call manual page π this one lives in the System Calls Manual and it's all about locking pages into memory but likeβ¦ asynchronously. main character energy fr fr.
π«Ά LIBRARY
Standard C Library (libc, -lc). yes queen, it's right there in libc, you don't have to go hunting πΈ
π SYNOPSIS
#include <aio.h>
int
aio_mlock(struct aiocb *iocb);
π DESCRIPTION
okay so here's the tea β β the aio_mlock() system call lets the calling process lock into memory the physical pages that belong to the virtual address range starting at iocb->aio_buf, for iocb->aio_nbytes bytes. iconic, right?
the call returns immediately after the locking request has been enqueued. so likeβ¦ the operation may or may not have completed by the time the call comes back. it's giving "don't wait up" π
you can subsequently use that iocb pointer as an argument to aio_return() and aio_error() to figure out the return or error status for the enqueued operation while it's still in progress. lowkey genius.
if the request could not be enqueued (generally because of aio(4) limits), then the call just returns without having enqueued the request. no drama, no queue π
the iocb->aio_sigevent structure can be used to request notification of the operation's completion, as described in aio(4). get that notif, bestie π
π¨ RESTRICTIONS
bestie, read this part, I'm literally begging π these are the rules and you cannot break them.
- The Asynchronous I/O Control Block structure pointed to by
iocb, and the buffer that theiocb->aio_bufmember of that structure references, must remain valid until the operation has completed. - The asynchronous I/O control buffer
iocbshould be zeroed before theaio_mlock()call, to avoid passing bogus context information to the kernel. zero it out babe, it's not optional-vibes, it's for your own good β¨ - Modifications of the Asynchronous I/O Control Block structure or the memory mapping described by the virtual address range are not allowed while the request is queued. hands off while it's cooking π
π RETURN VALUES
The aio_mlock() function returns the value 0 if successful π otherwise the value -1 is returned and the global variable errno is set to indicate the error. not the slay we wanted, but at least it tells you why π
π ERRORS
The aio_mlock() system call will fail if:
[EAGAIN]β The request was not queued because of system resource limitations. the queue said "no room bestie" π«[EINVAL]β The asynchronous notification method iniocb->aio_sigevent.sigev_notifyis invalid or not supported. wrong method, wrong vibe π«
if the request is successfully enqueued but then subsequently cancelled or an error occurs:
- the value returned by the
aio_return()system call is per themlock(2)system call π - the value returned by the
aio_error()system call is one of the error returns from themlock(2)system call, orECANCELEDif the request was explicitly cancelled via a call toaio_cancel(). cancelled =ECANCELED, periodt π
π SEE ALSO
aio_cancel(2), aio_error(2), aio_return(2), mlock(2), sigevent(3), aio(4)
go read those too, iykyk π
π PORTABILITY
The aio_mlock() system call is a FreeBSD extension, and should not be used in portable code. ngl bestie, if you're writing cross-platform code, this is NOT the one. it's a FreeBSD-only moment, no cap π¦
π HISTORY
The aio_mlock() system call first appeared in FreeBSD 10.0. a classic, a legend, an icon β
π AUTHORS
The system call was introduced by Gleb Smirnoff <glebius@FreeBSD.org>. thank you for your service, king π«‘
and that's the whole page, bestie!! this little beauty came to you from Debian, dated August 19, 2016 β so yeah, it's been living rent-free in the AIO_MLOCK(2) files since then. lock those pages, zero that iocb, and stay hydrated πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2013 Gleb Smirnoff <glebius@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms