SwapBoost v0.1alpha – early testers wanted

By | 2007/07/02

So a few months ago I was visiting Georgia and had a pleasant dinner with a few guys from the Georgia Team. Somehow the topic of Windows Vista came up and some of the “cool” features that it had, one of which being an ability to add available space from an inserted USB drive to the virtual memory (swap). Well, I quickly outlined a plan in my head on how it *could* work, but never sat down to actually try it. Today I finally made time to try it.

After twenty minutes I had a basic implementation. Not very flexible, but it worked on the USB drive I plugged it. The first implementation took only 43 lines of bash code, much of that simply being echo output, so it could have been smaller.

After some more testing and expanding it now seems a little more solid. It’s a bit over 100 lines of bash code, with plenty of room to grow but I wanted to get some feedback from the general public. If you would like to help alpha test this application you can get a copy of the script below. If you’d like to help on this project I think there is plenty of improvement and could make for a good team project as well.

In any event, here is a basic outline of what it does and how to use it at this point. It may not be completely intuitive, but that is part of what I need feedback on. Below are three steps to increase your swap size by using excess space on a pluggable USB disk.

  1. Insert USB disk and allow gnome / KDE to auto-mount the device.
  2. Run ./swapboost.sh -n to create a new swap addition
  3. Check your system memory. Your swap should now be extended by the amount of free space on the device. (swapon -s will show you all available swap areas).

When you would like to make use of the disk again for that other than swap you can run the cleanup portion of the script by doing the following.

  1. Run ./swapboost.sh -d to delete added swap and safely unmount your USB disk.
  2. Check your system memory. Your swap should now be reduced by the amount of space previously added. (swapon -s will show you only your default swap area).

I’d love to get some feedback on this script. I know there are some features that need improving. A GUI would be great. The ability to select the size to expand the swap, instead of *only* the full size. A more intuitive launcher.. etc. The list can go on and on. Again, if you’d like to join this project I think it could be fun. If you’d simply like to give some feedback check out the v0.1alpha release below.

This release goes out to my boys in Georgia. Thanks for planting the seed.

Remember, this script is in alpha stage and the user assumes all responsibility for its potential lack of function. If this messes up your machine it is not my fault. Use at your own risk. (I had to get that out of the way. It most likely won’t really screw things up, but you never know at this stage.)

SwapBoost.sh v0.1alpha

53 thoughts on “SwapBoost v0.1alpha – early testers wanted

  1. Pingback: SwapBoost: Quick Fix for Your Slow Computer | Veritas/tic

  2. jdong

    Cool — note that if you are going to swap, it will drastically reduce the lifespan of your flash media; current flash media is not meant to be rapidly overwritten to in this fashion. Of course, with flash media so cheap and people owning several sticks (and losing them way before 100,000 rewrites), I doubt many people care 😀

  3. Martins Skele

    I just looked at your code. Even I could understand it.

    Is this ALL that readyboost does? There has to be more.

    It’s hard to believe that it could be this simple.

    Martins

  4. Pete

    From my understanding of this technology on Vista, it is nothing at all like swap space.

    What happens is that commonly needed, yet infrequently modified files are copied to the usb drive.

    These files are then used during boot and application startups. The additional drive takes load off of the disk. Since the system is already bottlenecked by IO from the hard disk, having the additional data source makes things faster.

    Plus, since the files on the usb disk are infrequently changed, this has no ill effects on the lifespan of the usb drive.

  5. Jeremy

    Agreed with jdong, this will kill your flash drive.

    I know you have a disclaimer already, but you might want to make a note of it being bad for the drive.

  6. mike

    That is nothing like readyboost, but might still be useful. Readyboost does pre-emptive caching, copies stuff that has not been used yet but likely will, to the usb stick.

    Sure, you can mimick that with building a statistics gathering daemon and some fs redirecting to the stick…

  7. Jeff Schroeder

    Well preload certainly works for your “statistics gathering daemon”.

  8. mike

    Indeed, I was aware of that. All that is missing is some plumbing to make it so that the applications will access the certain files from the flash disk instead of the normal hdd..

  9. Athropos

    Dont’ want to offend you, but I don’t really see the point of this. It’s surely useless from the point of view of providing additional space, and I’m really not sure whether it could provide any speed boost by using the flash memory.

  10. dtlin

    Linux swap is not suitable for flash drives at all. Please do not encourage its misuse.

  11. Alex

    Well /I/ think it’s a good idea. ReadyBoost is just swap + preload. That’s /really/ all this is too. ReadyBoosts performance boost is also questionable, it’s just proof of concept of how simple MS readyboost is. nj zelut.

  12. Marius Gedminas

    I wonder what would happen if you (intentionally or accidentally) pulled out the flash drive when it was being used as swap.

    I wouldn’t be surprised to get a kernel panic.

  13. lefty.crupps

    Cool app, I had this idea as well when I read about Vista’s ReadyBoost ‘technology’. ..

    some ideas and concerns:

    1. Would it be possible to offer to backup the data, and restore it when the swap part wasn’t needed? I would hate to plug in my drive for this purpose and not realize i was losing everything.

    2. It would be ‘desasterous’ if the USB was a vfat32 partition and this left unknowing users with a stick that didn’t function on their closed OSes (unless drivers were installed, but you get the idea)

    3. Do well-setup Linux systems really need an additional 128 or whatever of Swap? Memory shortfalls are a Windows issue, and it looks like Vista hasn’t fixed it, they just allow you to dynamically add space. Adding swap space from a hard drive is easy enough (but this doesn’t solve the hard drive bottleneck issues as discussed).

    4. There are graphical tools meant for Bash which may help you; an example is Zenity (Automatix uses it)

    I like the concept though and it may be useful…

  14. thomas

    Sooooo stupid idea… Ubuntu, when Windows does something ugly, please do not waste your time trying copying it… You want to boost boot ? Fix apps. Fix HAL, CUPS, X.org, Gnome, … Read “Why userspace sucks” here : http://trends.newsforge.com/article.pl?sid=06/07/21/192241

    “on boot, FC5 was touching 79,000 files and opening 26,000 of them. On shutdown, 23,000 files were touched, of which 7,000 were opened.”

    Arrggghhhh… 79.000 files !!!

  15. jdong

    Vista ReadyBoost has nothing to do with swap or paging — it uses flash media as a cache basically. Linux does not use swap to perform any caching.

    The ONLY time I would do this, is if I had 512MB of RAM and a 1GB flash drive, my root fs was damaged, and fsck requires 800MB of total memory to rebuild my filesystem. 😉

  16. Pingback: Featured Linux Download: Speed up your Linux box with a thumb drive

  17. Pingback: » Featured Linux Download: Speed up your Linux box with a thumb drive

  18. Pingback: Featured Linux Download: Speed up your Linux box with a thumb drive at SoftSaurus

  19. neil

    I’m sorry for this, but this is a horrendous idea.

    Flash media poorly suited for use as normal swap space (very slow, limited life span).

    Vista is doing something quite particular and different than what you do here.

  20. Pingback: Techzi » Blog Archive » Featured Linux Download: Speed up your Linux box with a thumb drive

  21. Pingback: SwapBoost, utiliza el espacio libre de tu llave usb como un espacio swap extra en Linux

  22. Pingback: CyberTopo » SwapBoost : Le ReadyBoost de Linux?

  23. Pingback: Linux Platense » Blog Archive » SwapBoost 0.1 Alpha

  24. Pingback: links for 2007-07-07 : Bob Plankers, The Lone Sysadmin

  25. Pingback: Ubuntu Life » Blog Archive » SwapBoost - Aumenta la memoria de Linux usando llaves USB

  26. Omid

    for mount points those included spaces it cannot works.

  27. gus3

    Bad for flash, agreed, and dangerous for swap safety (unplugging while active?). However, pre-emptive caching is not necessarily available only with flash. I have a shell script that runs when I log in to Gnome, containing the line:

    ( cd /usr/lib ; find firefox* openoffice.org2.0/program -type f -name \*.so ) | nice xargs cat > /dev/null &

    This finds all regular files and reads them, effectively loading their contents into file cache. This speeds up the launch of Firefox and OpenOffice.org noticeably. You can substitute your own files/directories.

    Note: this really works only if you don’t normally use swap during regular system usage. I have 768M, so I want to use filesystem cache. On a 256M system, it probably won’t work as well for lots of file data.

  28. gus3

    Oh, and by the way:

    I started doing this a couple years ago, before Vista even got its name.

    Nyah nyah nyah, Redmond!

  29. Pingback: Ampliando memoria facendo uso do pendrive :-) « Que che vou contar…

  30. Pingback: Un Readyboost anche per Linux ? « Re Riccardo

  31. Pingback: Linux tariamosios atminties pl?timas : nežinau.lt

  32. Pingback: bilgisayar-destek » Linux için ReadyBoost?

  33. David

    It would make more sense to modify readahead or “preload” for example to cache the often readaccessed files (e.g. libc,libstdc++, etc.). This best resembles “ReadyBoost” technology.

    Anyway, the swap-prefetch patches from Con Kolivas, which prefetches swap data back to RAM, makes much more sense than this script…

  34. Shane

    With your static swap in fstab give it a low priority. It will still be just as fast but allow you to sneak in higher priority swap later on. In the script make sure you can set which priority the USB swap device will be when you insert it.

    Sure, this will zap your flash drive eventually – whats with the new U3 flash tech however, what makes that more stable?

  35. Duh

    As I understand it, ReadyBoost is a cached copy of part of the swap intended to speed up small, random accesses. Paging in of an entire app, for example, would still come from the HD, but individual pages could be read from the flash drive as needed.

    If you have an app that requires more memory than your available RAM (think heavy number-crunching), and the memory accesses are random enough, then using a FLASH drive for swap should speed things up.

  36. trev0

    Hey, i feel a lot of people are being kind of dickish on this forum. Hell, he made it and I’d be interested to use it. it needs a little more fine tuning yes, maybe employing preload to tell it what to store (that way it acts basically just like readyboost). The only trouble I’m having is running the script which seems to be having several conflicting permission problems, both OS and harddrive. Good job man, way to try and come up with something new for linux!

    my recommendations:
    -interact with preload to boost preload space that will be fast
    -add a gui, basic is all thats needed, if a noob wanted to use this, they couldn’t
    -definitely adjustable space option
    -backup swap and in case of sudden removal, sub in back up so kernel doesn’t freak

    Flash drives will also be made better and more reliable in the next few years so software made on flash should be started now. I’d keep this project, despite the naysayers

  37. jarno

    Does linux use swap evenly? If so, how long does it take to write 200 terabytes(*) of data to it? If not, patching it should be a big deal, right?

    *) 50k*4G, is this number way off for some reason?

  38. Pingback: SWAPBOOST

  39. Corro69

    Considering just how inexspensive flash has become I feel the risk of killing the drive is a minimal bump to cross. RAM costs much more and we are limited by just how much can be added. If the usb swap can speed up my pc, even by an small amount, it is worth it; If for nothing less that saving on the wear and tear of my hard drive. And as an added bonus, I dont have to listen to the thrashing as often.
    Good deal

  40. Penguat

    I like that idea of something simple, a little script that will work with moreorless any linux, not just ubuntu, that perhaps wears out flashdrives, but they’re cheap, I’d rather wear ten of those out than one hard drive. Perhaps it’s the first in essentially a tree of dependancies, where a GUI is added, and it’s automated as part of whatever automates USB disk mounting and unmounting? Those are the next steps, but they can’t happen without someone trying it in the first place. Thankyou, because it has to start somewhere.

  41. Yuhong Bao

    Your SwapBoost solution is not really readyboost at all. You see ReadyBoost mirrors some of the info from the swap file into a file on the memory stick. Thus the info on the memory stick is still in the swap file on the HD in case the memory stick is pulled out. SwapBoost may crash your system if you pull the memory stick without unmounting.

  42. Yuhong Bao

    I don’t think it would be hard to make a Linux kernel patch that does this.

  43. Dialogue62

    I’ve got a couple of machines using CF Flash as hard drives. They’ve been working for about a year now without any problems. I am seeing comments about flash sticks not being able to handle the rewrites in this thread. Is this a weakness of the flash in USB sticks? If so, will your batch work with a CF? My laptop has a CF port and I’d like to try this.

  44. ilke.muhtaroglu@openSuSE_10.2

    Hi up,

    I have just did readyboost stuff by hand from

    http://www.arsgeek.com/2008/07/24/readyboost-for-linux-a-quick-how-to/

    I am a Turk SuSE user and planning to do this
    stuff in turkish on SuSE.

    I have worked as a testere before
    My Computer Arcitecture was good 😉

    I will write here, is there any problem occured till now ?

    just 2 idea; USB Burns out in >3 years and some extra space should be left at drive ?

    “Peace at home, peace at World” M.K. Atatürk

  45. ilke.muhtaroglu@openSuSE_10.2

    hi
    my probe crushes when i just plug-out the flash disk, it crushes 🙁

    how to solve this ?

  46. Pingback: Add Extra Swap Space To Your Linux Box with a USB drive | Linux Hacks

  47. akhil

    hey i vl diffinitely like 2 folow with ur projct…v are also doing same project as our academic proj…

  48. skary

    nice. appears to be working. I haven’t filled up my swap space yet but i’m sure that extra GB will help.

  49. Darren

    Just found this after doing it myself (and writing about it). If you are unable to add RAM, and have a slow HDD, swap on flash is great and makes a noticable difference to interactivity. A 4G flash drive is cheap, and even if it lasts only a year (unlikely), it can make some pain go away.

    Cheers

  50. Scott

    ReadyBoost is not swap. It uses the flash drive as a drive cache for small files so that your system doesn’t have to wait for the hard drive to spin up.

    ReadyBoost really does boost performance unless you’re fortunate enough to have a SSD instead of a regular HD with moving parts – most of us don’t. If you’re not sure you’ve got one, you probably don’t – a 16GB SSD will run you about $80.

    A system like ReadyBoost will help performance in any OS because it’s a drive cache – so basically, if you’ve got a 4GB flash drive, it can be turned into a 4GB cache for small files. It saves your computer from waiting for your HD to spin up (or spin to the correct location), and it also allows you to cache more files by only caching small files on the flash drive and caching anything else in memory.

    Note that ReadyBoost has a size limit for the files it caches – because flash drives are slower than SATA drives, aside from the fact that they respond immediately. So if the file’s smaller than a certain size, it’s faster to read it from the flash drive – but if not, then it’s faster to read it from the hard drive.

    In short, though – ReadyBoost is NOT swap memory, and using a flash drive like that will most likely slow your computer down. Not to mention – you cannot unplug a drive that’s being used for swap and not risk losing data, but unplugging a drive cache is no problem – it’s just a copy of what’s already written to the drive.

  51. JD

    Is it possible to do this in gnome and put the script in the nautilus-scripts folder in ~/.gnome2/nautilus-scripts? And if it is, how could i change the script to set the environment variable to the flash drive in /media.

Comments are closed.