Page 1 of 1

Swap file on USB flash drive

Posted: 19 Jun 2007, 12:42
by helder
Hi,

I have a somewhat busy bubba server, right now I have running on it:
  • Two small blogs (using pybloxom);
  • a https server for the webmail;
  • Postfix + Spamassassin + Cyrus (I'm used to the Cyrus server and it runs OK);
  • NFS server;
  • NIS server;
  • DNS server (caching only);
The problem is that 64MB is very little for all this, so I have a bit of swapping (not very much).

Is it worse to use a USB flash drive to store the swap partition? What are the consequences of a disk failure on the swap partition?

The flash drives are so cheap right now that I wouldn't mind changing them when the number of read/write cycles is over... Also, the seek time should be better on the flash drive.

Posted: 19 Jun 2007, 14:22
by Cheeseboy
Hi helder,

I don't think that would be a good idea due to the performance of the USB interface available. Wouldn't it be better to increase the size of the swap partition on your internal hard drive and put seldom accessed files on the USB drive?
Large files only accessed by slow remote network users every now and then would not suffer from the USB bottleneck. But if you put your system swap on it it would probably cripple the whole system...

My 2 cents...

Cheers

/Cheeseboy

Posted: 19 Jun 2007, 15:02
by bjorn
Hi,

Actually, a little swapping won't kill you, mostly it's untouched memory from applications that are swapped so system resources can be used more efficiently.
Do you experience any explicit setbacks due to the swapping?
Is all your memory actually "used" or is it "cache"? (cat /proc/meminfo)

There's a parameter called "swappiness" that has a range of 0-100 where 0 is no/little tendency to swap to disk, and 100 is high tenency to swap out stuff. The value defaults to 60 for most machines/kernels/systems, can be read through /proc/sys/vm/swappiness and changed in /etc/sysctl.conf (perhaps you can even echo a value to the /proc/-stuff directly, haven't tried. Search the net for proper howto).

But you can always streamline your system if you haven't already.

turn off any service you're not using, like mt-daap, samba, proftpd and so on.
use lighttpd with ssl-support instead of apache
consider dropping the dns cache, unless your ISPs nameservers are highly unreliable

Good luck :)

edit:
and oh, you can always try using flash for swap and share the experience


/Bjorn

Posted: 19 Jun 2007, 15:28
by tor
Hi,

You can also take a look at this short howto, if you have missed it, on tuning and analyzing performance: Howto tune performance (especially the vmstat part.) And as bjorn said, any shared experience in tuning is greatly appreciated.

/Tor

Posted: 19 Jun 2007, 17:41
by helder
Hi,

Has I've said the swapping is not very high. The thing is that I haven't had a machine like this for a long time and think it's funny to try to get the most out of it. I'm learning a lot!

I had already went through the how-to, and also had removed all the unneeded services. Installing lighttpd is a good idea, I'll try that in the future.

Now, my experience.

Even though I've been warned, I bravely ventured into the flash swap drive thing affair! I've managed to get a 1GB flash drive and did the following:

Warning this procedure gives you, at least a forced reboot :wink:
  • Changed the partition type of /dev/sda1 to 82 using fdisk;
  • Made a swap partition on it: mkswap /dev/sda1
  • Activated this swap: swapon /dev/sda1
  • Deactivated the original swap: swapoff /dev/hda2
So far so good. Next, to have the system to start using the swap I've issued this command from another machine:

Code: Select all

$ time ab -n 20 -c 15  http://www.bombolom.com/weblog
It swapped alright:

Code: Select all

$ vmstat 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
14  4 102084   4940    276   4776  335  750   590   760 2805   109 66 34  0  0
15 14 105824   1136    356   4572 1515  814  1808   817 5366   211 60 39  0  1
13 10 105064   5600    428   5584 1181  617  1713   626 4772   246 53 30  0 17
And then the machine stopped responding! No ping nothing! Even ssh was rude to me:

Code: Select all

$ ssh helder@192.168.10.25
You don't exist, go away!
I laughed with that message. :)

The same test using the normal swap partition went alright.

The post mortem revealed nothing, I went through syslog, kern.log, etc...

/var/log/messages had:

Code: Select all

Jun 19 21:24:02 macavity kernel: Adding 983272k swap on /dev/sda1.  Priority:-4 extents:1 across:983272k
Jun 19 21:30:25 macavity shutdown[14619]: shutting down for system reboot
Jun 19 21:31:47 macavity syslogd 1.4.1#17: restart.
At least it made a propper shutdown.

I've been looking hard at the vmstat output and bubba only trashes a bit when doing spam analysis spamd uses ~30% of the memory, but is very reasonable (~8 second per message).

OH well, it was only one idea!

Thanks,

Helder

Posted: 19 Jun 2007, 18:20
by Cheeseboy
Brave!
How did you change stuff back after sshd told you to piss off?

Cheers

Cheeseboy

Posted: 19 Jun 2007, 18:34
by Cheeseboy
Sorry,

What I meant was how did you manage to get access to your bubba without ssh?
Have you got a custom rs232 interface or something? Or have I missed something?

Any case above, please tell me about it, because I have some things I want to try as well, but I want to be able to recover the thing when I screw things up without having to mount the HDD in another PC.

Cheers

/Niklas

Posted: 19 Jun 2007, 22:08
by osa
Cheeseboy, if you mess to much with bubba it is posible to edit files without removing hdd :D You can use flash drive with modified bubba.img

When reinstalling bubba software with flash drive bubba.img is used to execute bubbainstall.sh script. The trick is, to modify that file to get telnet access and not format hard drive.

I have done it twice (don't ask why :D ) and is very simple

1. download bubba.img from update.excito.net
2. create loopback to that file /home/osa/downloads/bubba.img -> losetup -/dev/loop0 /home/osa/downloads/bubba.img
3. mount loop0 to /mnt -> mount /dev/loop0 /mnt
4. edit with vi /mnt/bin/bubbainstall.sh - comment or remove all lines (like format,partitioning, installing root files) and add your own if needed
5. edit /mnt/etc/network/interfaces to set static IP (not necessary)
6. umount /mnt
7. losetup -d /dev/loop0
8. place bubba.img on flash drive

After all, restart bubba and hold power button to enter rescue mode
Now you can login with telnet without any password !!

I think it would be great to have bubba.img for rescuing system with a lot of disk tools and utilities

Posted: 20 Jun 2007, 02:37
by Cheeseboy
Hi osa,

That sounds lovely!
I shall have to give it a try (biting my nails hard during the first attempt)...
I assume you are starting with the bubba.img that you got from Excito for "emergency reset to manufacturer settings and loose all data" scenario?
Not a backup USB image?

Cheers

Posted: 20 Jun 2007, 03:56
by helder
Cheeseboy wrote:How did you change stuff back after sshd told you to piss off?
Had to do a reboot, by using the bubba button on the back next to the power. Since I didn't change /etc/fstab, on reboot it loaded the normal swap partition.