Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Page_map Class Reference

The Page_map includes the page directory and all of the page tables. More...

#include <pagemap.h>

Inherits Address_map.

Inheritance diagram for Page_map:

Inheritance graph
[legend]
Collaboration diagram for Page_map:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void init (unsigned &last_available_address)
void map_page (void *virtual_page, void *physical_page)
unsigned * map_temp_page (unsigned *physical_page)
void unmap_temp_page (unsigned *virtual_page)
void unmap_page (void *virtual_page)
Hash_table< void *, void * > & get_dirty_pages ()
Hash_table< void *, void * > & get_dirty_pages_next ()
void switch_dirty_pages_hashes ()
void free_dirty_pages_next ()
bool handle_page_fault ()
void * virtual_to_physical_page (void *virtual_addr)
bool is_dirty (void *virtual_addr)
void add_dirty_page (void *dirty_page, void *physical_page=NULL, int index=-1)
void print ()

Static Public Member Functions

unsigned * table_entry_to_phys (unsigned page_entry)

Static Public Attributes

const unsigned PTE_USER = 0x4
const unsigned PTE_ACCESSED = 0x20
const unsigned PTE_PAGE_FRAME_ADDRESS = 0xfffff000
const unsigned DIRTY_PAGE_COPIED = 1
const unsigned CR0_PAGING = (1 << 31)
const unsigned CR0_RESPECT_READONLY = (1 << 16)

Protected Attributes

void * direct_mapped_end
unsigned * temp_mapping_cache
unsigned * first_free_temp_mapping
Mapping_cache_info mapping_cache_usage [MAPPING_CACHE_PAGE_COUNT]
Hash_table< void *, Mapping_cache_info * > mapping_cache_mappings
Hash_node< void *, Mapping_cache_info * > mapping_nodes [MAPPING_CACHE_PAGE_COUNT]
Int_handler handler
Hash_table< void *, void * > dirty_pages [2]
int dirty_pages_index
Slab_allocator dirty_pages_nodes [2]

Static Protected Attributes

const Size MAPPING_CACHE_PAGE_COUNT = 1024

Detailed Description

The Page_map includes the page directory and all of the page tables.


Member Function Documentation

void Page_map::add_dirty_page void *  dirty_page,
void *  physical_page = NULL,
int  index = -1
 

Add the given virtual page to the dirty pages map.

Normally, calling this function directly isn't necessary, as allocated pages start out read-only and thus end up in the dirty pages map when a write fault occurs. But for pages that don't start out as read-only and should be added to the dirty pages map later, use this function. Provide an optional physical page address for this page if it is already known. An optional index into the dirty_pages list can also be provided. If not specified, then dirty_pages_index is used.

void Page_map::free_dirty_pages_next  ) 
 

Free and clear the next dirty pages hash and prepare it for reuse.

Hash_table<void*, void*>& Page_map::get_dirty_pages  )  [inline]
 

Get a hash of pages that have been dirtied since the last checkpoint.

The hash maps virtual addresses of these pages to their current physical addresses.

Hash_table<void*, void*>& Page_map::get_dirty_pages_next  )  [inline]
 

Get a hash of pages that have been dirtied since the beginning of the current checkpoint, which will be written to disk during the next checkpoint.

You should only call this function during a checkpoint.

bool Page_map::handle_page_fault  ) 
 

Recover gracefully from a page fault interrupt.

void Page_map::init unsigned &  last_available_address  ) 
 

Create initial page directory and page tables and enable paging.

bool Page_map::is_dirty void *  virtual_addr  )  [inline]
 

Return whether the given address is dirty.

void Page_map::map_page void *  virtual_page,
void *  physical_page
 

Create a virtual to physical memory mapping for a single page, making a page table to contain the mapping if necessary.

If the virtual page is within the memory managed by the virtual memory allocator, then it will be mapped read-only so that writes to the page cause a write fault, thereby allowing dirtied pages to be logged.

unsigned * Page_map::map_temp_page unsigned *  physical_page  ) 
 

Map a page into the temporary mapping cache, a portion of virtual memory set aside specifically for temporarily mapping pages while they are being modified.

This avoids wasting virtual address space by keeping them mapped all the time. If the page is already mapped by another caller, then the page's ref count will simply be incremented. Return the virtual mapped address, or NULL if the temporary mapping cache is full.

void Page_map::print  ) 
 

Print out the state of the page map.

void Page_map::switch_dirty_pages_hashes  )  [inline]
 

Switch the two dirty_pages hash tables.

This is called at the end of a checkpoint so that the dirty pages hash that was recording pages dirtied during the checkpoint becomes the main dirty pages hash in use. The other dirty pages hash table then becomes available for use during the next checkpoint.

unsigned* Page_map::table_entry_to_phys unsigned  page_entry  )  [inline, static]
 

Convert a page table entry into the physical page frame address it contains.

void Page_map::unmap_page void *  virtual_page  ) 
 

Disable the page table entry for the given virtual page.

void Page_map::unmap_temp_page unsigned *  virtual_page  ) 
 

Given the physical address of a page already mapped into the temporary mapping cache, decrement its ref count.

If the ref count reaches zero, the virtual address will be made available for mappings to other physical pages.

void* Page_map::virtual_to_physical_page void *  virtual_addr  )  [inline]
 

Convert a virtual address to its corresponding physical page.


Member Data Documentation

const unsigned Page_map::CR0_PAGING = (1 << 31) [static]
 

const unsigned Page_map::CR0_RESPECT_READONLY = (1 << 16) [static]
 

ring 0 faults on read-only pages

void* Page_map::direct_mapped_end [protected]
 

end of direct-mapped 1-to-1 memory

const unsigned Page_map::DIRTY_PAGE_COPIED = 1 [static]
 

dirty page was copied-on-write

Hash_table<void*, void*> Page_map::dirty_pages[2] [protected]
 

map of dirty virtual pages to their corresponding physical pages, this is an array of two hashes because we alternate between the two: at any given time, one hash contains the pages dirtied since the start of the previous checkpoint, and the other hash contains the pages dirtied since the start of the current checkpoint (if one is actually happening now)

int Page_map::dirty_pages_index [protected]
 

index to current dirty pages hash

Slab_allocator Page_map::dirty_pages_nodes[2] [protected]
 

since the Hash_table class doesn't allocate hash nodes for us, the dirty_pages_nodes allocator serves this purpose

unsigned* Page_map::first_free_temp_mapping [protected]
 

first available temp mapping

Int_handler Page_map::handler [protected]
 

page fault interrupt handler

Hash_table<void*, Mapping_cache_info*> Page_map::mapping_cache_mappings [protected]
 

phys addr table for mapping cache

const Size Page_map::MAPPING_CACHE_PAGE_COUNT = 1024 [static, protected]
 

Mapping_cache_info Page_map::mapping_cache_usage[MAPPING_CACHE_PAGE_COUNT] [protected]
 

page usage info for mapping cache

Hash_node<void*, Mapping_cache_info*> Page_map::mapping_nodes[MAPPING_CACHE_PAGE_COUNT] [protected]
 

nodes of phys addr table

const unsigned Page_map::PTE_ACCESSED = 0x20 [static]
 

const unsigned Page_map::PTE_PAGE_FRAME_ADDRESS = 0xfffff000 [static]
 

const unsigned Page_map::PTE_USER = 0x4 [static]
 

unsigned* Page_map::temp_mapping_cache [protected]
 

start of temporary mapping cache


The documentation for this class was generated from the following files:

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman