/* DF-2983 pressure helper: eat anonymous memory and hold it, forcing the
 * pagedaemon into laundering cycles. Run under nohup. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
main(void)
{
	size_t total = 0, i;
	char **chunks = NULL;
	size_t nchunks = 0;

	setvbuf(stdout, NULL, _IONBF, 0);
	for (;;) {
		char *p = malloc(16 << 20);
		if (!p) {
			printf("[eater] malloc failed at %zu MB\n", total >> 20);
			break;
		}
		memset(p, 0x42, 16 << 20);
		chunks = realloc(chunks, (nchunks + 1) * sizeof(char *));
		chunks[nchunks++] = p;
		total += 16 << 20;
		if ((total >> 20) % 256 == 0)
			printf("[eater] %zu MB\n", total >> 20);
		if ((total >> 20) >= 3072)
			break;
	}
	printf("[eater] holding %zu MB\n", total >> 20);
	for (;;)
		sleep(30);
	for (i = 0; i < nchunks; i++)
		chunks[i][0]++;
	return 0;
}
