X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=microbench%2Flockmem.c;fp=microbench%2Flockmem.c;h=c0ea9d2258449ae454baf98db185bd8d3609cfab;hb=1d1d7431b759d5027929362bdc668ccd64db6753;hp=0000000000000000000000000000000000000000;hpb=c1f4367b3c65b01562bc6484226dff0135cd4780;p=bluesky.git diff --git a/microbench/lockmem.c b/microbench/lockmem.c new file mode 100644 index 0000000..c0ea9d2 --- /dev/null +++ b/microbench/lockmem.c @@ -0,0 +1,38 @@ +/* A very simple program to lock a specified amount of memory (in megabytes) + * into memory. Used to decrease the available amount of free memory on a + * system for benchmarking purposes. */ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, + "Usage: %s \n" + "Locks the specified number of megabytes of RAM.\n", + argv[0]); + return 1; + } + + size_t bufsize = atoi(argv[1]) << 20; + char *buf = malloc(bufsize); + if (buf == NULL) { + fprintf(stderr, "Unable to allocate buffer: %m\n"); + return 1; + } + + if (mlock(buf, bufsize) < 0) { + fprintf(stderr, "Unable to lock memory: %m\n"); + return 1; + } + + /* Infinite loop; simply wait for the program to be killed. */ + while (1) { + sleep(3600); + } + + return 0; +}