Expert: Kenneth Gullberg Date: 12/7/2000 Subject: Paging in Unix
Question Hi,
I want to thank you for the tip on proctool. Really nice tool and freeware.
I don't understand the concept of paging. Why is it interesting to measure it?
//Mikael
Ps. I writing in English since I do not know if answers will be public.
Answer Hi!
Some background about how memory is handled is needed to understand why it is interesting to measure it.
<Snipped from Sun Performance and Tuning book by Adrian Cockroft & Richard Pettitt>
All the ram in a system is managed in the term of pages; these are used to hold the physical address space of a process. The kernel manages the virtual address space of a process by maintaining a compex set of data structures. Each process has a single-adderss space structure, with any number of segment data structures to map each contiguous segment of memory to a backing device, which holds the pages when they are not in ram.
The Life Cycle of a Typical Physical Memory Page
1. Initialization - A Page is born
When the system boots, all free memory is formed into pages, and a kernel data structure is allocated to hold the state of every page in the system.
2. Free - An Untouched Virgin Page
All the memory is put onto the free list to start with. At this stage, the content of the page is undefined
3. ZFOD - Joining a BSS Segment
When a program accesses a BSS segment for the very first time, a minor page fault occurs and a Zero Fill On Demand (ZFOD) operation takes place. The page is taken from the free list, block-cleared to contain all zeroes, and added to the list of anonymous pages for the BSS segment. The program then reads and writes data to the page.
4. Scanned - The pagedaemon Awakes
When the free list gets below a certain size, the pagedaemon starts to look for memory pages to steal from processes. It lokos at every page in physical memory order; when it gets to this page, the page is synchronized with the MMU and a reference bit is cleared.
5. Waiting - Is the program really using this page right now
There is a delay that varies depending upon how quickly the pagedaemon scans through memory. If the program references the page during this period, the MMU reference bit is set.
6. Page-out Time - Saving the contents
The pageout daemon returns and checks the MMU reference bit to find that the program has not used the page, so it can be stolen for reuse. The page is checked to see if anything had been written to it since it does contain data in this case; a page-out occurs. The page is moved to the page-out queue and marked as I/O pending. The swapfs code clusters the the page together with other pages on the queue and writes the cluster to the swap space. The page is the free and is put on the free list again. It remembers that it still contains the program data.
<END of Snip>
There are a few more steps available such as Page Reclaim, Page-In (Shared Code Segment) but these are not so important in understanding the overall picture, so keeping an eye on Paging activities is a good way of telling if you are running low on memory or not.
One thing to remember is that you should not panic if you see page-ins and page-outs in vmstat. It is quite normal to have some activity with these values. Hundreds or even thousands of kilobytes pagedin and out are not a cause of concern, just a sign that the system is working hard.
When you are really short on memory the sr (scanner) column in vmstat will be running continously at a high rate (over 200 pages/second averaged over 30 seconds).