Swap vrs Paging

Can anyone explain the difference between Paging and Swap in unix. I know over the years that the term has almost become interchangable.

However I have noticed in VMSTAT for a Solaris system that I am investigating that there is significant Paging but no Swapping and hence I am wondering do I have a RAM shortage or not.

My own understanding is that Paging is when individual parts ( i.e. pages ) of a process get swapped in/out whereas in swapping the entire process gets swapped in/out

Swapping came first and can be implemented on any cpu. Entire processes are loaded into core to run. And entire processes are written out. It is common to have a process split into segments... a read-only text segment and a writable data segment and often a writable stack segment. At swap-out time the text segment can be discarded. On many computers you can arrange for processes running the same program to share the text segment. This model arose during the 1970's. 128 kb was a very large memory for a cpu. 4 kb was a mid-sized process. So swapping was not super expensive.

Paging came after swapping and paging needs a cpu with a memory management unit (mmu). A process is started with zero or one pages in core. When a page is needed but is not in core, a page fault occurrs. The page is brought in as needed. Between risc architectures and 64 bit computing, processes are now too big for swapping to be useful. HP-UX will no longer swap ever. Some os'es still swap if paging wasn't cutting it. Any os that swapping is in deep trouble.

On Solaris, paging is used for data from data files too. The buffer cache is only for meta-data. This allows memory mapped data files processed with mmap() to be consistent with data files processed with read()/write().

Earlier this year I took Sun's performance tuning course. They made the point that scan-rate (sr in vmstat) is the metric to detect memory shortages. If it is zero, you have memory. Scan-rate is the number of pages examined to finf memory to free up.

thanks for the reply - very comprehensive ! :smiley: