Resident or not?

Now that we clearly understand that the pages allocated by malloc and friends are virtual and not guaranteed to be backed by physical frames (at least to start with), imagine we have a pointer to a (virtual) memory region and we know its length. We would now like to know whether the corresponding pages are in RAM, that is, whether they are resident or not.

It turns out there's a system call available that gives precisely this information: mincore(2).

The mincore(2) system call is pronounced m-in-core, not min-core. Core is an old word used to describe physical memory.

Let's take a look at the following code:

#include <unistd.h>#include <sys/mman.h>int mincore(void *addr, size_t length, unsigned char *vec);

Given the starting ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.