Using USB flash as swap space.
Dan Farrell
dan at spore.ath.cx
Thu Aug 6 17:39:35 UTC 2009
On Mon, 03 Aug 2009 12:02:59 -0700
Ray Parrish <crp at cmc.net> wrote:
> Hello,
>
> I recently read an article that states that using a USB flash drive
> as swap space can help speed up a low memory system since the flash
> drive is faster than a hard drive.
I think this is a terrible idea. First of all, who says a flash drive
is faster than a hard drive? Maybe if it is cached, it is just as fast
as any cached data. Of course that won't help if you're low on memory
anyway. But I don't think flash drives can hold a candle to, say, a 5
year old 50MB/s hard drive.
These drives are on USB and if you can't use a modern memory stick
chances are you aren't going to see optimal USB speeds anyway. Even if
you were - and correct me, list, if I'm wrong - the max read speed on
usb2.0 is 48MB/s, isn't it?
Just for fun I used hdparm to see just how fast I could hope my cheap
little 4G flash drive could go with hdparm:
sudo hdparm -t /dev/sdf
I got 17.86 MB/sec.
Granted, that's a very cheap flash drive and probably not the highest
performance money can buy. Nevertheless, by comparison an old 40G drive
that happens to be in the computer goes 46.37MB/sec.
Of course, that's read speed. I would imagine that due to the nature
of swapping out of memory, you'd expect swap to be written just as much
as it is read. Write speeds are considerably slower. For example, I
tested mounting that same usb drive and using this command to write to
it:
sudo dd if=/dev/zero of=./test.file;
# wait...
Ctrl-C
dd said 28.3mb/s. however, I ran 'sync' afterwards to make sure the
data actually got written, and it took about 30 seconds of flash drive
blinking before sync completed. Not a very well done benchmark, but a
good reference point. By comparison, the same command into a file in
my home directory gave me 82.8 MB/sec - and although this surely isn't
true write speed of my hard drive, nevertheless sync returned
instantly.
My conclusion - this is a terrible idea.
Newegg has a recertified maxtor 40G hard drive for $20 right now. A
terrible, crappy, prone-to-failure hard drive -perfect for disposable
data like swap, IF you can tolerate your system locking up when your
swap drive dies. (That's what will happen when you computer can't swap
something essential back into memory)
Finally, are you sure swap space is the way to speed up your
system? I think you should consider cutting down on memory usage - if
possible, that is - before you think about switching your swap space
onto something "faster". Swap will never compare to memory speeds. If
you want help slimming things down, let us know. I'm sure these fine
ubuntu people (i mostly just pretend to be an ubuntu person, in
reality, preferring gentoo) can help you trim the fat as it were. In
particular, try a lightweight window manager. Fluxbox or similar
should save many megs of memory. Ditch gnome!
More information about the ubuntu-users
mailing list