2 * Stupid program that leaks memory at a configurable rate, to test swapmon
4 * Mark Huang <mlhuang@cs.princeton.edu>
5 * Copyright (C) 2006 The Trustees of Princeton University
16 main(int argc, char *argv[])
23 int c, option_index = 0;
24 static struct option long_options[] = {
25 { "rate", required_argument, NULL, 'r' },
26 { "size", optional_argument, NULL, 's' },
27 { "help", no_argument, NULL, 'h' },
31 c = getopt_long(argc, argv, "r:h:s", long_options, &option_index);
44 fprintf(stderr, "Usage: %s [OPTION]...\n", argv[0]);
45 fprintf(stderr, "\t-r, --rate=MiB/sec\tRate to leak memory in MiB/sec\n");
46 fprintf(stderr, "\t-s, --size=MiB\tGrow to size and wait.\n");
53 int i, bufsize = rate * 1024 * 1024;
54 char *buf = malloc(bufsize);
55 if (buf && (leaked <= size)) {
56 /* Touch every page in the buffer */
57 for (i = 0; i < bufsize; i += 4096)
60 printf("\r%d MiB", leaked);