Linux内核


一旦内核初始化阶段结束,任何进程或内核进程都不直接使用主内核页表。


Pages of shared memory mappings are always included in the page cache; pages of private memory mappings are included in the page cache as long as they are unmodified. When a process tries to modify a page of a private memory mapping, the kernel duplicates the page frame and replaces the original page frame with the duplicate in the process Page Table; this is one of the applications of the Copy On Write mechanism that we discussed in . The original page frame still remains in the page cache, although it no longer belongs to the memory mapping since it is replaced by the duplicate. In turn, the duplicate is not inserted into the page cache because it no longer contains valid data representing the file on disk.



All pages belonging to the User Mode address space of processes or to the page cache are grouped into two lists called the active list and the inactive list ; they are also collectively denoted as LRU lists .




mm/swap.c
void fastcall lru_cache_add(struct page page)
{
struct pagevec
pvec = &get_cpu_var(lru_add_pvecs);
page_cache_get(page);
if (!pagevec_add(pvec, page))
__pagevec_lru_add(pvec);
put_cpu_var(lru_add_pvecs);
}
Since the function accesses a CPU-specific data structure, it must prevent the kernel from interrupting
execution and resuming later on another CPU. This form of protection is enabled implicitly by invoking
get_cpu_var, which not only disables preemption, but also returns the per-CPU variable.