# Where is the virtual memory stored on hard drive?

If a process wants to access a memory address that is not in physical memory, the OS outsources a page frame from physical memory to the hard drive for later use. Where on the hard drive is this data / instruction stored?

Is it stored on the swap partition?

-
Yes. Note that however, some other things are stored there, like hibernation state. –  BatchyX Mar 26 '13 at 14:11
But what if I do swapoff, where is it stored then? –  Ian Mar 26 '13 at 14:34
Nowhere. Your OS will only run in memory, and if it gets full, future memory allocation will be denied and programs may get killed. –  BatchyX Mar 26 '13 at 14:41

## 2 Answers

Pages of process memory may be displaced from the RAM to the disk. This is called swapping or paging (the terms are essentially synonymous). The data is moved to the swap space, and loaded back from the swap space when it is needed. Linux supports both partitions (and other block devices) and files as swap space.

If the page in question contains data that's been loaded from a file, then the data is not written to swap space if the page is to be reclaimed: it is simply erased from RAM. When the process needs the page again, the data is loaded back from that file.

-

You can run swapon -s to see what devices and files are being used for swap. For example, my scientific linux machine says:

[user@sl6.3 ~]\$ swapon -s
Filename                Type        Size    Used    Priority
/dev/sda3                               partition   8388600 833408  -1


So I'm using /dev/sda3 for swap. Also note the priority field that can be used to adjust the order in which swap pages are allocated (see man 2 swapon).

As some folks have stated, if you run out of swap (or have zero swap) the OOM Killer may start killing processes when physical memory gets low.

-