Memory – Can Swap Space Accommodate a Single Process?

memoryswap

From what I understand, the swap space can be used to swap out inactive processes to free up memory. But can a single process take advantage of swap space? For example, if my system has little memory, but a large harddrive with large swap space, can a process requiring large amounts of memory still run (albeit slowly) by taking advantage of the large disk swap space? Is any action required on my part or will Linux automatically take care of this?

Best Answer

You don't have to do anything special, apart from providing swap space and mounting it.

For processors with a MMU (memory management unit, i.e. most processors since the early 90's) the full address space can be used, although there doesn't have to be real memory (RAM) at all address range locations. If some memory location is addressed, RAM will be "attached" using a lookup mechanism. If no free RAM is available, some block is freed up by writing its contents to the swap space.

Of course the processor keeps track of what memory address range was written out, so that when some address in that range is once more needed the right block is "swapped in" (most often after freeing up some other RAM by writing its contents out).

The actual detail for each operating system differ, and the article in wikipedia on paging is a good start if you want more information.

Be forewarned with what you try, competing swapping applications easily makes your system slower by a few orders of magnitude, making it look like your machine is dead.

Related Question