swapout: Use random 1MB to avoid RAM compression.

This commit is contained in:
Ole Tange 2020-08-04 23:11:40 +02:00
parent 1209cfbbb8
commit b1bb72c63b
4 changed files with 48 additions and 27 deletions

View file

@ -17,7 +17,7 @@ B<drac> [[I<user>[:I<password>]@]I<host>]
iDRAC6 uses a Java program to show the virtual console. iDRAC6 uses a Java program to show the virtual console.
From the iDRAC6 B<drac> downloads the .jar file that is used to From the iDRAC6 B<drac> downloads the .jar file that is used to
connect to the iDRAC6's virtual console. Then it runs it with Java. connect to the virtual console of iDRAC6. Then it runs it with Java.
=head1 OPTIONS =head1 OPTIONS
@ -92,12 +92,12 @@ B<drac> uses B<java>.
B<java> B<java>
'
=cut =cut
read host user passwd < <(echo "$1" | read host user passwd < <(echo "$1" |
# parse [[user[:pass]@]host]
perl -pe 's/^(?:(.*?)(?::(.*?))?@)?(.*?)$/$3 $1 $2/') perl -pe 's/^(?:(.*?)(?::(.*?))?@)?(.*?)$/$3 $1 $2/')
# Set default values
if [ "$user" = "" ] ; then if [ "$user" = "" ] ; then
DRAC_USER=${DRAC_USER:-root} DRAC_USER=${DRAC_USER:-root}
else else
@ -114,8 +114,9 @@ else
DRAC_HOST="$host" DRAC_HOST="$host"
fi fi
tmp=`tempfile` tmp=$(tempfile)
# Find a command line tool to download with
get=$( get=$(
(lynx -source /dev/null && echo lynx -source) || (lynx -source /dev/null && echo lynx -source) ||
(fetch -o /dev/null file:///bin/sh && echo fetch -o -) || (fetch -o /dev/null file:///bin/sh && echo fetch -o -) ||
@ -124,6 +125,7 @@ get=$(
echo 'No lynx, wget, curl, fetch: Please file a bug report with which tool you use for downloading URLs' >&2 echo 'No lynx, wget, curl, fetch: Please file a bug report with which tool you use for downloading URLs' >&2
) )
# Use http instead of https to avoid dealing with self signed cert
$get http://"$DRAC_HOST"/software/avctKVM.jar > "$tmp" $get http://"$DRAC_HOST"/software/avctKVM.jar > "$tmp"
( (

View file

@ -1,9 +1,11 @@
#!/usr/bin/perl #!/usr/bin/perl
$timeout = shift || 10; use strict;
my $giga=2**30; my $timeout = shift || 10;
my $forks=1;
my $giga = 2**30;
my $forks = 1;
my $free; my $free;
@ -11,10 +13,13 @@ my $memtotal = int(
qx{ awk '/^(MemTotal):/ { sum += \$2} END { print sum }' /proc/meminfo } qx{ awk '/^(MemTotal):/ { sum += \$2} END { print sum }' /proc/meminfo }
/ 1024); / 1024);
$total = 1; my $total = 1;
$onemb = "x"x1048576;
do{ # 1 MB random data so it is not compressed
$start = time; my $onemb = pack("L*", map { rand(2**32) } 1..(2**18));
my ($missing, $sofar,$timediff, %buf, $pid,$shift);
do {
my $start = time;
$free = int ( $free = int (
qx{ awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += \$2} END { print sum }' /proc/meminfo } qx{ awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += \$2} END { print sum }' /proc/meminfo }
/ 1024); / 1024);
@ -26,21 +31,22 @@ do{
$total += int($free/100); $total += int($free/100);
$missing = $total - $sofar; $missing = $total - $sofar;
for(1..$missing) { for(1..$missing) {
$buf{$forks}{$total}{$_} = $onemb; # Shift every block 1 byte, so no blocks have the same content
$buf{$forks}{$total}{$_} = "x"x(++$shift) . $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 * 1048576 > $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;
print "child exit ",$forks,"\n"; print "child exit ",$forks,"\n";
} else { } else {
$buf{$forks}=1; $buf{$forks} = 1;
$forks++; $forks++;
} }
} }
} until ($pid or $timediff>$timeout or $total > $memtotal); } until ($pid or $timediff > $timeout or $total > $memtotal);
print "exit ",$forks,"\n"; print "exit ",$forks,"\n";

View file

@ -1,4 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl -w
=pod =pod
@ -44,8 +44,8 @@ Instead of overwriting I<file>, append to I<file>.
=head1 EXAMPLES =head1 EXAMPLES
(sleep 0.5; echo After 0.5s; sleep 1.5; echo After 2s) | teetime myfile (sleep 0.5; echo After 0.5s; sleep 1.5) | teetime myfile
(sleep 0.5; echo After 2.5s; sleep 1.5; echo After 4s) | teetime -a myfile (sleep 0.5; echo After 2.5s; sleep 1.5) | teetime -a myfile
teetime -i myfile teetime -i myfile
=head1 AUTHOR =head1 AUTHOR
@ -84,6 +84,8 @@ B<tee>
=cut =cut
use strict;
use Getopt::Long; use Getopt::Long;
sub now { sub now {
@ -110,18 +112,19 @@ sub readstdin {
my $rin = ''; my $rin = '';
my $in; my $in;
my $twogb = 2**31; my $twogb = 2**31;
my ($read, $time, $delta);
open(my $fh, ($opt::append ? ">>" : ">"), $file) || die; open(my $fh, ($opt::append ? ">>" : ">"), $file) || die;
vec($rin, fileno(STDIN), 1) = 1; vec($rin, fileno(STDIN), 1) = 1;
while(1) { while(1) {
select($rin,undef,undef,undef); select($rin,undef,undef,undef);
if(sysread(STDIN,$in,$twogb)) { $read = sysread(STDIN,$in,$twogb);
my $time = now(); $time = now();
my $delta = $time - $last_time; $delta = $time - $last_time;
print $fh pack("L*",$delta,length $in),$in; print $fh pack("L*",$delta,length $in),$in;
print STDOUT $in; print STDOUT $in;
$last_time = $time; $last_time = $time;
} else { if(not $read) {
# Select says there is something to read, # Select says there is something to read,
# but there is not => eof # but there is not => eof
last; last;
@ -136,7 +139,7 @@ sub readfile {
while(1) { while(1) {
my $in; my $in;
if(sysread($fh,$in,8)) { if(sysread($fh,$in,8)) {
($delta,$length) = unpack("L*",$in); my ($delta,$length) = unpack("L*",$in);
select(undef,undef,undef,$delta/1000); select(undef,undef,undef,$delta/1000);
sysread($fh,$in,$length); sysread($fh,$in,$length);
print $in; print $in;
@ -179,6 +182,15 @@ sub help() {
"",); "",);
} }
sub debug {
$opt::D or return;
@_ = grep { defined $_ ? $_ : "" } @_;
if($opt::D eq "all" or $opt::D eq $_[0]) {
print @_[1..$#_];
}
}
$|=1; $|=1;
$Global::progname = "teetime"; $Global::progname = "teetime";
$Global::version = "20200721"; $Global::version = "20200721";

View file

@ -32,7 +32,7 @@ Contact Ole Tange <ole@tange.dk>.
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2012 Ole Tange <ole@tange.dk>. Copyright (C) 2014-2020 Ole Tange <ole@tange.dk>.
=head1 LICENSE =head1 LICENSE
@ -65,6 +65,7 @@ B<ssh>(1)
=cut =cut
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure("bundling","require_order");
my @argv = @ARGV; my @argv = @ARGV;
get_options_from_array(\@ARGV,[]); get_options_from_array(\@ARGV,[]);