On Fri, 10 Nov 2000, Kevin Franden wrote:

> 
> 
> fork(2) makes an _entire_ copy of the parent - data elements and all. 
> This is very inconvenient for things that use alot of memory.
> 

An entire copy of the *address space* - and only the relevant parts. Only when
a page is accessed by the child will it be created into memory. As for .text,
it's shared. Linux also does demand paging.

As to the script, please notice that perl preallocates memory for arrays, more
than what is needed, and reallocates more when needed. So, you do not quite
allocate a 10 million integer array with you script, but you allocate a
shitload of SVs, and sizeof(SV) is way superior to sizeof(int). What you
allocate is way more than 300 megs. Also, when you fork with perl, you also
fork perl, and this makes for quite a huge memory hog. Using system() isn't
very smart either.

As a conclusion, COW and demand paging do work, thanks. What you have triggered
is the hazardeous behaviour of Linux in OOM situations, but this is currently
in the works. The system is not crashed but you made it unresponsive. Try
Sysrq-k.

Try this same test with 2.4, too. And try this in C.

> > 
> > perl -e '$| = 1; sub s1() { system("free -t | tail -1") } s1(); for 
> > ($i =
> > 0; $i<10_000_000; $i++) { $a[$i] = 0 } s1(); if (\!fork()) { s1(); 
> > for ($i
> > = 0; $i<scalar(@a); $i+=300) { $a[$i] = 0 } s1() } else { wait() }'
> > 

-- 
Francis Galiegue, [EMAIL PROTECTED]
"Programming is a race between programmers, who try and make more and more
idiot-proof software, and universe, which produces more and more remarkable
idiots. Until now, universe leads the race"  -- R. Cook


Reply via email to