For reproducing I made a simple perl one-liner (well,
more like 13 lines) that has a big string (100,000,000) which uses about 200MB RAM.
if I fork this script, on a linux kernel 2.4 all memory
is shared, so still 200MB in usage for both. only if I change the string in the child, memory is copied (400MB). I think this is called copy-on-write (correct me if I'm wrong).
now, with a 2.6 kernel on amd64 (debian both systems),
almost no memory is shared (like 1MB or so).
here's the test script:
perl 5.6.1 and 5.8.4 on kernel 2.6 both show that effect, while 2.4er kernels all share the whole memory (somebody else tested the above script on several machines).perl -we'my $cmd = qq{top -b -n 1 |grep }; print "$$ start\n";print qx{$cmd $$}; my $s="";my $x = "_" x $ARGV[0]; print "string\n";print qx{$cmd $$}; if (my $pid = fork) { print "parent $$ forked $pid\n";print qx{$cmd $$}; $s = "<".$s.">"; } else { print "child $$\n";print qx{$cmd $$}; $s = "(".$s.")";sleep 3; print "child slept 3\n"; } print "$$ end\n";print qx{$cmd $$};' 100000000
so, question: if this was a bug I would have probably found it with google, but I didn't find anything helpful. what can I do about it, has anyone else experienced this? I guess a pre-forking Apache/mod_perl is pretty common, so there must be others who have the same problem...
update: s/200/400/g and s/100/200/g for correct sizes
In reply to fork on linux 2.6 does not share memory by tinita
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |