* memory allocation mystery
@ 2001-07-06 22:59 Sasha Pachev
0 siblings, 0 replies; only message in thread
From: Sasha Pachev @ 2001-07-06 22:59 UTC (permalink / raw)
To: linux-kernel
Hello,
I have been investigating kernel behavior ( I am running 2.4.3) in out of
memory conditions with swap completely disabled and discovered a rather
interesting behavior. If you run the following code:
#include <stdio.h>
#include <stdlib.h>
#define LEAK_BLOCK (1024*1024)
#define MB (1024*1024)
int main()
{
unsigned long total = 0;
for (;;)
{
char* p, *p_end;
if(!(p=malloc(LEAK_BLOCK)))
{
fprintf(stderr, "malloc() failed\n");
exit(1);
}
p_end = p + LEAK_BLOCK;
while(p < p_end)
*p++ = 0;
total += LEAK_BLOCK;
printf("Allocated %d MB\n", total/MB);
}
return 0;
}
the process eventually gets killed by the kernel, rather than getting an
error from malloc() as you would logically expect
I have straced the process and see just a bunch of old_mmap() calls like this:
old_mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0)
= 0x46b6a000
( in addition to writes to stdout, of course). So it looks like old_mmap()
never returns an error.
Can somebody explain this behavior? To me it looks like a bug...
--
MySQL Development Team
For technical support contracts, visit https://order.mysql.com/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Sasha Pachev <sasha@mysql.com>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, http://www.mysql.com/
/_/ /_/\_, /___/\___\_\___/ Provo, Utah, USA
<___/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-07-06 22:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-06 22:59 memory allocation mystery Sasha Pachev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox