Memory allocation problems

Richard B. Johnson (root@chaos.analogic.com)
Fri, 27 Feb 1998 12:10:19 -0500 (EST)


I am still testing 2.1.87. There are some new memory allocation
problems not present in 2.1.85, the last version I thoroughly
tested.

The following program will hang the machine with 0 Free Pages, while
leaving 111300kB of free swap space. The magic key shows:

Free pages 0kb
Swap cache : Add 4509/4509, delete 1104450/3737, find 42583/664
Free swap 111300kb
8192 pages of RAM
717 free pages
392 pages shared
108 pages swap cached
buffer mem 140kb

Note... This is not a deliberate "killer" program. The children forked
will only live for 5 seconds and pages dirtied are immediately freed.

-------------

#include <stdio.h>
#include <sys/types.h>
#include <malloc.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>

#define HUGE 3000000
static pid_t pid;
int kids = 1;

void killer(int unused)
{
kill(SIGTERM, -1);
signal(SIGALRM, killer);
alarm(2);
}

void reaper(int unused)
{
while((wait3(0, WNOHANG, NULL)) > 0)
;
signal(SIGCHLD, reaper);
if(!(kids--))
exit(0);
}

int main(void);
int main()
{
int i;
char *ptr;
reaper(0);

for(i = 0; i < 200 ; i++)
{
switch((pid=fork()))
{
case 0:
(void) close(0);
(void) close(1);
(void) close(2);
if((ptr = (char *) malloc(HUGE * sizeof(char))) == NULL)
return(0);
signal(SIGALRM, killer);
alarm(5);
for(i=0; i< HUGE; i++)
ptr[i]= (char) (i & 0xff);
free(ptr);
pause();
exit(0);
break;
case -1:
fprintf(stderr, "fork failed!\n");
return -1;
default:
kids++;
break;
}
}
pause();
return 0;
}

------------

This is the "normal" look of /proc/meminfo

total: used: free: shared: buffers: cached:
Mem: 31494144 30543872 950272 6651904 17502208 6696960
Swap: 133885952 77824 133808128
MemTotal: 30756 kB
MemFree: 928 kB
MemShared: 6496 kB
Buffers: 17092 kB
Cached: 6540 kB
SwapTotal: 130748 kB
SwapFree: 130672 kB

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.87 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu