forked from memcached/mc-crusher
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathballoon.c
More file actions
34 lines (30 loc) · 840 Bytes
/
balloon.c
File metadata and controls
34 lines (30 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: balloon [megabytes]\n");
exit(1);
}
// autoflush stdout.
setvbuf(stdout, NULL, _IONBF, 0);
int size = atoi(argv[1]);
printf("megabytes: %d\n", size);
for (int x = 0; x < size; x++) {
// We're going to leak this.
uint64_t *temp = calloc(1, 1024 * 1024);
if (temp == NULL) {
fprintf(stderr, "Failed to calloc chunk #%d\n", x);
exit(1);
}
// Fill a bit harder to ensure RAM gets allocated
for (int i = 0; i < (1024*1024) / sizeof(uint64_t); i++) {
temp[i] = i;
}
}
printf("done.\n");
pause();
}