diff options
author | Rob Landley <rob@landley.net> | 2024-01-25 23:52:30 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2024-01-25 23:52:30 -0600 |
commit | ebcd678451feadfdec87277c48c12d01f936b391 (patch) | |
tree | 8024abdb869334a6f4dc4e5420627786fd235b05 | |
parent | 77d4207dbe76c55becf7f56eb01d443eb0bfc319 (diff) | |
download | toybox-ebcd678451feadfdec87277c48c12d01f936b391.tar.gz |
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).
-rw-r--r-- | toys/other/memeater.c | 31 | ||||
-rw-r--r-- | toys/pending/memeater.c | 31 |
2 files changed, 31 insertions, 31 deletions
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<size; i += 4096/sizeof(long)) p[i] = i; + + while (1) pause(); +} diff --git a/toys/pending/memeater.c b/toys/pending/memeater.c deleted file mode 100644 index d4aa5f04..00000000 --- a/toys/pending/memeater.c +++ /dev/null @@ -1,31 +0,0 @@ -/* memeater.c - consume the specified amount of memory - * - * Copyright 2024 The Android Open Source Project - -USE_MEMEATER(NEWTOY(memeater, "<1", TOYFLAG_USR|TOYFLAG_BIN)) - -config MEMEATER - bool "memeater" - default y - help - usage: memeater SIZE - - Consume the specified amount of memory (in bytes, with optional suffix). -*/ - -#define FOR_memeater -#include "toys.h" - -void memeater_main(void) -{ - long long size = atolx(*toys.optargs), i; - char* p; - - p = xmalloc(size); - // Lock the physical pages. - if (mlock(p, size)) perror_exit("mlock"); - // And ensure we weren't cheated by overcommit... - for (i = 0; i < size; i++) p[i] = i; - - while (1) pause(); -} |