1Variables 2extern bool trimming_cycle; 3 Determines if we are trimming - if we are nearly out of space 4 5static page_queue page_free_queue; 6 The queue that holds unused (but not cleared) pages 7 8static page_queue page_clear_queue; 9 The queue that holds cleared (0'ed) pages 10 11static page_queue page_modified_queue; 12 The queue that holds altered pages 13 14static page_queue page_active_queue; 15 The queue that holds in use pages that are not altered 16 17static vm_page *all_pages; 18 Every page in the system 19 20static addr physical_page_offset; 21 The first address of real ram 22 23static unsigned int num_pages; 24 Total number of pages in the system 25 26static spinlock_t page_lock; 27 A lock to protect the queues. 28 29static sem_id modified_pages_available; 30 A semaphore to indicate if there are pages that need to be written to disk 31 32static void clear_page(addr pa); 33 Sets all values in this page to 0. 34 35static vm_page * dequeue_page(page_queue *q) 36 Standard queue remove first page; has count; no locking 37 38void dump_page_stats(int argc, char **argv); 39 Dumps counts of each state (active, inactive, busy, not used, modified, free, cleared, wired) 40 41void dump_free_page_table(int argc, char **argv) 42 Not done. 43 44static void enqueue_page(page_queue *q, vm_page *page) 45 Standard queue add a page; has count; no locking; SPECIAL - for page_modified_queue, if there is only one page modified (new one), release semaphore 46 47static bool is_page_in_phys_range(kernel_args *ka, addr paddr) 48 Determines if a physical address is in the physical memory that exists. 49 50static void move_page_to_queue(page_queue *from_q, page_queue *to_q, vm_page *page) 51 Removes the page from the from_q and adds it to the to_q. 52 53static int pageout_daemon() 54 aquires the "modified pages available" semaphore. Gets first page from modified list. Sets it to busy, updates all processes mapping this page that it is no longer a modified page, writes it out to disk, then puts it on the active list (i.e. not modified). Doesn't write out "anonymous" blocks unless we are trimming. 55 56static int page_scrubber(void *); 57 Every 1/10 second, takes a page from the free queue, memsets it to 0's, then puts it on the clear queue. 58 59static void remove_page_from_queue(page_queue *q, vm_page *page) 60 Removes a given page from the given page queue. No locking. 61 62addr vm_alloc_from_ka_struct(kernel_args *ka, unsigned int size, int lock) 63 Gets virtual space in the ka using vm_alloc_vspace_from_ka_struct, then uses vm_alloc_ppage_from_kernel_struct to find a physical page to map it to. 64 65static addr vm_alloc_ppage_from_kernel_struct(kernel_args *ka) 66 Attempts to extend, by one page, one of the phys_alloc_range blocks in the kernel args. 67 68static addr vm_alloc_vspace_from_ka_struct(kernel_args *ka, unsigned int size) 69 Attempts to find an address range that can be extended to hold size bytes. 70 71vm_page * vm_lookup_page(addr page_num) 72 Does the math to get vm_page pointer from a page number. 73 74int vm_mark_page_inuse(addr page) 75 Calls vm_mark_page_range_inuse with len of 1. 76 77int vm_mark_page_range_inuse(addr start_page, addr len) 78 Sets state to PAGE_STATE_UNUSED for all pages in this range. 79 80vm_page * vm_page_allocate_page(int page_state) 81 Gets a single page from the clear or free queue (from page_state), fall back to the other. 82 83vm_page * vm_page_allocate_page_run(int page_state, addr len) 84 Attempts to find a run of pages "len" long that are either free or clear. If found, pulls them from their queues and calls vm_page_set_state_nolock on them 85 86vm_page * vm_page_allocate_specific_page(addr page_num, int page_state) 87 Finds this page, removes it from the clear or free queue, clears it if necessary and returns. Returns NULL for not found or page in use. 88 89int vm_page_init(kernel_args *ka) 90 Initializes the free, clear, modified and active queues. Sets up the vm structures. 91 92int vm_page_init2(kernel_args *ka) 93 Properly maps the vm structures allocated in vm_page_init. 94 95int vm_page_init_postthread(kernel_args *ka) 96 Creates the page scrubber and the pageout daemon. 97 98addr vm_page_num_pages() 99 Returns the total number of pages. 100 101addr vm_page_num_free_pages() 102 Returns count of pages in free and clear queues. 103 104int vm_page_set_state(vm_page *page, int page_state) 105 Locks, then calls vm_page_set_state_nolock, then unlocks. 106 107static int vm_page_set_state_nolock(vm_page *page, int page_state); 108 Moves a page from the state that it is in to the state specified, and moves it from the old queue to the new one. 109 110 111 112 113