4/25/2007

Solaris Physical Memory

在机场। 这次出门要和solaris打交道,准备一下,看到这张图,顺手就贴了上来।

现在休息室,惊闻广播里找"Fan Jian Nan"। 服务员念的时候似乎有些犹豫,要不就是生疏,呵呵,效果更是搞笑了। 同情一下这位兄弟,不知道现在哪个角落喝可乐吧?:)

2 comments:

Yonghang Wang 说...

File I/O Paging: "Good" Paging
Traditional Solaris file systems (including UFS, VxFS, NFS, etc.) use the virtual memory system as the primary file cache (ZFS is an exception). We cover file systems caching in more detail in Section 14.8 in Solaris™ Internals.

File system I/O paging is the term we use for paging reads and writes files through file systems in their default cached mode. Files are read and written in multiples of page-size units to the I/O or to the network device backing the file system. Once a file page is read into memory, the virtual memory system caches that page so that subsequent file-level accesses don't have to reread pages from the device. It's normal to see a substantial amount of paging activity as a result of file I/O. Beginning with Solaris 8, a cyclic file system cache was introduced. The cyclic file system cache recirculates pages from the file system through a central pool known as the cache list, preventing the file system from putting excessive paging pressure on other users of memory within the system. This feature superseded the priority paging algorithms used in Solaris 7 and earlier to minimize these effects.

Paging can be divided into the following categories:

Reading files. File system reads that miss in the file cache are performed as virtual memory page-ins. A new page is taken off the free list, and an I/O is scheduled to fill the page from its backing store. Files read with the system call read(2) are mapped into the segmap cache and are eventually placed back onto the tail of the cache list. The cache list becomes an ordered list of file pages; the oldest cached pages (head of the cache list) are eventually recycled as file system I/O consumes new pages from the free list.

Smaller I/Os typically exhibit a one-to-one ratio between file system cache misses and page-ins. In some cases, however, the file system will group reads or issue prefetch, resulting in larger or differing relationships between file I/O and paging.

Writing files. The process of writing a file also involves virtual memory operationsupdated files are paged out to the backing I/O in multiples of page-size chunks. However, the reporting mechanism exhibits some oddities; for example, only page-outs that hint at discarding the page from cache show as file system page-outs in the kstat and vmstat statistics.

Reading executables. The virtual memory system reads executables (program binaries) into memory upon exec and reads shared libraries into a process's address space. These read operations are basically the same as regular file system reads; however, the virtual memory system marks and tracks them separately to make it easy to isolate program paging from file I/O paging.

Paging of executables is visible through vmstat statistics; executable page-ins, page-outs, and frees are shown in the epi, epo, and epf columns. File page-ins, page-outs, and frees are shown in the fpi, fpo, and fpf columns.

$ vmstat -p 3
memory page executable anonymous filesystem
swap free re mf fr de sr epi epo epf api apo apf fpi fpo fpf
411696 12720 38 35473 15738 0 217112 20 0 848 13 14146 14331 23 377 559
409356 35344 11 1823 9717 0 141771 104 0 22 96 9376 9389 62 295 306
345264 26724 53 5234 2329 0 8727 28 0 0 263 2200 2200 103 217 129
301104 48032 36 7313 8451 0 102271 76 0 75 167 8199 8241 15 157 135

Yonghang Wang 说...

Anonymous Memory Paging: "Bad" Paging
Anonymous memory paging is the term we use when the virtual memory system migrates anonymous pages to the swap device because of a shortage of physical memory. Most often, this occurs when the sum of the process heaps, shared memory, and stacks exceeds the available physical memory, causing the page scanner to begin shifting out to the swap device those pages that haven't recently been used. The next time the owning process references these pages, it incurs a data fault and must go to sleep while waiting for the pages to be brought back in from the swap device.

Anonymous paging is visible through the vmstat statistics; page-ins and page-outs are shown in the api and apo columns.

$ vmstat -p 3
memory page executable anonymous filesystem
swap free re mf fr de sr epi epo epf api apo apf fpi fpo fpf
411696 12720 38 35473 15738 0 217112 20 0 848 13 14146 14331 23 377 559
409356 35344 11 1823 9717 0 141771 104 0 22 96 9376 9389 62 295 306
345264 26724 53 5234 2329 0 8727 28 0 0 263 2200 2200 103 217 129
301104 48032 36 7313 8451 0 102271 76 0 75 167 8199 8241 15 157 135



Although swap I/O is just another form of file system I/O, it is most often much slower than regular file I/O because of the random movement of memory to and from the swap device. Pages are collected and queued to the swap device in physical page order by the page scanner and are efficiently issued to the swap device (clustering allows up to 1-Mbyte I/Os). However, the owning process typically references the pages semi-sequentially in virtual memory order, resulting in random page-size I/O from the swap device. We know from simple I/O metrics that random 8-Kbyte I/O is likely to yield service times of around 5 milliseconds, significantly affecting performance.