A swap space primer

Swap Tricks

Article from ADMIN 09/2012
By
What happens when RAM runs out?

In Issue 7, you learned that free memory in Linux does not really exist [1]. The kernel employs all memory not in use by an application in a variety of useful activities, among which is caching the reads and buffering the writes of the storage subsystem. When an application is launched, memory pages are reclaimed from the caches for the application's own use. In the last issue, I also examined how to use the stress [2] tool to put arbitrary memory pressure on your test system. The next natural question is: What happens when memory runs out? That is, running applications are attempting to use more memory than the system possesses. An important distinction is that allocating pages alone is not sufficient; the Linux kernel is efficient, and memory pages have to be dirty with data to take up physical RAM.

When running processes request more than the system physically has, the swap space facility offers the kernel a solution for otherwise unmanageable demands. In Linux, swapping is completely transparent to the processes themselves, which typically remain unaware of where their memory pages reside. Because swapping memory pages to disk is conceptually the inverse of disk caching, then just as disk caching enhances system performance, swapping is detrimental to it, the disk being several orders of magnitude slower than RAM.

Unless the swapped pages belong to a steadily idling process or are not being used consistently, disk thrashing results as the system attempts to keep things running by continuously swapping pages in and out of RAM, bringing performance to a grinding halt.

The simplest way to investigate the configuration of swap space is to check /proc/swaps directly (Listing 1) or with the equivalent swapon -s.

...
Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=