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