From b1bb72c63bcdbace6227bb5b91b1b6c5c33fe8c0 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Tue, 4 Aug 2020 23:11:40 +0200 Subject: [PATCH] swapout: Use random 1MB to avoid RAM compression. --- drac/drac | 10 ++++++---- swapout/swapout | 28 +++++++++++++++++----------- teetime/teetime | 34 +++++++++++++++++++++++----------- wssh/wssh | 3 ++- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/drac/drac b/drac/drac index 0f28689..2d47425 100755 --- a/drac/drac +++ b/drac/drac @@ -17,7 +17,7 @@ B [[I[:I]@]I] iDRAC6 uses a Java program to show the virtual console. From the iDRAC6 B 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 @@ -92,12 +92,12 @@ B uses B. B -' =cut read host user passwd < <(echo "$1" | + # parse [[user[:pass]@]host] perl -pe 's/^(?:(.*?)(?::(.*?))?@)?(.*?)$/$3 $1 $2/') - +# Set default values if [ "$user" = "" ] ; then DRAC_USER=${DRAC_USER:-root} else @@ -114,8 +114,9 @@ else DRAC_HOST="$host" fi -tmp=`tempfile` +tmp=$(tempfile) +# Find a command line tool to download with get=$( (lynx -source /dev/null && echo lynx -source) || (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 ) +# Use http instead of https to avoid dealing with self signed cert $get http://"$DRAC_HOST"/software/avctKVM.jar > "$tmp" ( diff --git a/swapout/swapout b/swapout/swapout index 86eac6d..fe0ef73 100755 --- a/swapout/swapout +++ b/swapout/swapout @@ -1,9 +1,11 @@ #!/usr/bin/perl -$timeout = shift || 10; +use strict; -my $giga=2**30; -my $forks=1; +my $timeout = shift || 10; + +my $giga = 2**30; +my $forks = 1; my $free; @@ -11,10 +13,13 @@ my $memtotal = int( qx{ awk '/^(MemTotal):/ { sum += \$2} END { print sum }' /proc/meminfo } / 1024); -$total = 1; -$onemb = "x"x1048576; -do{ - $start = time; +my $total = 1; + +# 1 MB random data so it is not compressed +my $onemb = pack("L*", map { rand(2**32) } 1..(2**18)); +my ($missing, $sofar,$timediff, %buf, $pid,$shift); +do { + my $start = time; $free = int ( qx{ awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += \$2} END { print sum }' /proc/meminfo } / 1024); @@ -26,21 +31,22 @@ do{ $total += int($free/100); $missing = $total - $sofar; 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; $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()) { + if($pid = fork()) { print "child spawn ",$forks,"\n"; wait; print "child exit ",$forks,"\n"; } else { - $buf{$forks}=1; + $buf{$forks} = 1; $forks++; } } -} until ($pid or $timediff>$timeout or $total > $memtotal); +} until ($pid or $timediff > $timeout or $total > $memtotal); print "exit ",$forks,"\n"; diff --git a/teetime/teetime b/teetime/teetime index 366a3db..2f95a5e 100755 --- a/teetime/teetime +++ b/teetime/teetime @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w =pod @@ -44,8 +44,8 @@ Instead of overwriting I, append to I. =head1 EXAMPLES - (sleep 0.5; echo After 0.5s; sleep 1.5; echo After 2s) | teetime myfile - (sleep 0.5; echo After 2.5s; sleep 1.5; echo After 4s) | teetime -a myfile + (sleep 0.5; echo After 0.5s; sleep 1.5) | teetime myfile + (sleep 0.5; echo After 2.5s; sleep 1.5) | teetime -a myfile teetime -i myfile =head1 AUTHOR @@ -84,6 +84,8 @@ B =cut +use strict; + use Getopt::Long; sub now { @@ -110,18 +112,19 @@ sub readstdin { my $rin = ''; my $in; my $twogb = 2**31; + my ($read, $time, $delta); open(my $fh, ($opt::append ? ">>" : ">"), $file) || die; vec($rin, fileno(STDIN), 1) = 1; while(1) { select($rin,undef,undef,undef); - if(sysread(STDIN,$in,$twogb)) { - my $time = now(); - my $delta = $time - $last_time; - print $fh pack("L*",$delta,length $in),$in; - print STDOUT $in; - $last_time = $time; - } else { + $read = sysread(STDIN,$in,$twogb); + $time = now(); + $delta = $time - $last_time; + print $fh pack("L*",$delta,length $in),$in; + print STDOUT $in; + $last_time = $time; + if(not $read) { # Select says there is something to read, # but there is not => eof last; @@ -136,7 +139,7 @@ sub readfile { while(1) { my $in; if(sysread($fh,$in,8)) { - ($delta,$length) = unpack("L*",$in); + my ($delta,$length) = unpack("L*",$in); select(undef,undef,undef,$delta/1000); sysread($fh,$in,$length); 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; $Global::progname = "teetime"; $Global::version = "20200721"; diff --git a/wssh/wssh b/wssh/wssh index eb64816..d0d09b7 100755 --- a/wssh/wssh +++ b/wssh/wssh @@ -32,7 +32,7 @@ Contact Ole Tange . =head1 AUTHOR -Copyright (C) 2012 Ole Tange . +Copyright (C) 2014-2020 Ole Tange . =head1 LICENSE @@ -65,6 +65,7 @@ B(1) =cut use Getopt::Long; +Getopt::Long::Configure("bundling","require_order"); my @argv = @ARGV; get_options_from_array(\@ARGV,[]);