Paging vs. swapping
In my life I often get into discussions about Linux performance that end with someone saying "but paging is not swapping". This statement puts an end to the discussion because no one seems to know the difference. Time for a clarification.
First I want to tell you a usecase for this discussion: Your computer is slow and you want to know if it started swapping. If yes, you just increase the RAM size and everything is fine again. Using the command vmstat you can quickly find out if the damn machine did paging or swapping:
tweedleburg:~/sapvpn2.01 # vmstat 10 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 80 41508 192112 2163916 0 0 10 18 1 4 2 0 97 1 0 0 80 41700 192112 2163960 0 0 0 129 616 1108 1 0 98 1
You see - no paging, no swapping.
According to german wikipedia, the difference between swapping and paging is that paging swaps memory pages while swapping swaps the address space of complete processes. This seems to be bullshit.
According to a talk with colleagues, there is anonymous memory. This is memory that does not represent the content of a file. For example, executable loaded into memory or data files loaded into memory are non-anonymous. If the kernel needs memory, it can just delete these areas because it can reload them from disk. This is called paging - getting file content from disk to memory and writing out the dirty block to disk. Swapping is writing anonymous data (the web site that you just loaded) to disk and loading them again when needed.