tinita has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fork on linux 2.6 does not share memory
by perrin (Chancellor) on Jul 26, 2005 at 14:51 UTC | |
by tinita (Parson) on Jul 26, 2005 at 14:55 UTC | |
|
Re: fork on linux 2.6 does not share memory
by PreferredUserName (Pilgrim) on Jul 26, 2005 at 16:34 UTC | |
by salva (Canon) on Jul 27, 2005 at 13:57 UTC | |
|
Re: fork on linux 2.6 does not share memory
by Monk Eugene (Initiate) on Jul 26, 2005 at 14:52 UTC | |
by dave_the_m (Monsignor) on Jul 26, 2005 at 14:58 UTC |