Where is the virtual memory stored on hard drive?
Solution 1
You can run swapon -s
to see what devices and files are being used for swap. For example, my scientific linux machine says:
[[email protected] ~]$ 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.
Solution 2
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.
Related videos on Youtube
JohnnyFromBF
Updated on September 18, 2022Comments
-
JohnnyFromBF over 1 year
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?
-
BatchyX about 11 yearsYes. Note that however, some other things are stored there, like hibernation state.
-
JohnnyFromBF about 11 yearsBut what if I do
swapoff
, where is it stored then? -
BatchyX about 11 yearsNowhere. Your OS will only run in memory, and if it gets full, future memory allocation will be denied and programs may get killed.
-