swapout: Dynamically size the chunk to reserve.

This commit is contained in:
Ole Tange 2018-02-24 16:49:00 +01:00
parent e7dd4cf74a
commit 11d2fd96a1

View file

@ -2,20 +2,33 @@
$timeout = shift || 10; $timeout = shift || 10;
$total=10000000;
my $giga=2**30; my $giga=2**30;
my $forks=1; 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{ do{
$start = time; $start = time;
$total=int(1+$total*1.03); $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; $missing = $total - $sofar;
$buf{$forks}{$total}="x"x$missing; for(1..$missing) {
$buf{$forks}{$total}{$_} = $onemb;
}
$sofar = $total; $sofar = $total;
$timediff = time - $start; $timediff = time - $start;
print "Chunk size: $missing Time for swapping: $timediff seconds. Total memory used: $total\n"; print "Chunk size: $missing Time for swapping: $timediff seconds. Total memory used: $total\n";
if($total > $forks * $giga) { if($total * 1048576 > $forks * $giga) {
if($pid=fork()) { if($pid=fork()) {
print "child spawn ",$forks,"\n"; print "child spawn ",$forks,"\n";
wait; wait;
@ -25,5 +38,5 @@ do{
$forks++; $forks++;
} }
} }
} until ($pid or $timediff>$timeout); } until ($pid or $timediff>$timeout or $total > $memtotal);
print "exit ",$forks,"\n"; print "exit ",$forks,"\n";