xref: /netbsd-src/sys/uvm/uvm.h (revision f595094cfe0e17df2dcda1070f4b2263e9edfce3)
1*f595094cSriastradh /*	$NetBSD: uvm.h,v 1.78 2023/07/17 12:55:37 riastradh Exp $	*/
21f6b921cSmrg 
3f2caacc7Smrg /*
4f2caacc7Smrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
5f2caacc7Smrg  * All rights reserved.
6f2caacc7Smrg  *
7f2caacc7Smrg  * Redistribution and use in source and binary forms, with or without
8f2caacc7Smrg  * modification, are permitted provided that the following conditions
9f2caacc7Smrg  * are met:
10f2caacc7Smrg  * 1. Redistributions of source code must retain the above copyright
11f2caacc7Smrg  *    notice, this list of conditions and the following disclaimer.
12f2caacc7Smrg  * 2. Redistributions in binary form must reproduce the above copyright
13f2caacc7Smrg  *    notice, this list of conditions and the following disclaimer in the
14f2caacc7Smrg  *    documentation and/or other materials provided with the distribution.
15f2caacc7Smrg  *
16f2caacc7Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17f2caacc7Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18f2caacc7Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19f2caacc7Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20f2caacc7Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21f2caacc7Smrg  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22f2caacc7Smrg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23f2caacc7Smrg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24f2caacc7Smrg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25f2caacc7Smrg  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261f6b921cSmrg  *
271f6b921cSmrg  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
28f2caacc7Smrg  */
29f2caacc7Smrg 
30021fdb64Sperry #ifndef _UVM_UVM_H_
31021fdb64Sperry #define _UVM_UVM_H_
32021fdb64Sperry 
3367afbd62Smrg #if defined(_KERNEL_OPT)
34ad7a8740Sthorpej #include "opt_lockdebug.h"
35feb1d22dSthorpej #include "opt_multiprocessor.h"
36d9048520Smrg #include "opt_uvmhist.h"
37565a3d30Suebayasi #include "opt_uvm_page_trkown.h"
383d29b1e5Spk #endif
39d9048520Smrg 
40f2caacc7Smrg #include <uvm/uvm_extern.h>
41f2caacc7Smrg 
428169e469Smrg #ifdef _KERNEL
43f2caacc7Smrg #include <uvm/uvm_stat.h>
448169e469Smrg #endif
45f2caacc7Smrg 
46f2caacc7Smrg /*
47f2caacc7Smrg  * pull in prototypes
48f2caacc7Smrg  */
49f2caacc7Smrg 
50f2caacc7Smrg #include <uvm/uvm_amap.h>
51f2caacc7Smrg #include <uvm/uvm_aobj.h>
52f2caacc7Smrg #include <uvm/uvm_fault.h>
53f2caacc7Smrg #include <uvm/uvm_glue.h>
54f2caacc7Smrg #include <uvm/uvm_km.h>
55f2caacc7Smrg #include <uvm/uvm_loan.h>
56f2caacc7Smrg #include <uvm/uvm_map.h>
57f2caacc7Smrg #include <uvm/uvm_object.h>
58f2caacc7Smrg #include <uvm/uvm_page.h>
59f2caacc7Smrg #include <uvm/uvm_pager.h>
60f2caacc7Smrg #include <uvm/uvm_pdaemon.h>
61f2caacc7Smrg #include <uvm/uvm_swap.h>
62f2caacc7Smrg 
633479cf6bSthorpej #ifdef _KERNEL
643479cf6bSthorpej 
65609524ccScherry #include <uvm/uvm_physseg.h>
66f9d2ab17Sriastradh 
67f2caacc7Smrg /*
687fd701e0Sthorpej  * pull in VM_NFREELIST
697fd701e0Sthorpej  */
707fd701e0Sthorpej #include <machine/vmparam.h>
717fd701e0Sthorpej 
728bf76628Syamt struct workqueue;
739b1e2fa2Sad struct pgflcache;
748bf76628Syamt 
757fd701e0Sthorpej /*
76cbbf514eSad  * per-cpu data
77cbbf514eSad  */
78cbbf514eSad 
79cbbf514eSad struct uvm_cpu {
80364cbbd3Sad 	/* allocator */
819b1e2fa2Sad 	struct pgflcache *pgflcache[VM_NFREELIST];/* cpu-local cached pages */
829b1e2fa2Sad 	void		*pgflcachemem;		/* pointer to allocated mem */
839b1e2fa2Sad 	size_t		pgflcachememsz;		/* size of allocated memory */
849b1e2fa2Sad 	u_int		pgflcolor;		/* next color to allocate */
859b1e2fa2Sad 	u_int		pgflbucket;		/* where to send our pages */
86364cbbd3Sad 
8794843b13Sad 	/* uvmpdpol: queue of intended page status changes. */
8894843b13Sad 	struct vm_page	**pdq;			/* queue entries */
8994843b13Sad 	u_int		pdqhead;		/* current queue head */
9094843b13Sad 	u_int		pdqtail;		/* maximum number entries */
9194843b13Sad 	int		pdqtime;		/* last time queue cleared */
92cbbf514eSad };
93cbbf514eSad 
94cbbf514eSad /*
95f2caacc7Smrg  * uvm structure (vm global state: collected in one structure for ease
96f2caacc7Smrg  * of reference...)
97f2caacc7Smrg  */
98f2caacc7Smrg 
99f2caacc7Smrg struct uvm {
100f2caacc7Smrg 	/* vm_page related parameters */
101aeda8d3bSchs 
102f2caacc7Smrg 		/* vm_page queues */
1039ec517a6Sthorpej 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
1049b1e2fa2Sad 	u_int	bucketcount;
1059b1e2fa2Sad 	bool	page_init_done;		/* true if uvm_page_init() finished */
106aeda8d3bSchs 
107f2caacc7Smrg 		/* page daemon trigger */
108f2caacc7Smrg 	int pagedaemon;			/* daemon sleeps on this */
1094688843dSad 	struct lwp *pagedaemon_lwp;	/* daemon's lid */
110f2caacc7Smrg };
111f2caacc7Smrg 
11288ab7da9Sad /*
1134688843dSad  * kernel object: to support anonymous pageable kernel memory
1144688843dSad  */
1154688843dSad extern struct uvm_object *uvm_kernel_object;
1164688843dSad 
1174688843dSad /*
11888ab7da9Sad  * locks (made globals for lockstat).
11988ab7da9Sad  */
12088ab7da9Sad 
1214688843dSad extern kmutex_t uvm_kentry_lock;
12288ab7da9Sad 
1233479cf6bSthorpej #endif /* _KERNEL */
1243479cf6bSthorpej 
125d9048520Smrg /*
126f2caacc7Smrg  * vm_map_entry etype bits:
127f2caacc7Smrg  */
128f2caacc7Smrg 
129f2caacc7Smrg #define UVM_ET_OBJ		0x01	/* it is a uvm_object */
130a4d3b16dSchuck #define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
131a4d3b16dSchuck #define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
132a4d3b16dSchuck #define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
133f2caacc7Smrg 
134f2caacc7Smrg #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
135f2caacc7Smrg #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
136f2caacc7Smrg #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
137f2caacc7Smrg #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
138f2caacc7Smrg 
139abb48c5bSthorpej #ifdef _KERNEL
140abb48c5bSthorpej 
1412f159a1bSmrg /*
1422f159a1bSmrg  * holds all the internal UVM data
1432f159a1bSmrg  */
144061ecbffSchs extern struct uvm uvm;
145061ecbffSchs 
146061ecbffSchs /*
147061ecbffSchs  * historys
148061ecbffSchs  */
149061ecbffSchs 
150fbf49881Sperry #ifdef UVMHIST
151061ecbffSchs UVMHIST_DECL(maphist);
152061ecbffSchs UVMHIST_DECL(pdhist);
153aeda8d3bSchs UVMHIST_DECL(ubchist);
154f25d78c7Syamt UVMHIST_DECL(loanhist);
155dd07fed8Sperry #endif
156061ecbffSchs 
15752f0a628Syamt extern struct evcnt uvm_ra_total;
15852f0a628Syamt extern struct evcnt uvm_ra_hit;
15952f0a628Syamt extern struct evcnt uvm_ra_miss;
16052f0a628Syamt 
161f2caacc7Smrg /*
162b0afc900Sthorpej  * UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
163b0afc900Sthorpej  * interlocked tsleep() function.
164f2caacc7Smrg  */
165f2caacc7Smrg 
166b0afc900Sthorpej #define	UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo)		\
167b0afc900Sthorpej do {									\
1684a780c9aSad 	(void) mtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0),	\
169b0afc900Sthorpej 	    msg, timo, slock);						\
170dd07fed8Sperry } while (/*CONSTCOND*/ 0)
171f2caacc7Smrg 
1729d3e3eabSyamt void uvm_kick_pdaemon(void);
17327f66d3bSthorpej 
17427f66d3bSthorpej /*
175f2caacc7Smrg  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
176f2caacc7Smrg  */
177f2caacc7Smrg 
178f2caacc7Smrg #if defined(UVM_PAGE_TRKOWN)
179f2caacc7Smrg #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
180abb48c5bSthorpej #else
181f2caacc7Smrg #define UVM_PAGE_OWN(PG, TAG) /* nothing */
182f2caacc7Smrg #endif /* UVM_PAGE_TRKOWN */
183f2caacc7Smrg 
184a3af4c15Syamt #include <uvm/uvm_fault_i.h>
185a3af4c15Syamt 
18600ed0b8fSmatt #endif /* _KERNEL */
18700ed0b8fSmatt 
18800ed0b8fSmatt #endif /* _UVM_UVM_H_ */
189