CSE 451: Introduction to Operating Systems

 

Section 8, May/17/2001

Jochen Jäger

 

 

 

 

 

 

 

1.    Project 3 turn-in

2.    Project 4 hand-out

3.    Paging

4.    Educational Assessment Survey

 

 


 

CR3 (or PDBR page-directory base register)

Bits 31 – 12: Physical address of the base of the page directory (thus page directory must be aligned to a page (4-KByte) boundary)

Bit 4,3: PCD, PWT: control caching of page directory in processor’s internal data caches L1, L2 (they do not control TLB caching)

 


source/include/linux/mm.h#134

 

typedef struct page {

         struct list_head list;

         struct address_space *mapping;

         unsigned long index;

         struct page *next_hash;

         atomic_t count;   // #users of this page (>1 è shared between processes)

         unsigned long flags;   // atomic flags, some possibly updated asynchronously

         struct list_head lru;

         unsigned long age;  // high age è good candidate for discarding or swapping

         wait_queue_head_t wait;

         struct page **pprev_hash;

         struct buffer_head * buffers;

         void *virtual; // non-NULL if kmapped

         struct zone_struct *zone;

} mem_map_t;


Figure 3.3: Three Level Page Tables

 

Each platform that Linux runs on must provide translation macros that allow the kernel to traverse the page tables for a particular process. This way, the kernel does not need to know the format of the page table entries or how they are arranged.

This is so successful that Linux uses the same page table manipulation code for the Alpha processor, which has three levels of page tables, and for Intel x86 processors, which have two levels of page tables.

 

 

Once an executable image has been memory mapped into a processes virtual memory it can start to execute. As only the very start of the image is physically pulled into memory it will soon access an area of virtual memory that is not yet in physical memory. When a process accesses a virtual address that does not have a valid page table entry, the processor will report a page fault to Linux.

no vm_area_struct èSIGSEGV signal

 

Linux must differentiate between pages that are in the swap file and those that are part of an executable image on a disk somewhere. It does this by using the page table entry for this faulting virtual address.

If the page's page table entry is invalid but not empty, the page fault is for a page currently being held in the swap file.

 

 

if not found è read page from file and also read next page (page read ahead)

 

 

Swapping Out and Discarding Pages

 

kernel swap daemon (kswapd) runs in physical address space as a kernel thread

 

Its role is make sure that there are enough free pages in the system to keep the memory management system operating efficiently.

 

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.

 

If below free_pages_high (free 3 pages) and  if below free_pages_low (free 6 pages and sleep only half of regular time) by:

 

Reducing the size of the buffer and page caches,

Swapping out System V shared memory pages (IPC),

Swapping out (to swap file) and discarding pages