xref: /haiku/docs/develop/kernel/vm/VM_Locking (revision a127b88ecbfab58f64944c98aa47722a18e363b2)
1Locks/Reference Counting:
2
3vm_address_space:
4	sem R/W for area creation/deletion and any other address space changes
5	fields: areas, area_hint (is currently written in vm_area_lookup() without a write lock!),
6		state
7	ref_count: ensures validity of object beyond team lifetime,
8		retrieved via the global sAddressSpaceTable's pointer (which is guarded by
9			sAddressSpaceHashSem)
10		vm_address_space_walk_next() is unsafe! (and obsolete, only used by the former
11			page scanner)
12	Problems: resize_area() does not lock any address spaces yet, but needs to lock all clones
13
14vm_area:
15	ref_count: ensures validity
16		retrieved via the global sAreaHash's pointer (which is guarded by
17			sAreaHashLock)
18		vs. vm_area_lookup() which iterates over the address space's area list, not
19			the hash - therefore, it checks ref_count against NULL (ugly)
20	variable fields:
21		size, protection: essentially unguarded! (can be changed by resize_area()
22			and set_area_protection())
23		mappings: guarded by the global sMappingLock (currently a spinlock)
24		address_space_next: vm_address_space::sem
25		hash_next: sAreaHashLock
26		cache: guarded by vm_area_get_locked_cache()/sAreaCacheLock
27		cache_next|prev: cache_ref::lock
28
29vm_cache_ref:
30	ref_count: ensures validity
31		vm_cache_remove_consumer(): does scary things with the ref_count
32		fault_acquire_locked_source(): tries to get a ref through the vm_cache
33	cache, areas: guarded by lock
34
35vm_cache:
36	all fields: guarded by ref::lock
37	BUT: ref may change, therefore it's generally unsafe to go from cache to ref
38		without holding the ref's lock (which happens, by design, in vm_cache::source
39		and vm_cache::consumers)!
40
41vm_page:
42	hash_next: guarded by sPageCacheTableLock spinlock
43	queue_prev|next: guarded by sPageLock
44	cache_prev|next, cache, cache_offset: guarded by vm_cache_ref::lock
45	mappings: guarded by the global sMappingLock (currently a spinlock)
46	state: in vm_page only used with the sPageLock held, other uses have the
47		cache locked the page is in
48	wired_count, usage_count: not guarded? TBD
49	busy_reading, busy_writing: dummy pages only
50
51vm_translation_map:
52	TBD.
53