mincore(2)

๐Ÿ‘‘ mincore(2) โ€” the page residency vibe check ๐Ÿ‘‘

okay bestie, so mincore is a Linux system call (manual section 2, system calls, iykyk) and it literally just tells you which of your pages are chillin' in RAM right now. no cap.


๐ŸŒธ NAME ๐ŸŒธ

mincore โ€” determine whether pages are resident in memory

like, is this page in memory or not? that's the whole question. it's giving "where are my pages" energy. ๐Ÿ’…


๐ŸŽ€ LIBRARY ๐ŸŽ€

Standard C library (libc, -lc)


โœจ SYNOPSIS โœจ

#include <sys/mman.h>

int mincore(size_t length;
            void addr[length], size_t length, unsigned char *vec);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

mincore():
    Since glibc 2.19:
        _DEFAULT_SOURCE
    glibc 2.19 and earlier:
        _BSD_SOURCE || _SVID_SOURCE
yes bestie, that is literally how it's written. we do not fix the synopsis, we respect the synopsis. ๐Ÿ™ˆ

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so mincore() hands you back a whole vector telling you whether pages of your calling process's virtual memory are resident in core (that's RAM bestie) โ€” meaning if you touched them, they would not cause a disk access (a page fault) ๐Ÿซถ. the kernel gives you the residency tea about the pages starting at the address addr, and it keeps going for length bytes.

the addr argument must be a multiple of the system page size. no exceptions, the kernel is not flexible on this one. the length argument doesn't have to be a multiple of the page size, BUT โ€” and this is the part people trip on โ€” since residency info comes back for whole pages, length effectively gets rounded up to the next multiple of the page size. you can grab the page size (PAGE_SIZE) with sysconf(_SC_PAGESIZE). slay.

the vec argument must point to an array containing at least (length+PAGE_SIZE-1) / PAGE_SIZE bytes. on return, the least significant bit of each byte gets set if the corresponding page is currently resident in memory, and it's clear otherwise. (the settings of the other bits in each byte are undefined โ€” those bits are reserved for possible later use, so don't you dare read meaning into them ๐Ÿ™ˆ).

and of course the information returned in vec is only a snapshot: pages that are not locked in memory can come and go at any moment, and the contents of vec may already be stale by the time this call returns. it's giving "you blinked and the data changed" ๐Ÿ˜ญ. that's not a bug, that's just memory being memory.


๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

  • On success, mincore() returns zero. โœจ
  • On error, -1 is returned, and errno is set to indicate the error. classic.

๐Ÿ’€ ERRORS ๐Ÿ’€

  • EAGAIN โ€” kernel is temporarily out of resources. it's not you, it's the kernel, it's going through something.
  • EFAULT โ€” vec points to an invalid address. bestie that pointer is not pointing anywhere real ๐Ÿ’€
  • EINVAL โ€” addr is not a multiple of the page size. you knew this rule. you were told about this rule. ๐Ÿ‘€
  • ENOMEM โ€” length is greater than (TASK_SIZE - addr). (this could occur if a negative value is specified for length, since that value will be interpreted as a large unsigned integer ๐Ÿซ ). in Linux 2.6.11 and earlier, the error EINVAL was returned for this condition.
  • ENOMEM โ€” addr to addr + length contained unmapped memory. yeah, there's a hole in there.
not two ENOMEM entries being a thing but here we are, both are real, both count. โœจ

๐ŸŒˆ STANDARDS ๐ŸŒˆ

None. literally none. she's not standardized, she's just there, doing her thing, living her best life. ๐Ÿ’…


๐Ÿฆ‹ HISTORY ๐Ÿฆ‹

SunOS 4.1, 4.4BSD, FreeBSD 2.2, Solaris 8, Linux 2.3.99pre1, glibc 2.2, NetBSD 1.5, OpenBSD 2.9, AIX 5.1.

she's been around the block, an absolute icon, a legend, a very well-traveled syscall. ๐Ÿ‘‘


๐Ÿ“ BUGS ๐Ÿ“

before Linux 2.6.21, mincore() did not return correct information for MAP_PRIVATE mappings, or for nonlinear mappings (established using remap_file_pages(2)). so if you're time-traveling back to pre-2.6.21 Linux... good luck bestie, the data was lying to you ๐Ÿ˜ญ. (not an issue anymore, but we keep receipts.)


๐Ÿ’œ SEE ALSO ๐Ÿ’œ


and that's the whole page, bestie, no cap, we kept every single detail โ€” fr fr. this was brought to you by Linux man-pages 6.20, dated 2026-02-16, and yes, mincore(2) is eating and leaving no crumbs. mwah ๐Ÿ’…โœจ๐Ÿซถ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • 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 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms