xref: /openbsd-src/sys/uvm/uvm_anon.h (revision 19dcab733a71ecac0688127acdc039e90a471eba)
1*19dcab73Smpi /*	$OpenBSD: uvm_anon.h,v 1.22 2021/01/19 13:21:36 mpi Exp $	*/
21414b0faSart /*	$NetBSD: uvm_anon.h,v 1.13 2000/12/27 09:17:04 chs Exp $	*/
3cd7ee8acSart 
4cd7ee8acSart /*
5cd7ee8acSart  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6cd7ee8acSart  * All rights reserved.
7cd7ee8acSart  *
8cd7ee8acSart  * Redistribution and use in source and binary forms, with or without
9cd7ee8acSart  * modification, are permitted provided that the following conditions
10cd7ee8acSart  * are met:
11cd7ee8acSart  * 1. Redistributions of source code must retain the above copyright
12cd7ee8acSart  *    notice, this list of conditions and the following disclaimer.
13cd7ee8acSart  * 2. Redistributions in binary form must reproduce the above copyright
14cd7ee8acSart  *    notice, this list of conditions and the following disclaimer in the
15cd7ee8acSart  *    documentation and/or other materials provided with the distribution.
16cd7ee8acSart  *
17cd7ee8acSart  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18cd7ee8acSart  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19cd7ee8acSart  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20cd7ee8acSart  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21cd7ee8acSart  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22cd7ee8acSart  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23cd7ee8acSart  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24cd7ee8acSart  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25cd7ee8acSart  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26cd7ee8acSart  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27cd7ee8acSart  */
28cd7ee8acSart 
29cd7ee8acSart #ifndef _UVM_UVM_ANON_H_
30cd7ee8acSart #define _UVM_UVM_ANON_H_
31cd7ee8acSart 
32cd7ee8acSart /*
33cd7ee8acSart  * anonymous memory management
34cd7ee8acSart  *
35cd7ee8acSart  * anonymous virtual memory is short term virtual memory that goes away
36cd7ee8acSart  * when the processes referencing it go away.    an anonymous page of
37cd7ee8acSart  * virtual memory is described by the following data structure:
38cd7ee8acSart  */
39cd7ee8acSart 
40cd7ee8acSart struct vm_anon {
41*19dcab73Smpi 	struct rwlock *an_lock;
42*19dcab73Smpi 
43b8a635f6Stedu 	struct vm_page *an_page;	/* if in RAM */
44b8a635f6Stedu 	int an_ref;			/* reference count */
4560675802Sthib 
4660675802Sthib 	/*
47b8a635f6Stedu 	 * Drum swap slot # (if != 0) [if we hold an_page, PG_BUSY]
4860675802Sthib 	 */
4960675802Sthib 	int an_swslot;
50cd7ee8acSart };
51cd7ee8acSart 
52cd7ee8acSart /*
538d0b5bafSpedro  * for active vm_anon's the data can be in one of the following state:
548d0b5bafSpedro  * [1] in a vm_page with no backing store allocated yet, [2] in a vm_page
558d0b5bafSpedro  * with backing store allocated, or [3] paged out to backing store
568d0b5bafSpedro  * (no vm_page).
57cd7ee8acSart  *
58cd7ee8acSart  * for pageout in case [2]: if the page has been modified then we must
59cd7ee8acSart  * flush it out to backing store, otherwise we can just dump the
60cd7ee8acSart  * vm_page.
61cd7ee8acSart  */
62cd7ee8acSart 
63cd7ee8acSart /*
64cd7ee8acSart  * anons are grouped together in anonymous memory maps, or amaps.
65cd7ee8acSart  * amaps are defined in uvm_amap.h.
66cd7ee8acSart  */
67cd7ee8acSart 
68cd7ee8acSart /*
69cd7ee8acSart  * processes reference anonymous virtual memory maps with an anonymous
70cd7ee8acSart  * reference structure:
7160675802Sthib  * Note that the offset field indicates which part of the amap we are
7260675802Sthib  * referencing.
7360675802Sthib  * Locked by vm_map lock.
74cd7ee8acSart  */
75cd7ee8acSart 
76cd7ee8acSart struct vm_aref {
77cd7ee8acSart 	int ar_pageoff;			/* page offset into amap we start */
78cd7ee8acSart 	struct vm_amap *ar_amap;	/* pointer to amap */
79cd7ee8acSart };
80cd7ee8acSart 
81ab87c361Ssmart #ifdef _KERNEL
82c4071fd1Smillert struct vm_anon	*uvm_analloc(void);
8339ee2284Sbeck void		 uvm_anfree_list(struct vm_anon *, struct pglist *);
84*19dcab73Smpi void		 uvm_anon_release(struct vm_anon *);
854bfd0d76Sstefan void		 uvm_anwait(void);
86c4071fd1Smillert void		 uvm_anon_init(void);
87c4071fd1Smillert void		 uvm_anon_dropswap(struct vm_anon *);
88*19dcab73Smpi boolean_t	 uvm_anon_pagein(struct vm_amap *, struct vm_anon *);
89*19dcab73Smpi 
90*19dcab73Smpi #define		uvm_anfree(an)	uvm_anfree_list((an), NULL)
91*19dcab73Smpi 
92ab87c361Ssmart #endif /* _KERNEL */
93ab87c361Ssmart 
94cd7ee8acSart #endif /* _UVM_UVM_ANON_H_ */
95