Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


NR_FILE_MAPPED, /* pagecache pages mapped into pagetables.
only modified from process context */
NR_FILE_PAGES,
NR_FILE_DIRTY,
NR_WRITEBACK,
/* Second 128 byte cacheline */
NR_SLAB_RECLAIMABLE,
NR_SLAB_UNRECLAIMABLE,
NR_PAGETABLE, /* used for pagetables */
NR_UNSTABLE_NFS, /* NFS unstable pages */
NR_BOUNCE,
NR_VMSCAN_WRITE,
#ifdef CONFIG_NUMA
/* Omitted: NUMA-specific statistics */
#endif
NR_VM_ZONE_STAT_ITEMS };

The meanings of the entries are easy to guess from their names.NR_FILE_DIRTYspecifies the number
of file-based dirty pages, andNR_WRITEBACKindicates how many are currently being written back.
NR_PAGETABLEstores the number of pages used to hold the page tables, andNR_FILE_MAPPEDspecifies
how many pages are mapped by the page table mechanism (only the file-based pages are accounted for;
direct kernel mappings are not included). Finally,NR_SLAB_RECLAIMABLEandNR_SLAB_UNRECLAIMABLE
indicate how many pages are used for the slab cache described in Chapter 3 (despite their name, the con-
stants work also for the slub cache). The remaining entries consider special cases that are not interesting
for our purposes.


Note that the kernel not only keeps a global array to collect page statistics, but also provides the same
information resolved by memory zone:


<mmzone.h>
struct zone {
...
/* Zone statistics */
atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
...
}

It is the job of memory management to keep the global and zone-specific arrays up-to-date. Of prime
interest at this point is how the information is used. To gain a status overview of the entire system, it
is necessary to combine the information in the array entries to obtain not only CPU-specific data but
the data of the overall system. The kernel provides the auxiliary functionglobal_page_state,which
delivers the current value of a particular field ofvm_stat:


<vmstat.h>
unsigned long global_page_state(enum zone_stat_item item)

Because thevm_statarrays and their entries are not protected by a locking
mechanism, it may happen that the data change whileglobal_page_stateis
running. The result returned is not exact but an approximation. This is not a
problem because the figures are simply a general indication of how effectively work
is distributed. Minor differences between real data and returned data are acceptable.
Free download pdf