Out of memory handling broken

Pavel Machek (pavel@suse.cz)
Tue, 25 Sep 2001 00:34:16 +0200


I need to allocate as much memory as possible (but not more). Okay, so
I use out_of_memory, right?

Does this code look sane?

static void eat_memory(void)
int i = 0;
void **c= eaten_memory, *m;

printk("Eating pages ");
while ((m = (void *) get_free_page(GFP_USER))) {
memset(m, 0, PAGE_SIZE);
eaten_memory = m;
if (!(i%5000))
printk( "." );
*eaten_memory = c;
c = eaten_memory;
if (out_of_memory())
printk("(%dK)\n", i*4);

[if not, how should I code it?]

But, when I looked into out_of_memory... Of course its
wrong. out_of_memory() contains

if (nr_swap_pages > 0)
return 0;

...which is obviously wrong. It is well possible to have free swap
_and_ be out of memory -- eat_memory() loop gets system to this state

I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at discuss@linmodems.org
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/