#include #include #include #include #include #include int main(int argc, char *argv[]) { char *junk; uint64_t mem; uint64_t i; uint64_t count; long pagesize; long pages; if (argc != 1) { fprintf(stderr, "Usage: memeater\n"); return 1; } pagesize = sysconf(_SC_PAGESIZE); pages = sysconf(_SC_PHYS_PAGES); // Allocate all memory in the machine except for 150MB mem = (uint64_t)(pagesize) * (uint64_t)(pages) - (150 * 1024 * 1024); fprintf(stdout, "Going to malloc %llu bytes\n",mem); junk = malloc(mem); if (junk == NULL) { fprintf(stderr, "Failed to malloc %llu bytes: %s\n",mem,strerror(errno)); return 2; } fprintf(stdout, "Going to touch %llu bytes continuously; Ctrl-C to quit\n",mem); count = 0; while (1) { for (i = 0; i < mem ; i++) *(junk + i) = count; count++; } free(junk); return 0; }