Is putting swap on a USB2 flashdrive practical?
Flash drives are slower. My SSD is older and half the speed of newer systems and my system is all SATA2 and USB2.
sudo hdparm -t /dev/sdd4
older SSD drive: Timing buffered disk reads: 626 MB in 3.01 seconds = 208.20 MB/sec
Older 160GB rotating drive: Timing buffered disk reads: 212 MB in 3.01 seconds = 70.46 MB/sec
USB2 flash drive Timing buffered disk reads: 50 MB in 3.07 seconds = 16.26 MB/sec
Or my flash drive is only 10% as fast for reading as my slow SSD. And writes are notoriously slow on flash drives.
You can set swappiness to use RAM first.
cat /proc/sys/vm/swappiness
gksudo gedit /etc/sysctl.conf
Add this:
vm.swappiness=10
https://help.ubuntu.com/community/SwapFaq#What_is_swappiness_and_how_do_I_change_it.3F
There is the swapspace or dynamic swap manager. Looks like not maintained, but still in repository of 12.04.
sudo apt-get install swapspace
http://pqxx.org/development/swapspace/
Smaller USB drive seek times are much faster as compared to an HDD, if you had one. The downside is that regular and sequential read/writes to the USB drive decrease the life of the drive itself. It is not as good as having proper RAM but at least it is far better than having Swap on the HDD.
To do so, delete all files uon the USB flash drive, so plug it in and unmount it by-
sudo umount /media/sdb1
to watch the disk label as we have used here sdb1 (yours might be different). Yse the following and make sure which one is your USB flash drive with the consideration of size, and sdb1 is just used here for exampling and explaining -
sudo fdisk -l
Now create swap on your USB flash drive by-
sudo mkswap /dev/sdb1
turn it on with
sudo swapon -p 32767 /dev/sdx1
to check it works
cat /proc/swaps
which will show both your swap on your booting drive and the USB Flash Drive as well.