>>>>> On Thu, 14 Mar 2002 07:25:27 -0500, Bill Marrs <[EMAIL PROTECTED]> said:

 >> It's copy-on-write.  The swap is a write-to-disk.
 >> There's no such thing as sharing memory between one process on disk(/swap)
 >> and another in memory.

  > agreed.   What's interesting is that if I turn swap off and back on
  > again, the sharing is restored!  So, now I'm tempted to run a crontab
  > every 30 minutes that  turns the swap off and on again, just to keep
  > the httpds shared.  No Apache restart required!

Funny, I'm doing this for ages and I never really knew why, you just
found the reason, Thank You! My concerns were similar to yours but on
a smaller scale, so I did not worry that much, but I'm running a
swapflusher regularly.

Make sure you have a recent kernel, because all old kernels up to
2.4.12 or so were extremely unresponsive during swapoff. With current
kernels, this is much, much faster and nothing to worry about.

Let me show you the script I use for the job. No rocket science, but
it's easy to do it wrong. Be careful to maintain equality of priority
among disks:

  use strict;

  $|=1;
  print "Running swapon -a, just in case...\n";
  system "swapon -a";
  print "Running swapon -s\n";
  open S, "swapon -s |";
  my(%prio);
  PARTITION: while (<S>) {
    print;
    next if /^Filename/;
    chop;
    my($f,$t,$s,$used,$p) = split;
    my $disk = $f;
    $disk =~ s/\d+$//;
    $prio{$disk} ||= 5;
    $prio{$disk}--;
    if ($used == 0) {
      print "Unused, skipping\n";
      next PARTITION;
    }
    print "Turning off\n";
    system "swapoff $f";
    print "Turning on with priority $prio{$disk}\n";
    system "swapon -p $prio{$disk} $f";
  }
  system "swapon -s";


Let me know if you see room for improvements,

Regards,
-- 
andreas

Reply via email to