MINCORE(2)
π MINCORE(2) π
okay bestie, sit down, we're doing a system call today. this one lives in the System Calls Manual section (that's section 2, iykyk) and it's all about figuring out which of your memory pages are actually here right now. it's giving detective energy. πβ¨
πΈ NAME πΈ
mincore β determine residency of memory pages
like... which pages are home rn? that's the whole vibe.
π LIBRARY π
Standard C Library (libc, -lc)
yeah you just link the normal libc, nothing spicy, no extra flag needed beyond -lc. slay.
β¨ SYNOPSIS β¨
#include <sys/mman.h>
int
mincore(const void *addr, size_t len, char *vec);
look at her. three arguments, one int return, no drama. π
π¦ DESCRIPTION π¦
so the mincore() system call figures out whether each of the pages in the region starting at addr and going on for len bytes is resident or mapped β and which of those two things it tells you depends on the value of the sysctl vm.mincore_mapped. yes, a sysctl controls the whole mood. iconic.
the status comes back in the vec array, and it's literally one character per page. each character is either:
0if the page is not resident, or- a combination of the following flags (these are defined in
<sys/mman.h>, bestie, go look):
π§ the flags π§
MINCORE_INCOREβ page is in core (resident). she's here, she's present, main character.MINCORE_REFERENCEDβ page has been referenced by us.MINCORE_MODIFIEDβ page has been modified by us.MINCORE_REFERENCED_OTHERβ page has been referenced.MINCORE_MODIFIED_OTHERβ page has been modified.MINCORE_SUPERβ page is part of a large (βsuperβ) page. big page energy fr fr.
β οΈ okay important: the info thatmincore()gives you may already be out of date by the time the system call returns. like, you asked, the answer came back, and the world moved on. π the only way to actually ensure a page is resident is to lock it into memory with themlock(2)system call. that's the real ones' move.
π the sysctl situation π
if vm.mincore_mapped is set to a non-zero value (and that's the default, btw), then only the current process' mappings of the pages in the specified virtual address range get examined.
but heads up: this does not preclude the system from returningMINCORE_REFERENCED_OTHERandMINCORE_MODIFIED_OTHERstatuses. so don't be shocked when those show up anyway. π
otherwise, if the sysctl value is zero, then all resident pages backing the specified address range get examined β regardless of the mapping state. the whole neighborhood gets a vibe check. π
π RETURN VALUES π
the mincore() function returns the value 0 if successful. otherwise the value -1 is returned, and the global variable errno gets set to indicate the error.
0 = we ate. -1 = check errno, bestie. π
π₯ ERRORS π₯
the mincore() system call will fail if:
[ENOMEM]β the virtual address range specified by theaddrandlenarguments is not fully mapped. you pointed at a hole, girl.[EFAULT]β thevecargument points to an illegal address. that pointer is not it. π«
π SEE ALSO π
madvise(2), mlock(2), mprotect(2), msync(2), munmap(2), getpagesize(3)
the whole memory-management friend group honestly. go read them all, they're a package deal. π«Ά
β HISTORY β
the mincore() system call first appeared in 4.4BSD. a true elder. she's been doing this since before you were born, respect her. π
and that's the page!! tysm for reading, you're literally so good at Unix now. π
this one came from the fine folks at Debian, dated January 7, 2019 β mwah, love that for them. π
π¦ 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) 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms