Swapless: Disabling Virtual Memory in Ubuntu
- 2012.05.14 - Tip Jar
Swap space. Swap files. Page files. Virtual memory. It's all pretty much the same thing: Extending your computer's physical system memory (RAM) by swapping data to and from your hard drive or SSD. For those of you with slow hard drives (or, more importantly, SSDs, which can have their lives shortened by overuse), swap space can be a real drag. (This applies to running your PC from a USB flash drive or a Compact Flash or SD memory card as well.)
Here's how to "drop the swap" and gain a little performance on a hard drive and a lot of life on an SSD.
Before proceeding, answer this quick question: Does your PC have at least 1 GB of RAM? If so, you can skip the rest of this. If not, well, I hate to tell you this, but unless you've got a really lightweight version of Ubuntu, you may encounter issues that could result in data loss.
Don't say I didn't warn you! As always, it's smart to back up your data.
Sorry to say it, but Windows is too dependent on virtual memory for this to work. However, I hear the "lovely" Windows 8 will use RAM more efficiently, so please put down the tomatoes!
The same goes for Mac OS X, but if you're using the Classic Mac OS, you can disable Virtual Memory from the Memory control panel.
If you want to see how your system will run without swap before making system changes, pick up GParted Partition Manager from the Ubuntu Software Center. In GParted, right click the partition that represents your swap, then click swapoff. If you want a Frankenstein-esque feeling, you can have System Monitor open during this whole process, so you can watch the available swap dropping until "not available" appears. Go ahead, do the mad scientist laugh - I judge not.
If you have any problems with the swap being totally off (like I did with my 1 GB-equipped T42, but not the 2 GB-equipped X41), don't sweat it. You can reduce the "swappiness" (the tendency of the kernel to move processes to swap space).
- Open the Terminal by pressing Ctrl-Alt-T
- Type gksudo gedit /etc/sysctl.conf
- Add the line vm.swappiness=10 to the bottom of the file
- Save and restart
Turning Off the Swap
If you check your memory usage and find you're not using any swap, even when you're at the height of your work (or gaming) time, you can probably follow the steps below if you're using a stock install of Ubuntu (i.e., one big boot partition and a smaller swap partition)
- Grab an Ubuntu LiveCD or Live USB and boot from it.
- Use GParted in the LiveCD/USB to delete the swap partition (I did this on the X41 with no problems).
- If you're really confident you won't need the swap, you can extend your main partition out to cover the old swap partition. Since my drive had an extra 1 MB of free space at the end, I only extended it to meet the free space rather than filling it up totally - not sure why, but hey, it can't hurt.
- Execute the partition changes.
- Shut down and boot from the hard drive or SSD.
When Things Go Wrong
The beauty of Ubuntu is that it's very forgiving. If the lack of swap ever gives you trouble, just boot from a LiveCD/USB and create a new swap partition. If the swappiness values give you trouble, just repeat the process, putting the value at its default 60 rather than 10.
For SSDs, this process should help extend their lives considerably, so it's well worth the risk.
Recent Low End PC Articles
- Windows 7 vs. Ubuntu 12.04 on a 2005 ThinkPad, 2012.07.09. Windows eats up more memory and has more consistent frame rates, while free Ubuntu is less memory hungry and easy to use.
- My Experiences with the Lenovo ThinkPad X120e, 2012.06.22. When his 13" MacBook Pro died, Alex Barnes replaced it with a $400 ThinkPad, which he says is no slouch.
- Keep Your PC Cool by Replacing Its Thermal Compound, 2012.06.15. Over time, thermal paste dries out and becomes less effective. Replacing it keeps you computer cool, thus increasing its life.
- ThinkPad X41 Revived, 2012.05.09. The ThinkPad X41 converts from a laptop to a tablet. More memory and Compact Flash gave this one a new lease on life.
- Pixels and Points, Screens and Paper, 2003.02.26. What you see on the screen corresponds to what you get on the printed page. A brief history of points, pixels, and the changing face of computer displays.
- More in the Low End PC index.
Recent Content on Low End Mac
- iPad 2 Stealing New iPad Sales?, iPhone Nearly One-Third of Smartphone Market, and More, iOS News Review, 2012.07.09. Also Bill Gates says Apple may need a Surface-like device, top 5 uses of tablets, Windows RT to displace Windows NT, and more.
- Life After PCs, Retina MacBook Has Better Color, $42 Portable USB Blu-ray Player, and More, The 'Book Review, 2012.07.06. Also Ultrabooks creating growth of higher price point notebooks, Lounge-Book laptop stands, security lock for Retina MacBook Pro, and more.
- Chrome or IE #1 Browser?, Will Kinect Leap Obsolete Mouse, Free Menubar Calendar, and More, Mac News Review, 2012.07.06. Dualing sources disagree on top 3 browser spots, Mac users spend more on long term care insurance, and more.
- Is Tech Really Racist?, Dan Knight, Mac Musings, 2012.07.05. The folks at Online IT Degree claim that tech 'seems to be' racist. Do their arguments hold water?
- The Lion Sleeps (on My MacBook) Tonight, John Hatchett, Recycled Computing, 2012.07.05. Starting with a full backup, a Time Machine Backup, and an OS X 10.7 thumb drive, John Hatchett moved to Lion.