≡ Menu

hard disk

Linux: Should You Use Twice the Amount of Ram as Swap Space?

Linux and other Unix-like operating systems use the term "swap" to describe both the act of moving memory pages between RAM and disk, and the region of a disk the pages are stored on. It is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions. Now, many admins (both Windows and Linux/UNIX) follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. Let us say I've 32GB RAM, should I set swap space to 64 GB? Is 64 GB of swap space really required? How big should your Linux / UNIX swap space be?

Old dumb memory managers

I think the '2x swap space' rule came from Old Solaris and Windows admins. Also, earlier memory mangers were very badly designed. There were not very smart. Today, we have very smart and intelligent memory manager for both Linux and UNIX.

Nonsense rule: Twice the size of your main system RAM for Servers

According to OpenBSD FAQ:

Many people follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. This rule is nonsense. On a modern system, that's a LOT of swap, most people prefer that their systems never swap. You don't want your system to ever run out of RAM+swap, but you usually would rather have enough RAM in the system so it doesn't need to swap.

Select right size for your setup

Here is my rule for normal server (Web / Mail etc):

  1. Swap space == Equal RAM size (if RAM < 2GB)
  2. Swap space == 2GB size (if RAM > 2GB)

My friend who is a true Oracle GURU recommends something as follows for heavy duty Oracle server with fast storage such as RAID 10:

  1. Swap space == Equal RAM size (if RAM < 8GB)
  2. Swap space == 0.50 times the size of RAM (if RAM > 8GB)

Red Hat Recommendation

Red hat recommends setting as follows for RHEL 5:

The reality is the amount of swap space a system needs is not really a function of the amount of RAM it has but rather the memory workload that is running on that system. A Red Hat Enterprise Linux 5 system will run just fine with no swap space at all as long as the sum of anonymous memory and system V shared memory is less than about 3/4 the amount of RAM. In this case the system will simply lock the anonymous and system V shared memory into RAM and use the remaining RAM for caching file system data so when memory is exhausted the kernel only reclaims pagecache memory.

Considering that 1) At installation time when configuring the swap space there is no easy way to predetermine the memory a workload will require, and 2) The more RAM a system has the less swap space it typically needs, a better swap space

  1. Systems with 4GB of ram or less require a minimum of 2GB of swap space
  2. Systems with 4GB to 16GB of ram require a minimum of 4GB of swap space
  3. Systems with 16GB to 64GB of ram require a minimum of 8GB of swap space
  4. Systems with 64GB to 256GB of ram require a minimum of 16GB of swap space

Swap will just keep running servers...

Swap space will just keep operation running for a while on heavy duty servers by swapping process. You can always find out swap space utilization using any one of the following command:
cat /proc/swaps
swapon -s
free -m

See how to find out disk I/O and related information under Linux. In the end, you need to add more RAM, adjust software (like controlling Apache workers or using lighttpd web server to save RAM) or use some sort of load balancing.

Also, refer Linux kernel documentation for /proc/sys/vm/swappiness. With this you can fine tune swap space.

A note about Desktop and Laptop

If you are going to suspend to disk, then you need swap space more than actual RAM. For example, my laptop has 1GB RAM and swap is setup to 2GB. This only applies to Laptop or desktop but not to servers.

Kernel hackers need more swap space

If you are a kernel hacker (debugging and fixing kernel issues) and generating core dumps, you need twice the RAM swap space.


If Linux kernel is going to use more than 2GiB swap space at a time, all users will feel the heat. Either, you get more RAM (recommend) and move to faster storage to improve disk I/O. There are no rules, each setup and configuration is unique. Adjust values as per your requirements. Select amount of swap that is right for you.

What do you think? Please add your thoughts about 'swap space' in the comments below.

Record Labels To Sue SourceForge Open Source Project Hosting Platform

Consider this ... the stupidest example of law. From the blog post:

French record labels have received the green light to sue four US-based companies that develop P2P applications, including the BitTorrent client Vuze, Limewire and Morpheus. Shareaza is the fourth application, for which the labels are going after the open source development platform SourceForge.

By this logic they will sue hard disk manufacture companies (for providing data storage equipment) and ISPs (for transferring out P2P traffic). Putting aside the discussion on the responsibilities of application developers for their users activities, the decision to go after SourceForge for hosting a application that can potentially infringe, is stretching credibility beyond all bounds.

=> Record Labels to Sue Vuze, Limewire and SourceForge

Seagate Barracuda: 1.5TB Hard Drive Launched

Wow, this is a large size desktop hard disk for storing movies, tv shows, music / mp3s, and photos. You can also load multiple operating systems using vmware or other software for testing purpose. This hard disk comes with 5 year warranty and can transfer at 300MB/s. From the article:

It's been more than 18 months since Hitachi reached the terabyte mark with the Deskstar 7K1000. In that time, all the major players in the hard drive industry have spun up terabytes of their own, and in some cases, offered multiple models targeting different markets. With so many options available and more than enough time for the milestone capacity's initial buzz to fade, it's no wonder that the current crop of 1TB drives is more affordable than we've ever seen from a flagship capacity. The terabyte, it seems, is old news.

Fig.01: Seagate's Barracuda 7200.11 1.5TB hard drive

Fig.01: Seagate's Barracuda 7200.11 1.5TB hard drive

The real question is about reliability. How reliable is the hard disk? So far my Seagate 500GB hard disk working fine. I might get one to dump all my multimedia data / files :)

How To Avoid Sudden Outburst Of Backup Shell Script / Program Disk I/O

A sudden outburst of violent disk I/O activity can bring down your email or web server. Usually, a web / mysql or mail server serving millions and millions pages per months are prone to this kind of problem. Backup activity can increase current system load. To avoid this kind of sudden outburst problem, run your script with scheduling class and priority. Linux comes with various utilities to manage this kind of madness.
[click to continue…]

Linux Find SCSI Hard Disk Model, Serial Number, Size, and Total Sectors Information

Simply use utility called sdparm to fetch SCSI / SATA device information. Inquiry data including Vital Product Data (VPD) pages can also be displayed. Commands associated with starting and stopping the medium; loading and unloading the medium; and other housekeeping functions may also be performed by this utility.

In short you can get or set SCSI hard disk parameters. If you are using ATA ( IDE ) hard disk use hdparm utility.

Install sdparm utility

Type the following command at shell prompt:
# apt-get install sdparm
Red Hat / CentOS user can grab sdparm rpm package here.

sdparm examples

To list common mode parameters of a disk, enter:
# sdparm /dev/sda
To list the designators within the device identification VPD page of a disk:
# sdparm --inquiry /dev/sdb
To see all parameters for the caching mode page:
# sdparm --page=ca /dev/sdc
To set the "Writeback Cache Enable" bit in the current values page:
# sdparm --set=WCE /dev/sda

Further readings:

  • sdparm man page

Splashtop to Ship ASUS Motherboards With Linux Preinstalled On BIOS

Splashtop is a proprietary pre-boot environment, developed by DeviceVM, which allows you to rapidly access certain applications without the need to boot your main operating system. Splashtop boots out of the BIOS on your PC motherboard, and launches a lightweight Linux stack capable of running certain applications like the Splashtop web browser, and the Skype VOIP program. The Splashtop environment allow you to open a web browser, check email, watch videos, instant message, and place VOIP calls within seconds instead of minutes.

Splashtop is currently available only on the ASUS P5E3 Deluxe / WiFi AP motherboard. That motherboard is available most places where ASUS PC components can be purchased.

I've old Intel Celeron 1.7 with 512 MB and 3 x 80GB hard disk FreeSAN SAN device. I'm not thinking to get ASUS P5E3 Deluxe and add 3x 1TB to improve my home storage :)

My friend has this board (P5E3 Premium/WiFi-AP @n) and it has some crazy overclocking abilities. It also supports DDR3 RAM.

More information Linux's biggest victory so far - Splashtop to ship on ASUS motherboards

Linux Disk Benchmarking – IO Performance With fio Tool

You can use old good hdparm to find out how fast is your hard disk under Linux. There is another tool called Bonnie++ which is a benchmark suite that is aimed at performing a number of simple tests of hard drive and file system performance. Then you can decide which test is important and decide how to compare different systems after running it.

Linux.com has published article about a new tool called fio:

fio was created to allow benchmarking specific disk IO workloads. It can issue its IO requests using one of many synchronous and asynchronous IO APIs, and can also use various APIs which allow many IO requests to be issued with a single API call. You can also tune how large the files fio uses are, at what offsets in those files IO is to happen at, how much delay if any there is between issuing IO requests, and what if any filesystem sync calls are issued between each IO request. A sync call tells the operating system to make sure that any information that is cached in memory has been saved to disk and can thus introduce a significant delay. The options to fio allow you to issue very precisely defined IO patterns and see how long it takes your disk subsystem to complete these tasks.

=> Inspecting disk IO performance with fio