1 /* A very simple program to lock a specified amount of memory (in megabytes)
2 * into memory. Used to decrease the available amount of free memory on a
3 * system for benchmarking purposes. */
10 int main(int argc, char *argv[])
14 "Usage: %s <amount in MiB>\n"
15 "Locks the specified number of megabytes of RAM.\n",
20 size_t bufsize = atoi(argv[1]) << 20;
21 char *buf = malloc(bufsize);
23 fprintf(stderr, "Unable to allocate buffer: %m\n");
27 if (mlock(buf, bufsize) < 0) {
28 fprintf(stderr, "Unable to lock memory: %m\n");
32 /* Infinite loop; simply wait for the program to be killed. */