From ebcd678451feadfdec87277c48c12d01f936b391 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 25 Jan 2024 23:52:30 -0600 Subject: [PATCH] Cleanup and promote memeater. Add -M option to switch off mlock(), and only touch start of each page to dirty them (leaving the rest zeroed by kernel). --- toys/other/memeater.c | 31 +++++++++++++++++++++++++++++++ toys/pending/memeater.c | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 toys/other/memeater.c delete mode 100644 toys/pending/memeater.c diff --git a/toys/other/memeater.c b/toys/other/memeater.c new file mode 100644 index 00000000..f2523c0e --- /dev/null +++ b/toys/other/memeater.c @@ -0,0 +1,31 @@ +/* memeater.c - consume the specified amount of memory + * + * Copyright 2024 The Android Open Source Project + +USE_MEMEATER(NEWTOY(memeater, "<1>1M", TOYFLAG_USR|TOYFLAG_BIN)) + +config MEMEATER + bool "memeater" + default y + help + usage: memeater [-M] BYTES + + Consume the specified amount of memory and wait to be killed. + + -M Don't mlock() the memory (let it swap out). +*/ + +#define FOR_memeater +#include "toys.h" + +void memeater_main(void) +{ + unsigned long size = atolx_range(*toys.optargs, 0, ULONG_MAX), i, + *p = xmalloc(size); + + // Lock and dirty the physical pages. + if (!FLAG(M) && mlock(p, size)) perror_exit("mlock"); + for (i = 0; i