2 extern bool trimming_cycle;
3 Determines if we are trimming - if we are nearly out of space
5 static page_queue page_free_queue;
6 The queue that holds unused (but not cleared) pages
8 static page_queue page_clear_queue;
9 The queue that holds cleared (0'ed) pages
11 static page_queue page_modified_queue;
12 The queue that holds altered pages
14 static page_queue page_active_queue;
15 The queue that holds in use pages that are not altered
17 static vm_page *all_pages;
18 Every page in the system
20 static addr physical_page_offset;
21 The first address of real ram
23 static unsigned int num_pages;
24 Total number of pages in the system
26 static spinlock_t page_lock;
27 A lock to protect the queues.
29 static sem_id modified_pages_available;
30 A semaphore to indicate if there are pages that need to be written to disk
32 static void clear_page(addr pa);
33 Sets all values in this page to 0.
35 static vm_page * dequeue_page(page_queue *q)
36 Standard queue remove first page; has count; no locking
38 void dump_page_stats(int argc, char **argv);
39 Dumps counts of each state (active, inactive, busy, not used, modified, free, cleared, wired)
41 void dump_free_page_table(int argc, char **argv)
44 static 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
47 static bool is_page_in_phys_range(kernel_args *ka, addr paddr)
48 Determines if a physical address is in the physical memory that exists.
50 static 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.
53 static 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.
56 static 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.
59 static void remove_page_from_queue(page_queue *q, vm_page *page)
60 Removes a given page from the given page queue. No locking.
62 addr 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.
65 static 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.
68 static 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.
71 vm_page * vm_lookup_page(addr page_num)
72 Does the math to get vm_page pointer from a page number.
74 int vm_mark_page_inuse(addr page)
75 Calls vm_mark_page_range_inuse with len of 1.
77 int vm_mark_page_range_inuse(addr start_page, addr len)
78 Sets state to PAGE_STATE_UNUSED for all pages in this range.
80 vm_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.
83 vm_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
86 vm_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.
89 int vm_page_init(kernel_args *ka)
90 Initializes the free, clear, modified and active queues. Sets up the vm structures.
92 int vm_page_init2(kernel_args *ka)
93 Properly maps the vm structures allocated in vm_page_init.
95 int vm_page_init_postthread(kernel_args *ka)
96 Creates the page scrubber and the pageout daemon.
98 addr vm_page_num_pages()
99 Returns the total number of pages.
101 addr vm_page_num_free_pages()
102 Returns count of pages in free and clear queues.
104 int vm_page_set_state(vm_page *page, int page_state)
105 Locks, then calls vm_page_set_state_nolock, then unlocks.
107 static 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.