Out of memory handling broken
Hi!
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;
i++;
if (out_of_memory())
break;
}
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 easily.
Pavel
Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care." Panos Katsaloulis describing me w.r.t. patents at [email protected]
Quoted 2 lines · Pavel Machek
I need to allocate as much memory as possible (but not more). Okay, so I use
out_of_memory, right?
Nope, out_of_memory() is about virtual memory handling, not at all about physical memory.
Quoted 9 lines
But, when I looked into
out_of_memory... Of course its wrong.out_of_memory()containsif (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 easily.
This is because you're using out_of_memory() for something it was never meant for. ;)
Even if it didn't take swap into account, you'd still end up counting highmem pages your code cannot use...
cheers,
Rik
--
IA64: a worthy successor to the i860.
http://www.surriel.com/
Hi!
Quoted 5 lines
Quoted 2 lines
I need to allocate as much memory as possible (but not more). Okay, so I use
out_of_memory, right?Nope,
out_of_memory()is about virtual memory handling, not at all about physical memory.
Yes, so... What happens at physical memory exhaustion? System crash?
Quoted 6 lines
Quoted 6 lines
But, when I looked into
out_of_memory... Of course its wrong.out_of_memory()containsif (nr_swap_pages > 0) return 0;
Quoted 6 lines
Quoted 3 lines
...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 easily.This is because you're using
out_of_memory()for something it was never meant for. ;)
Okay, okay. Is there any solution (in 2.4.10) in doing what I want to do?
Pavel
Signature · 2 lines
Causalities in World Trade Center: 6453 dead inside the building, cryptography in U.S.A. and free speech in Czech Republic.
Quoted 7 lines · Pavel Machek
Quoted 5 lines
Quoted 2 lines
I need to allocate as much memory as possible (but not more). Okay, so I use
out_of_memory, right?Nope,
out_of_memory()is about virtual memory handling, not at all about physical memory.Yes, so... What happens at physical memory exhaustion? System crash?
We swap something out.
But indeed, when the kernel needs memory for itself and no more memory is available, we'd crash. This is not something I've ever seen any system get close to, however...
Quoted 2 lines
Okay, okay. Is there any solution (in 2.4.10) in doing what I want to do?
GPF_ATOMIC and giving kswapd a chance to run whenever the atomic allocations fail ?
regards,
Rik
Signature · 5 lines
IA64: a worthy successor to i860. http://www.surriel.com/ http://distro.conectiva.com/ Send all your spam to [email protected] (spam digging piggy)
Hi!
Quoted 6 lines
We swap something out.
But indeed, when the kernel needs memory for itself and no more memory is available, we'd crash. This is not something I've ever seen any system get close to, however...
Yep...
Quoted 5 lines
Quoted 2 lines
Okay, okay. Is there any solution (in 2.4.10) in doing what I want to do?
GPF_ATOMICand giving kswapd a chance to run whenever the atomic allocations fail ?
But how do I know when to stop? I'd have to place timeout there :-(. How do I know no more memory is available?
Pavel
Signature · 2 lines
Causalities in World Trade Center: 6453 dead inside the building, cryptography in U.S.A. and free speech in Czech Republic.