xref: /netbsd-src/sys/uvm/uvm_param.h (revision 3e51e50883710f1a1c6aa8ce9466cfdcc4c331a7)
1*3e51e508Sriastradh /*	$NetBSD: uvm_param.h,v 1.42 2023/07/11 09:48:56 riastradh Exp $	*/
24c698e84Smrg 
34c698e84Smrg /*
44c698e84Smrg  * Copyright (c) 1991, 1993
54c698e84Smrg  *	The Regents of the University of California.  All rights reserved.
64c698e84Smrg  *
74c698e84Smrg  * This code is derived from software contributed to Berkeley by
84c698e84Smrg  * The Mach Operating System project at Carnegie-Mellon University.
94c698e84Smrg  *
104c698e84Smrg  * Redistribution and use in source and binary forms, with or without
114c698e84Smrg  * modification, are permitted provided that the following conditions
124c698e84Smrg  * are met:
134c698e84Smrg  * 1. Redistributions of source code must retain the above copyright
144c698e84Smrg  *    notice, this list of conditions and the following disclaimer.
154c698e84Smrg  * 2. Redistributions in binary form must reproduce the above copyright
164c698e84Smrg  *    notice, this list of conditions and the following disclaimer in the
174c698e84Smrg  *    documentation and/or other materials provided with the distribution.
18aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
194c698e84Smrg  *    may be used to endorse or promote products derived from this software
204c698e84Smrg  *    without specific prior written permission.
214c698e84Smrg  *
224c698e84Smrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234c698e84Smrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244c698e84Smrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254c698e84Smrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264c698e84Smrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274c698e84Smrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284c698e84Smrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294c698e84Smrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304c698e84Smrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314c698e84Smrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324c698e84Smrg  * SUCH DAMAGE.
334c698e84Smrg  *
344c698e84Smrg  *	@(#)vm_param.h	8.2 (Berkeley) 1/9/95
354c698e84Smrg  *
364c698e84Smrg  *
374c698e84Smrg  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
384c698e84Smrg  * All rights reserved.
394c698e84Smrg  *
404c698e84Smrg  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
414c698e84Smrg  *
424c698e84Smrg  * Permission to use, copy, modify and distribute this software and
434c698e84Smrg  * its documentation is hereby granted, provided that both the copyright
444c698e84Smrg  * notice and this permission notice appear in all copies of the
454c698e84Smrg  * software, derivative works or modified versions, and any portions
464c698e84Smrg  * thereof, and that both notices appear in supporting documentation.
474c698e84Smrg  *
484c698e84Smrg  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
494c698e84Smrg  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
504c698e84Smrg  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
514c698e84Smrg  *
524c698e84Smrg  * Carnegie Mellon requests users of this software to return to
534c698e84Smrg  *
544c698e84Smrg  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
554c698e84Smrg  *  School of Computer Science
564c698e84Smrg  *  Carnegie Mellon University
574c698e84Smrg  *  Pittsburgh PA 15213-3890
584c698e84Smrg  *
594c698e84Smrg  * any improvements or extensions that they make and grant Carnegie the
604c698e84Smrg  * rights to redistribute these changes.
614c698e84Smrg  */
624c698e84Smrg 
634c698e84Smrg /*
644c698e84Smrg  *	Machine independent virtual memory parameters.
654c698e84Smrg  */
664c698e84Smrg 
674c698e84Smrg #ifndef	_VM_PARAM_
684c698e84Smrg #define	_VM_PARAM_
694c698e84Smrg 
70df0a9badSatatat #ifdef _KERNEL_OPT
71081df643Smatt #include "opt_modular.h"
72df0a9badSatatat #include "opt_uvm.h"
73df0a9badSatatat #endif
74cce919e0Smatt #ifdef _KERNEL
755ea0e70cShe #include <sys/types.h>
764c698e84Smrg #include <machine/vmparam.h>
77cce919e0Smatt #endif
784c698e84Smrg 
7973606572Sthorpej #if defined(_KERNEL)
804c698e84Smrg 
8173606572Sthorpej #if defined(PAGE_SIZE)
8273606572Sthorpej 
834c698e84Smrg /*
8473606572Sthorpej  * If PAGE_SIZE is defined at this stage, it must be a constant.
854c698e84Smrg  */
8673606572Sthorpej 
8773606572Sthorpej #if PAGE_SIZE == 0
8873606572Sthorpej #error Invalid PAGE_SIZE definition
8973606572Sthorpej #endif
9073606572Sthorpej 
9173606572Sthorpej /*
9273606572Sthorpej  * If the platform does not need to support a variable PAGE_SIZE,
9373606572Sthorpej  * then provide default values for MIN_PAGE_SIZE and MAX_PAGE_SIZE.
9473606572Sthorpej  */
9573606572Sthorpej 
9673606572Sthorpej #if !defined(MIN_PAGE_SIZE)
9773606572Sthorpej #define	MIN_PAGE_SIZE	PAGE_SIZE
9873606572Sthorpej #endif /* ! MIN_PAGE_SIZE */
9973606572Sthorpej 
10073606572Sthorpej #if !defined(MAX_PAGE_SIZE)
10173606572Sthorpej #define	MAX_PAGE_SIZE	PAGE_SIZE
10273606572Sthorpej #endif /* ! MAX_PAGE_SIZE */
10373606572Sthorpej 
10473606572Sthorpej #else /* ! PAGE_SIZE */
10573606572Sthorpej 
10673606572Sthorpej /*
10773606572Sthorpej  * PAGE_SIZE is not a constant; MIN_PAGE_SIZE and MAX_PAGE_SIZE must
10873606572Sthorpej  * be defined.
10973606572Sthorpej  */
11073606572Sthorpej 
11173606572Sthorpej #if !defined(MIN_PAGE_SIZE)
11273606572Sthorpej #error MIN_PAGE_SIZE not defined
11373606572Sthorpej #endif
11473606572Sthorpej 
11573606572Sthorpej #if !defined(MAX_PAGE_SIZE)
11673606572Sthorpej #error MAX_PAGE_SIZE not defined
11773606572Sthorpej #endif
11873606572Sthorpej 
11973606572Sthorpej #endif /* PAGE_SIZE */
12073606572Sthorpej 
12173606572Sthorpej /*
12273606572Sthorpej  * MIN_PAGE_SIZE and MAX_PAGE_SIZE must be constants.
12373606572Sthorpej  */
12473606572Sthorpej 
12573606572Sthorpej #if MIN_PAGE_SIZE == 0
12673606572Sthorpej #error Invalid MIN_PAGE_SIZE definition
12773606572Sthorpej #endif
12873606572Sthorpej 
12973606572Sthorpej #if MAX_PAGE_SIZE == 0
13073606572Sthorpej #error Invalid MAX_PAGE_SIZE definition
13173606572Sthorpej #endif
13273606572Sthorpej 
13373606572Sthorpej /*
13473606572Sthorpej  * If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
1354cd80e92Sskrll  * non-constant PAGE_SIZE, et al for modules.
13673606572Sthorpej  */
137081df643Smatt #if (MIN_PAGE_SIZE != MAX_PAGE_SIZE)
138081df643Smatt #define	__uvmexp_pagesize
1394cd80e92Sskrll #if defined(_MODULE)
14073606572Sthorpej #undef PAGE_SIZE
14173606572Sthorpej #undef PAGE_MASK
14273606572Sthorpej #undef PAGE_SHIFT
14373606572Sthorpej #endif
144081df643Smatt #endif
14573606572Sthorpej 
14673606572Sthorpej /*
14773606572Sthorpej  * Now provide PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT if we do not
14873606572Sthorpej  * have ones that are compile-time constants.
14973606572Sthorpej  */
15073606572Sthorpej #if !defined(PAGE_SIZE)
151a1994013Smatt extern const int *const uvmexp_pagesize;
152a1994013Smatt extern const int *const uvmexp_pagemask;
153a1994013Smatt extern const int *const uvmexp_pageshift;
154c9ff0b16Suebayasi #define	PAGE_SIZE	(*uvmexp_pagesize)	/* size of page */
155c9ff0b16Suebayasi #define	PAGE_MASK	(*uvmexp_pagemask)	/* size of page - 1 */
156c9ff0b16Suebayasi #define	PAGE_SHIFT	(*uvmexp_pageshift)	/* bits to shift for pages */
15773606572Sthorpej #endif /* PAGE_SIZE */
15873606572Sthorpej 
1594c698e84Smrg #endif /* _KERNEL */
1604c698e84Smrg 
1614c698e84Smrg /*
1624c698e84Smrg  * CTL_VM identifiers
1634c698e84Smrg  */
1644c698e84Smrg #define	VM_METER	1		/* struct vmmeter */
1654c698e84Smrg #define	VM_LOADAVG	2		/* struct loadavg */
1664c698e84Smrg #define	VM_UVMEXP	3		/* struct uvmexp */
1674c698e84Smrg #define	VM_NKMEMPAGES	4		/* kmem_map pages */
1683c1b8a2bSsimonb #define	VM_UVMEXP2	5		/* struct uvmexp_sysctl */
16983d071a3Schs #define	VM_ANONMIN	6
170849c9b2bSchs #define	VM_EXECMIN	7
171849c9b2bSchs #define	VM_FILEMIN	8
172f3008983Smatt #define	VM_MAXSLP	9
173f3008983Smatt #define	VM_USPACE	10
174849c9b2bSchs #define	VM_ANONMAX	11
175849c9b2bSchs #define	VM_EXECMAX	12
176849c9b2bSchs #define	VM_FILEMAX	13
177b007730cSmatt #define	VM_MINADDRESS	14
178b007730cSmatt #define	VM_MAXADDRESS	15
1794e84514dSchristos #define	VM_PROC		16		/* process information */
1805f391f4aSjoerg #define	VM_GUARD_SIZE	17		/* guard size for main thread */
1815f391f4aSjoerg #define	VM_THREAD_GUARD_SIZE	18	/* default guard size for new threads */
18283d071a3Schs 
1834e84514dSchristos #define VM_PROC_MAP	1		/* struct kinfo_vmentry */
1844c698e84Smrg 
1854c698e84Smrg #ifndef ASSEMBLER
1864c698e84Smrg /*
1874c698e84Smrg  *	Convert addresses to pages and vice versa.
1884c698e84Smrg  *	No rounding is used.
1894c698e84Smrg  */
1904c698e84Smrg #ifdef _KERNEL
191f134ba44Spk #define	atop(x)		(((paddr_t)(x)) >> PAGE_SHIFT)
192a617230fSmatt #define	ptoa(x)		(((paddr_t)(x)) << PAGE_SHIFT)
1934c698e84Smrg 
1944c698e84Smrg /*
1954c698e84Smrg  * Round off or truncate to the nearest page.  These will work
1964c698e84Smrg  * for either addresses or counts (i.e., 1 byte rounds to 1 page).
1974c698e84Smrg  */
1984c698e84Smrg #define	round_page(x)	(((x) + PAGE_MASK) & ~PAGE_MASK)
1994c698e84Smrg #define	trunc_page(x)	((x) & ~PAGE_MASK)
2004c698e84Smrg 
20121c591daSchristos #ifndef VM_DEFAULT_ADDRESS_BOTTOMUP
20221c591daSchristos #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
20321c591daSchristos     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
20421c591daSchristos #endif
20537493adfSchristos 
2065f391f4aSjoerg extern unsigned int user_stack_guard_size;
2075f391f4aSjoerg extern unsigned int user_thread_stack_guard_size;
20821c591daSchristos #ifndef VM_DEFAULT_ADDRESS_TOPDOWN
20921c591daSchristos #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
210b77121f1Sjoerg     trunc_page(VM_MAXUSER_ADDRESS - MAXSSIZ - (sz) - user_stack_guard_size)
21121c591daSchristos #endif
21221c591daSchristos 
213fc030738Schs extern int		ubc_nwins;	/* number of UBC mapping windows */
214b7a193fbSmlelstv extern const int	ubc_winshift;	/* shift for a UBC mapping window */
2154c698e84Smrg 
2164c698e84Smrg #else
2174c698e84Smrg /* out-of-kernel versions of round_page and trunc_page */
2184c698e84Smrg #define	round_page(x) \
2194c698e84Smrg 	((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
2204c698e84Smrg 	    vm_page_size)
2214c698e84Smrg #define	trunc_page(x) \
2224c698e84Smrg 	((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
2234c698e84Smrg 
2244c698e84Smrg #endif /* _KERNEL */
2251e0c5c59Suebayasi 
2261e0c5c59Suebayasi /*
2271e0c5c59Suebayasi  * typedefs, necessary for standard UVM headers.
2281e0c5c59Suebayasi  */
2291e0c5c59Suebayasi 
2301e0c5c59Suebayasi typedef unsigned int uvm_flag_t;
2311e0c5c59Suebayasi 
2321e0c5c59Suebayasi typedef int vm_inherit_t;	/* XXX: inheritance codes */
2331e0c5c59Suebayasi typedef off_t voff_t;		/* XXX: offset within a uvm_object */
2341e0c5c59Suebayasi typedef voff_t pgoff_t;		/* XXX: number of pages within a uvm object */
2351e0c5c59Suebayasi 
2364c698e84Smrg #endif /* ASSEMBLER */
2374c698e84Smrg #endif /* _VM_PARAM_ */
238