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).
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 ...