2012-12-10 23:58:15 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
$timeout = shift || 10;
|
|
|
|
|
|
|
|
my $giga=2**30;
|
|
|
|
my $forks=1;
|
|
|
|
|
2018-02-24 15:49:00 +00:00
|
|
|
my $free;
|
|
|
|
|
|
|
|
my $memtotal = int(
|
|
|
|
qx{ awk '/^(MemTotal):/ { sum += \$2} END { print sum }' /proc/meminfo }
|
|
|
|
/ 1024);
|
|
|
|
|
|
|
|
$total = 1;
|
|
|
|
$onemb = "x"x1048576;
|
2012-12-10 23:58:15 +00:00
|
|
|
do{
|
2018-02-24 15:49:00 +00:00
|
|
|
$start = time;
|
|
|
|
$free = int (
|
|
|
|
qx{ awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += \$2} END { print sum }' /proc/meminfo }
|
|
|
|
/ 1024);
|
|
|
|
print "Free $free ";
|
|
|
|
$total += int($free/100);
|
|
|
|
$missing = $total - $sofar;
|
|
|
|
for(1..$missing) {
|
|
|
|
$buf{$forks}{$total}{$_} = $onemb;
|
|
|
|
}
|
|
|
|
$sofar = $total;
|
|
|
|
$timediff = time - $start;
|
|
|
|
|
2012-12-10 23:58:15 +00:00
|
|
|
print "Chunk size: $missing Time for swapping: $timediff seconds. Total memory used: $total\n";
|
2018-02-24 15:49:00 +00:00
|
|
|
if($total * 1048576 > $forks * $giga) {
|
2012-12-10 23:58:15 +00:00
|
|
|
if($pid=fork()) {
|
|
|
|
print "child spawn ",$forks,"\n";
|
|
|
|
wait;
|
|
|
|
print "child exit ",$forks,"\n";
|
|
|
|
} else {
|
|
|
|
$buf{$forks}=1;
|
|
|
|
$forks++;
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 15:49:00 +00:00
|
|
|
} until ($pid or $timediff>$timeout or $total > $memtotal);
|
2012-12-10 23:58:15 +00:00
|
|
|
print "exit ",$forks,"\n";
|