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
15 main(int argc, char *argv[])
22 int c, option_index = 0;
23 static struct option long_options[] = {
24 { "rate", required_argument, NULL, 'r' },
25 { "size", optional_argument, NULL, 's' },
26 { "help", no_argument, NULL, 'h' },
30 c = getopt_long(argc, argv, "r:h:s", long_options, &option_index);
43 fprintf(stderr, "Usage: %s [OPTION]...\n", argv[0]);
44 fprintf(stderr, "\t-r, --rate=MiB/sec\tRate to leak memory in MiB/sec\n");
45 fprintf(stderr, "\t-s, --size=MiB\tGrow to size and wait.\n");
52 int i, bufsize = rate * 1024 * 1024;
53 char *buf = malloc(bufsize);
54 if (buf && (leaked <= size)) {
55 /* Touch every page in the buffer */
56 for (i = 0; i < bufsize; i += 4096)
59 printf("\r%d MiB", leaked);