Skip to content

Instantly share code, notes, and snippets.

@jlevon
Created October 1, 2020 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlevon/18d9c50d36e6684937e1dc5337110af7 to your computer and use it in GitHub Desktop.
Save jlevon/18d9c50d36e6684937e1dc5337110af7 to your computer and use it in GitHub Desktop.
mincore test of memfd
#include <unistd.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <linux/mman.h>
#include <sys/mman.h>
#include <assert.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int fd = memfd_create("test", 0);
assert(fd != -1);
int rc = ftruncate(fd, 4096 * 256 * 1024);
assert(rc == 0);
void *addr = mmap(0, 4096 * 256 * 1024, PROT_READ | PROT_WRITE,
MAP_PRIVATE, fd, 0);
assert(addr != -1);
unsigned char in;
rc = mincore(addr, 4096, &in);
assert (rc == 0);
printf("in: %d\n", (int)in);
*((char *)addr) = 1;
rc = mincore(addr, 4096, &in);
assert (rc == 0);
printf("in: %d\n", (int)in);
}
$ ./mincore
in: 0
in: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment