[test program] for OOM situations

Bernd Kaindl (bk@suse.de)
Thu, 1 Jul 1999 02:18:19 +0200 (MEST)


Hi,

I've a test program here which can be used to check the differend
behavor of OOM situations in 2.0, 2.2 and 2.3 kernels.

The program is quite effective in eating every byte of userspace memory:

--- empty Thu Jul 1 02:01:49 1999
+++ mem.c Thu Jul 1 02:02:00 1999
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <string.h>
+
+#define MEM_MAX 1024 * 1024 * 5
+
+main()
+{
+ long mem_avail = MEM_MAX;
+ char *buf;
+
+ while(1)
+ {
+ printf("Trying to allocate %ld bytes: ", mem_avail);
+
+ if ((buf = (char *)malloc((size_t)mem_avail)))
+ {
+ printf(" success!\n");
+ memset(buf, 'X', mem_avail);
+ //sleep(1);
+ }
+ else
+ {
+ printf(" failed :(\n");
+ mem_avail = mem_avail / 2;
+ sleep(1);
+ }
+ }
+
+ return 0;
+}

Result on 2.0.37:
Runs slowly, eats all mem and keeps running. 'top' can be used to kill it.
Ctrl-C interrupts the program immediately.

Result on 2.3.9-pre8
Runs fast, eats all mem and keeps running. 'top' can be used to kill it.
Ctrl-C interrupts the program immediately.

Result on 2.2.{7,10}
Runs fast, eats all mem and stops. 'top' stops refreshing its display,
so you need to catch the pid before OOM if you want to kill it. some
seconds pass from pressing the 'k'-key in top and the 'PID to kill'-prompt.
Ctrl-C takes quite some time to interrupt the program(if you are lucky).

Any Comments?

- Bernd

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/