tangetools/swapout/swapout

43 lines
969 B
Plaintext
Raw Normal View History

2012-12-10 23:58:15 +00:00
#!/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;
2012-12-10 23:58:15 +00:00
do{
$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";
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++;
}
}
} until ($pid or $timediff>$timeout or $total > $memtotal);
2012-12-10 23:58:15 +00:00
print "exit ",$forks,"\n";