develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #119937] Global destruction sometimes makes linux COW useless

Thread Next
Victor Efimov
September 21, 2013 21:42
[perl #119937] Global destruction sometimes makes linux COW useless
Message ID:
# New Ticket Created by  Victor Efimov 
# Please include the string:  [perl #119937]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Below example (with $N high enough - 100 in my case) works fine if I
terminate process group with Ctrl-C
but start swapping if I wait for graceful process termination (i.e. with
USR1, when exit() called).

I think that's because Linux COW feature - after huge process forks, memory
is not copied in real, until modified.
And, it seems, that when Perl global destruction happens, all memory is
modified in this particular example.

So I am wondering, maybe it's possible to free simple data structures
without modifying them.


use strict;
use warnings;

my $N=20;

my $x={};

$x->{a} = [map { $_ } 1..10_000_000 ];

$SIG{USR1} = sub { print "exiting $$\n"; exit(0); };

my @pids;
for (1..$N) {
  if (my $pid = fork) {
    push @pids, $pid;
  } else {
    while() { sleep 1;}

sleep 5;
print "GRACEFUL EXIT\n";
kill 'USR1', $_ for @pids;

(tested with 5.10.1 and 5.19.4. Linux 2.6.38, 16GB ram)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About