Outils pour utilisateurs

Outils du site


issue48:labolinux

Ceci est une ancienne révision du document !


I am prompted by my co-podcaster and fellow columnist Ed Hewitt to amend a statement I made in File-systems Part 1, which stated that you won't get through a Linux install without defining a swap partition. Whilst most of the installers these days will let you through with a warning of how this is inadvisable, few will stop you in your tracks for this 'sin'. Let's step back for a moment. Why do I need a SWAP partition for Linux? Swap partitions are necessary for those computers which have less physical memory (RAM) than the applications need. Think of a swap partition as temporary storage which is used when all the physical memory is in use - with no further space for data and programs. Given the complex operating systems we now run, with advanced graphics, large programs, and multi-tasking, you can soon use your physical memory resources fully. In this case, the operating system will swap out some of the programs and data to temporary storage. With plenty of physical memory available, the swap partition may never be used and the space would be wasted. So the question is really 'how much RAM is in my machine, and do I ever fill it past capacity?' Answer yes, and you could benefit from a Swap partition. It may not be needed all the time, but it will help your computer from freezing at times of over-capacity.

How do I know if I need one or not? Apologies for answering a question with more questions, but what's your use-case? What's your operating system and your peak workload? Got a netbook, with 1GB RAM and Ubuntu Netbook edition; mostly surfing the web, writing emails, and the odd wordprocessed document? You may never fully use all the physical memory. Swap partition needed? No. However, jump onto Skype for a conference call with 50 tabs open in Firefox, you'll probably roll-over into Swap right there. Unless you're Ed and the whole thing locks up. Insert smiley face here. My old Toshiba Satellite has only 196MB RAM. Running a light-weight Linux such as Crunchbang or DSL for some light surfing, it's fine with no Swap. Step up to Lubuntu 10.10 with LibreOffice and Firefox running, now I roll over into Swap.

My Dell 6400 with 4GB RAM and a fully loaded Ubuntu 10.10 is fine with Firefox, Chrome, and OpenOffice multi-tasking together, using no Swap for whole sessions at a time. Launch Audacity sound editor, and OpenShot video editor for some work on the Podcast, and YouTube Hi-Definition, and I'm back into using Swap. Any machine running a current, full-size operating system (not a light-weight), with a small amount of physical memory, maybe 256MB or less, will need a Swap partition. As workload rises, with more programs open working on larger data files, you'll push through your maximum physical memory threshold - be it 512MB, 1GB, 2GB or higher - into Swap. Why a Whole Partition? There is an alternate approach to this 'virtual memory management,' it's called Page Files. In both Windows and some Linux configurations, page files reside on the main program- or data-partition, alongside all your other files. This is often considered, shall we say, sub-optimal, both for performance and for data security. Page files can be very large, demanding fast on-demand writes to disk. It can cause an Input/Output bottleneck, and when you've had a Windows pagefile trash a chunk of your active partition - losing precious data and programs, you appreciate the Linux approach - segregating Swap from everything else.

What size swap do I need? As we've seen, maybe none. When we do need one, the trick is to balance the use of smaller, faster RAM against slower larger disk, so that you (or rather the operating system kernel) get the best performance out of that combination. The truth is that - with modern kernels like we have in the Debian 2.6 family - memory management is a lot smarter. The old recommendation that swap should be between one-and-a-half and two times of the physical memory is probably over-generous for a desktop machine, but barely sufficient for a server. Setting a swap space between half and equal the amount of physical RAM should be adequate. If you have a laptop and set it to 'suspend' to disk, then you need swap space equal or greater than physical RAM. If in doubt, choose a larger swap, since a couple of gigabytes won't be missed - unless you have a Solid-State Drive, but that's another story… In Part Two, Virtual Memory Management, Swap-On, Swap-Off.

issue48/labolinux.1305746164.txt.gz · Dernière modification : 2011/05/18 21:16 de fredphil91