Dear Wise Monks,
I am testing changes to my
limit.confon my RHEL4 system. I want to see what happens if I set my virtual memory very low ... like ...
$ ulimit -a ... virtual memory (kbytes, -v) 8192
... and then I run Perl script that fork's off some memory draining processes ... like so ...
$ cat swaphogger.pl #!/usr/bin/perl -w use strict; sub start_hogging_memory { my @blackhole; my $count = 0; print __FILE__ . " [" . __LINE__ . "] child [$$]\n"; open ( FH, "> ${0}_${$}.output" ) or die " could not open file +:$!\n"; my $swapon = `swapon -s | tail -1`; while ( 1 ) { chomp( $swapon ); print FH "[$swapon $count]\n"; push @blackhole, "$count ----------------------------- +------------------------------------------\n"; $count++; $swapon = `swapon -s | tail -1` # strangeness } close (FH); } my $maxChildren = shift; my $numChildren = 0; while ( $numChildren < $maxChildren ) { $numChildren++; my $pid = fork(); if ( $pid == 0 ) { start_hogging_memory (); } elsif ( $pid ) { print __FILE__ . " [" . __LINE__ . "] parent [$$]\n"; } else { die __FILE__ . " [" . __LINE__ . "] couldn't fork() :$ +!\n"; } }
The funny thing is that above code does NOT use up any swap! But if I comment out the line :
$swapon = `swapon -s | tail -1` # strangeness
... things work the way I would expect ....
$ ./swaphogger.pl 10 ./swaphogger.pl [8] child [2583] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2584] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2585] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2588] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2589] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2590] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2591] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2592] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2593] ./swaphogger.pl [30] parent [2582] ./swaphogger.pl [8] child [2594] ./swaphogger.pl [30] parent [2582] rcecala@eman-sjc1-001: Priority=4 scripts$ Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory! Out of memory!
Why does the line ...
... seem to fix my memory hole?$swapon = `swapon -s | tail -1` # strangeness
In reply to Swap hog - I do not understand this behavoir by Plankton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |