xref: /haiku/docs/develop/kernel/vm/vm_daemon (revision 18a8edbf0eefdb04e81331c074d4a7b78abee552)
1Variables
2
3bool trimming_cycle;
4Do we need free space?
5
6static addr free_memory_low_water;
7
8static addr free_memory_high_water;
9
10static void scan_pages(vm_address_space *aspace, addr free_target)
11	Finds a region in this address space to scan.
12	Locks the region's cache_ref.
13	For each page,
14		if the page is present, do nothing with this page
15		Lookup the page structure. If this page doesn't exist, do nothing with this page.
16		If the page is written to or is hard wired (unswapable), do nothing with it.
17		If the page is not accessed and is active and we need space (free_target), unmap it. If this is the last reference to that mapped page, put it on the inactive list.
18		If the page has been modified, but wasn't on the active list, put it there.
19	Move to the next region in this address space, wrap around until we hit the first one.
20
21static int page_daemon()
22	Walk through every address space:
23		Adjust the size of the processes' working set (i.e. memory allocation) to be larger or smaller, to tailor to faults.
24		Set trimming cycle if free pages is below the high water mark.
25		Clear trimming cycle if free pages is above high water mark.
26		Set free memory target to be the processes' mapped size minus the working set
27		Call scan_pages
28
29
30int vm_daemon_init()
31	Sets high water to pages/4 and low water to pages/8.
32	Creates the page daemon as a kernel thread.
33