Page 273 - DCAP403_Operating System
P. 273
Operating System
Notes Figure 13.7: The Linux Page Cache
page_hash_table
mem_map_t mem_map_t
inode 12 inode 12
offset 0x8000 offset 0x2000
next_hash next_hash
: prev_hash prev_hash
:
:
Each file in Linux is identified by a VFS inode data structure and each VFS inode is unique and
fully describes one and only one file. The index into the page table is derived from the fi le’s VFS
inode and the offset into the fi le.
Whenever a page is read from a memory mapped file, for example when it needs to be brought
back into memory during demand paging, the page is read through the page cache. If the page is
present in the cache, a pointer to the mem_map_t data structure representing it is returned to the
page fault handling code. Otherwise the page must be brought into memory from the fi le system
that holds the image. Linux allocates a physical page and reads the page from the file on disk.
If it is possible, Linux will initiate a read of the next page in the file. This single page read ahead
means that if the process is accessing the pages in the file serially, the next page will be waiting
in memory for the process.
Over time the page cache grows as images are read and executed. Pages will be removed from
the cache as they are no longer needed, say as an image is no longer being used by any process.
As Linux uses memory it can start to run low on physical pages. In this case Linux will reduce
the size of the page cache.
13.5.12 Swapping Out and Discarding Pages
When physical memory becomes scarce the Linux memory management subsystem must attempt
to free physical pages. This task falls to the kernel swap daemon (kswapd).
The kernel swap daemon is a special type of process, a kernel thread. Kernel threads are processes
have no virtual memory, instead they run in kernel mode in the physical address space. The
kernel swap daemon is slightly misnamed in that it does more than merely swap pages out to the
system’s swap files. Its role is make sure that there are enough free pages in the system to keep
the memory management system operating effi ciently.
The Kernel swap daemon (kswapd) is started by the kernel init process at startup time and sits
waiting for the kernel swap timer to periodically expire.
266 LOVELY PROFESSIONAL UNIVERSITY