xref: /freebsd/sys/kern/subr_param.c (revision 79f62ed69004b699d56e16b29fc2ac3a6d3a7d34)
19454b2d8SWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1980, 1986, 1989, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  * (c) UNIX System Laboratories, Inc.
5df8bae1dSRodney W. Grimes  * All or some portions of this file are derived from material licensed
6df8bae1dSRodney W. Grimes  * to the University of California by American Telephone and Telegraph
7df8bae1dSRodney W. Grimes  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8df8bae1dSRodney W. Grimes  * the permission of UNIX System Laboratories, Inc.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
19df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
20df8bae1dSRodney W. Grimes  *    without specific prior written permission.
21df8bae1dSRodney W. Grimes  *
22df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
33df8bae1dSRodney W. Grimes  *
3470b012caSJeffrey Hsu  *	@(#)param.c	8.3 (Berkeley) 8/20/94
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37677b542eSDavid E. O'Brien #include <sys/cdefs.h>
38677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$");
39677b542eSDavid E. O'Brien 
404bd49128SPeter Wemm #include "opt_param.h"
414053b05bSSergey Kandaurov #include "opt_msgbuf.h"
42ee342e1bSPeter Wemm #include "opt_maxusers.h"
4350c73f36SGarrett Wollman 
44df8bae1dSRodney W. Grimes #include <sys/param.h>
45ee342e1bSPeter Wemm #include <sys/systm.h>
46ee342e1bSPeter Wemm #include <sys/kernel.h>
4702c6fc21SKonstantin Belousov #include <sys/limits.h>
484053b05bSSergey Kandaurov #include <sys/msgbuf.h>
4902c6fc21SKonstantin Belousov #include <sys/sysctl.h>
5002c6fc21SKonstantin Belousov #include <sys/proc.h>
51df8bae1dSRodney W. Grimes 
52e9a3f785SAlan Cox #include <vm/vm.h>
537419d1e2SDag-Erling Smørgrav #include <vm/vm_param.h>
54e9a3f785SAlan Cox #include <vm/pmap.h>
55cbc89bfbSPaul Saab 
56df8bae1dSRodney W. Grimes /*
57df8bae1dSRodney W. Grimes  * System parameter formulae.
58df8bae1dSRodney W. Grimes  */
59df8bae1dSRodney W. Grimes 
60df8bae1dSRodney W. Grimes #ifndef HZ
61bcebf6a1SNathan Whitehorn #  if defined(__mips__) || defined(__arm__)
62df8bae1dSRodney W. Grimes #    define	HZ 100
63bcebf6a1SNathan Whitehorn #  else
64bcebf6a1SNathan Whitehorn #    define	HZ 1000
65df8bae1dSRodney W. Grimes #  endif
667f03c419SMaxim Sobolev #  ifndef HZ_VM
67347e22a6SMike Silbersack #    define	HZ_VM 100
687f03c419SMaxim Sobolev #  endif
697f03c419SMaxim Sobolev #else
707f03c419SMaxim Sobolev #  ifndef HZ_VM
717f03c419SMaxim Sobolev #    define	HZ_VM HZ
727f03c419SMaxim Sobolev #  endif
738f650450SPeter Wemm #endif
74ee342e1bSPeter Wemm #define	NPROC (20 + 16 * maxusers)
75ee342e1bSPeter Wemm #ifndef NBUF
76ee342e1bSPeter Wemm #define NBUF 0
77ee342e1bSPeter Wemm #endif
785a00f364SDag-Erling Smørgrav #ifndef MAXFILES
79ee342e1bSPeter Wemm #define	MAXFILES (maxproc * 2)
805a00f364SDag-Erling Smørgrav #endif
81dd0b2081SDavid Greenman 
823610a226SIvan Voras static int sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS);
833610a226SIvan Voras 
84ee342e1bSPeter Wemm int	hz;
85ee342e1bSPeter Wemm int	tick;
86ee342e1bSPeter Wemm int	maxusers;			/* base tunable */
87ee342e1bSPeter Wemm int	maxproc;			/* maximum # of processes */
88ee342e1bSPeter Wemm int	maxprocperuid;			/* max # of procs per user */
89ee342e1bSPeter Wemm int	maxfiles;			/* sys. wide open files limit */
90ee342e1bSPeter Wemm int	maxfilesperproc;		/* per-proc open files limit */
914053b05bSSergey Kandaurov int	msgbufsize;			/* size of kernel message buffer */
92ee342e1bSPeter Wemm int	ncallout;			/* maximum # of timer events */
93ee342e1bSPeter Wemm int	nbuf;
94412f9500SBrooks Davis int	ngroups_max;			/* max # groups per process */
95ee342e1bSPeter Wemm int	nswbuf;
9602c6fc21SKonstantin Belousov pid_t	pid_max = PID_MAX;
975bd65606SJohn Baldwin long	maxswzone;			/* max swmeta KVA storage */
985bd65606SJohn Baldwin long	maxbcache;			/* max buffer cache KVA storage */
9964ecd139SJohn Baldwin long	maxpipekva;			/* Limit on pipe KVA */
1003dc30911SIvan Voras int 	vm_guest;			/* Running as virtual machine guest? */
1017419d1e2SDag-Erling Smørgrav u_long	maxtsiz;			/* max text size */
1027419d1e2SDag-Erling Smørgrav u_long	dfldsiz;			/* initial data size limit */
1037419d1e2SDag-Erling Smørgrav u_long	maxdsiz;			/* max data size */
1047419d1e2SDag-Erling Smørgrav u_long	dflssiz;			/* initial stack size limit */
1057419d1e2SDag-Erling Smørgrav u_long	maxssiz;			/* max stack size */
1067419d1e2SDag-Erling Smørgrav u_long	sgrowsiz;			/* amount to grow stack */
107df8bae1dSRodney W. Grimes 
1089b84ba1cSJohn Baldwin SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RDTUN, &hz, 0,
1099b84ba1cSJohn Baldwin     "Number of clock ticks per second");
110b9f2a7daSJohn Baldwin SYSCTL_INT(_kern, OID_AUTO, ncallout, CTLFLAG_RDTUN, &ncallout, 0,
111b9f2a7daSJohn Baldwin     "Number of pre-allocated timer events");
112b9f2a7daSJohn Baldwin SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RDTUN, &nbuf, 0,
1139b84ba1cSJohn Baldwin     "Number of buffers in the buffer cache");
114b9f2a7daSJohn Baldwin SYSCTL_INT(_kern, OID_AUTO, nswbuf, CTLFLAG_RDTUN, &nswbuf, 0,
115b9f2a7daSJohn Baldwin     "Number of swap buffers");
1164053b05bSSergey Kandaurov SYSCTL_INT(_kern, OID_AUTO, msgbufsize, CTLFLAG_RDTUN, &msgbufsize, 0,
1174053b05bSSergey Kandaurov     "Size of the kernel message buffer");
11842dd14baSJohn Baldwin SYSCTL_LONG(_kern, OID_AUTO, maxswzone, CTLFLAG_RDTUN, &maxswzone, 0,
1199b84ba1cSJohn Baldwin     "Maximum memory for swap metadata");
12042dd14baSJohn Baldwin SYSCTL_LONG(_kern, OID_AUTO, maxbcache, CTLFLAG_RDTUN, &maxbcache, 0,
1219b84ba1cSJohn Baldwin     "Maximum value of vfs.maxbufspace");
122ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RW | CTLFLAG_TUN, &maxtsiz, 0,
1239b84ba1cSJohn Baldwin     "Maximum text size");
124ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RW | CTLFLAG_TUN, &dfldsiz, 0,
1259b84ba1cSJohn Baldwin     "Initial data size limit");
126ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RW | CTLFLAG_TUN, &maxdsiz, 0,
1279b84ba1cSJohn Baldwin     "Maximum data size");
128ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RW | CTLFLAG_TUN, &dflssiz, 0,
1299b84ba1cSJohn Baldwin     "Initial stack size limit");
130ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RW | CTLFLAG_TUN, &maxssiz, 0,
1319b84ba1cSJohn Baldwin     "Maximum stack size");
132ceb0f715SAndrey Zonov SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RW | CTLFLAG_TUN, &sgrowsiz, 0,
133ceb0f715SAndrey Zonov     "Amount to grow stack on a stack fault");
1343610a226SIvan Voras SYSCTL_PROC(_kern, OID_AUTO, vm_guest, CTLFLAG_RD | CTLTYPE_STRING,
1353610a226SIvan Voras     NULL, 0, sysctl_kern_vm_guest, "A",
13607ce8d9bSIvan Voras     "Virtual machine guest detected? (none|generic|xen)");
1377c45a9c4SAlfred Perlstein 
138df8bae1dSRodney W. Grimes /*
139df8bae1dSRodney W. Grimes  * These have to be allocated somewhere; allocating
140df8bae1dSRodney W. Grimes  * them here forces loader errors if this file is omitted
141df8bae1dSRodney W. Grimes  * (if they've been externed everywhere else; hah!).
142df8bae1dSRodney W. Grimes  */
14328f8db14SBruce Evans struct	buf *swbuf;
1449722d88fSJason Evans 
1450b993ee5SAlan Cox /*
1460b993ee5SAlan Cox  * The elements of this array are ordered based upon the values of the
1470b993ee5SAlan Cox  * corresponding enum VM_GUEST members.
1480b993ee5SAlan Cox  */
14934820bbfSBjoern A. Zeeb static const char *const vm_guest_sysctl_names[] = {
15034820bbfSBjoern A. Zeeb 	"none",
15134820bbfSBjoern A. Zeeb 	"generic",
15234820bbfSBjoern A. Zeeb 	"xen",
15334820bbfSBjoern A. Zeeb 	NULL
15434820bbfSBjoern A. Zeeb };
15534820bbfSBjoern A. Zeeb 
15634820bbfSBjoern A. Zeeb #ifndef XEN
1579bd2cbe4SJung-uk Kim static const char *const vm_bnames[] = {
1589bd2cbe4SJung-uk Kim 	"QEMU",				/* QEMU */
1599bd2cbe4SJung-uk Kim 	"Plex86",			/* Plex86 */
1609bd2cbe4SJung-uk Kim 	"Bochs",			/* Bochs */
161ea235a14SChristian S.J. Peron 	"Xen",				/* Xen */
1629bd2cbe4SJung-uk Kim 	NULL
1639bd2cbe4SJung-uk Kim };
1649bd2cbe4SJung-uk Kim 
1654da059f3SMaxim Sobolev static const char *const vm_pnames[] = {
1667f03c419SMaxim Sobolev 	"VMware Virtual Platform",	/* VMWare VM */
1677f03c419SMaxim Sobolev 	"Virtual Machine",		/* Microsoft VirtualPC */
1687f03c419SMaxim Sobolev 	"VirtualBox",			/* Sun xVM VirtualBox */
1697f03c419SMaxim Sobolev 	"Parallels Virtual Platform",	/* Parallels VM */
1707f03c419SMaxim Sobolev 	NULL
1717f03c419SMaxim Sobolev };
1727f03c419SMaxim Sobolev 
1733610a226SIvan Voras 
1743610a226SIvan Voras /*
1753610a226SIvan Voras  * Detect known Virtual Machine hosts by inspecting the emulated BIOS.
1763610a226SIvan Voras  */
1773dc30911SIvan Voras static enum VM_GUEST
1787f03c419SMaxim Sobolev detect_virtual(void)
1797f03c419SMaxim Sobolev {
1807f03c419SMaxim Sobolev 	char *sysenv;
1817f03c419SMaxim Sobolev 	int i;
1827f03c419SMaxim Sobolev 
1839bd2cbe4SJung-uk Kim 	sysenv = getenv("smbios.bios.vendor");
1849bd2cbe4SJung-uk Kim 	if (sysenv != NULL) {
1859bd2cbe4SJung-uk Kim 		for (i = 0; vm_bnames[i] != NULL; i++)
1869bd2cbe4SJung-uk Kim 			if (strcmp(sysenv, vm_bnames[i]) == 0) {
1879bd2cbe4SJung-uk Kim 				freeenv(sysenv);
1883dc30911SIvan Voras 				return (VM_GUEST_VM);
1899bd2cbe4SJung-uk Kim 			}
1909bd2cbe4SJung-uk Kim 		freeenv(sysenv);
1919bd2cbe4SJung-uk Kim 	}
1927f03c419SMaxim Sobolev 	sysenv = getenv("smbios.system.product");
1937f03c419SMaxim Sobolev 	if (sysenv != NULL) {
1949bd2cbe4SJung-uk Kim 		for (i = 0; vm_pnames[i] != NULL; i++)
1959bd2cbe4SJung-uk Kim 			if (strcmp(sysenv, vm_pnames[i]) == 0) {
1969bd2cbe4SJung-uk Kim 				freeenv(sysenv);
1973dc30911SIvan Voras 				return (VM_GUEST_VM);
1987f03c419SMaxim Sobolev 			}
1999bd2cbe4SJung-uk Kim 		freeenv(sysenv);
2007f03c419SMaxim Sobolev 	}
2013dc30911SIvan Voras 	return (VM_GUEST_NO);
2027f03c419SMaxim Sobolev }
20334820bbfSBjoern A. Zeeb #endif
2047f03c419SMaxim Sobolev 
2059722d88fSJason Evans /*
20666a11b9fSMatthew Dillon  * Boot time overrides that are not scaled against main memory
207ee342e1bSPeter Wemm  */
208ee342e1bSPeter Wemm void
20966a11b9fSMatthew Dillon init_param1(void)
210ee342e1bSPeter Wemm {
2113dc30911SIvan Voras #ifndef XEN
2123dc30911SIvan Voras 	vm_guest = detect_virtual();
2133dc30911SIvan Voras #else
2143dc30911SIvan Voras 	vm_guest = VM_GUEST_XEN;
2153dc30911SIvan Voras #endif
2167f03c419SMaxim Sobolev 	hz = -1;
217ee342e1bSPeter Wemm 	TUNABLE_INT_FETCH("kern.hz", &hz);
2189bd2cbe4SJung-uk Kim 	if (hz == -1)
2193dc30911SIvan Voras 		hz = vm_guest > VM_GUEST_NO ? HZ_VM : HZ;
220ee342e1bSPeter Wemm 	tick = 1000000 / hz;
221ee342e1bSPeter Wemm 
222e1616f3aSMatthew Dillon #ifdef VM_SWZONE_SIZE_MAX
2232f9e4e80SMatthew Dillon 	maxswzone = VM_SWZONE_SIZE_MAX;
224e1616f3aSMatthew Dillon #endif
2255bd65606SJohn Baldwin 	TUNABLE_LONG_FETCH("kern.maxswzone", &maxswzone);
226e1616f3aSMatthew Dillon #ifdef VM_BCACHE_SIZE_MAX
2272f9e4e80SMatthew Dillon 	maxbcache = VM_BCACHE_SIZE_MAX;
228e1616f3aSMatthew Dillon #endif
2295bd65606SJohn Baldwin 	TUNABLE_LONG_FETCH("kern.maxbcache", &maxbcache);
2304053b05bSSergey Kandaurov 	msgbufsize = MSGBUF_SIZE;
2314053b05bSSergey Kandaurov 	TUNABLE_INT_FETCH("kern.msgbufsize", &msgbufsize);
232cbc89bfbSPaul Saab 
233cbc89bfbSPaul Saab 	maxtsiz = MAXTSIZ;
2347419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz);
235cbc89bfbSPaul Saab 	dfldsiz = DFLDSIZ;
2367419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz);
237cbc89bfbSPaul Saab 	maxdsiz = MAXDSIZ;
2387419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz);
239cbc89bfbSPaul Saab 	dflssiz = DFLSSIZ;
2407419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz);
241cbc89bfbSPaul Saab 	maxssiz = MAXSSIZ;
2427419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz);
243cbc89bfbSPaul Saab 	sgrowsiz = SGROWSIZ;
2447419d1e2SDag-Erling Smørgrav 	TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz);
245412f9500SBrooks Davis 
246412f9500SBrooks Davis 	/*
247412f9500SBrooks Davis 	 * Let the administrator set {NGROUPS_MAX}, but disallow values
248412f9500SBrooks Davis 	 * less than NGROUPS_MAX which would violate POSIX.1-2008 or
249412f9500SBrooks Davis 	 * greater than INT_MAX-1 which would result in overflow.
250412f9500SBrooks Davis 	 */
251412f9500SBrooks Davis 	ngroups_max = NGROUPS_MAX;
252412f9500SBrooks Davis 	TUNABLE_INT_FETCH("kern.ngroups", &ngroups_max);
253412f9500SBrooks Davis 	if (ngroups_max < NGROUPS_MAX)
254412f9500SBrooks Davis 		ngroups_max = NGROUPS_MAX;
25502c6fc21SKonstantin Belousov 
25602c6fc21SKonstantin Belousov 	/*
25702c6fc21SKonstantin Belousov 	 * Only allow to lower the maximal pid.
2583fa615bcSKonstantin Belousov 	 * Prevent setting up a non-bootable system if pid_max is too low.
25902c6fc21SKonstantin Belousov 	 */
26002c6fc21SKonstantin Belousov 	TUNABLE_INT_FETCH("kern.pid_max", &pid_max);
26102c6fc21SKonstantin Belousov 	if (pid_max > PID_MAX)
26202c6fc21SKonstantin Belousov 		pid_max = PID_MAX;
2633fa615bcSKonstantin Belousov 	else if (pid_max < 300)
2643fa615bcSKonstantin Belousov 		pid_max = 300;
265ee342e1bSPeter Wemm }
26666a11b9fSMatthew Dillon 
26766a11b9fSMatthew Dillon /*
26866a11b9fSMatthew Dillon  * Boot time overrides that are scaled against main memory
26966a11b9fSMatthew Dillon  */
27066a11b9fSMatthew Dillon void
271447b3772SPeter Wemm init_param2(long physpages)
27266a11b9fSMatthew Dillon {
27366a11b9fSMatthew Dillon 
27466a11b9fSMatthew Dillon 	/* Base parameters */
2750b94a0e9SMatthew Dillon 	maxusers = MAXUSERS;
2760b94a0e9SMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
2770b94a0e9SMatthew Dillon 	if (maxusers == 0) {
2784fbd563eSMatthew Dillon 		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
27966a11b9fSMatthew Dillon 		if (maxusers < 32)
28066a11b9fSMatthew Dillon 			maxusers = 32;
281*79f62ed6SAlfred Perlstein #ifdef VM_MAX_AUTOTUNE_MAXUSERS
282*79f62ed6SAlfred Perlstein                 if (maxusers > VM_MAX_AUTOTUNE_MAXUSERS)
283*79f62ed6SAlfred Perlstein                         maxusers = VM_MAX_AUTOTUNE_MAXUSERS;
284*79f62ed6SAlfred Perlstein #endif
2857b6d92c0SAlfred Perlstein                 /*
286*79f62ed6SAlfred Perlstein                  * Scales down the function in which maxusers grows once
287*79f62ed6SAlfred Perlstein                  * we hit 384.
2887b6d92c0SAlfred Perlstein                  */
289*79f62ed6SAlfred Perlstein                 if (maxusers > 384)
290*79f62ed6SAlfred Perlstein                         maxusers = 384 + ((maxusers - 384) / 8);
29166a11b9fSMatthew Dillon         }
29266a11b9fSMatthew Dillon 
29366a11b9fSMatthew Dillon 	/*
29466a11b9fSMatthew Dillon 	 * The following can be overridden after boot via sysctl.  Note:
29566a11b9fSMatthew Dillon 	 * unless overriden, these macros are ultimately based on maxusers.
29666a11b9fSMatthew Dillon 	 */
29766a11b9fSMatthew Dillon 	maxproc = NPROC;
29866a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
29977a7d074SMike Silbersack 	/*
30077a7d074SMike Silbersack 	 * Limit maxproc so that kmap entries cannot be exhausted by
30177a7d074SMike Silbersack 	 * processes.
30277a7d074SMike Silbersack 	 */
30377a7d074SMike Silbersack 	if (maxproc > (physpages / 12))
30477a7d074SMike Silbersack 		maxproc = physpages / 12;
30566a11b9fSMatthew Dillon 	maxfiles = MAXFILES;
30666a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
307ebacce5eSMike Silbersack 	maxprocperuid = (maxproc * 9) / 10;
308ebacce5eSMike Silbersack 	maxfilesperproc = (maxfiles * 9) / 10;
30966a11b9fSMatthew Dillon 
31066a11b9fSMatthew Dillon 	/*
311347194c1SMike Silbersack 	 * Cannot be changed after boot.
312347194c1SMike Silbersack 	 */
313347194c1SMike Silbersack 	nbuf = NBUF;
314347194c1SMike Silbersack 	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
315347194c1SMike Silbersack 
316347194c1SMike Silbersack 	ncallout = 16 + maxproc + maxfiles;
317347194c1SMike Silbersack 	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
318347194c1SMike Silbersack 
319347194c1SMike Silbersack 	/*
320e9a3f785SAlan Cox 	 * The default for maxpipekva is min(1/64 of the kernel address space,
321e9a3f785SAlan Cox 	 * max(1/64 of main memory, 512KB)).  See sys_pipe.c for more details.
322347194c1SMike Silbersack 	 */
323e9a3f785SAlan Cox 	maxpipekva = (physpages / 64) * PAGE_SIZE;
324289016f2SMike Silbersack 	if (maxpipekva < 512 * 1024)
325289016f2SMike Silbersack 		maxpipekva = 512 * 1024;
326e9a3f785SAlan Cox 	if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64)
327e9a3f785SAlan Cox 		maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) /
328e9a3f785SAlan Cox 		    64;
32964ecd139SJohn Baldwin 	TUNABLE_LONG_FETCH("kern.ipc.maxpipekva", &maxpipekva);
33066a11b9fSMatthew Dillon }
3313610a226SIvan Voras 
3323610a226SIvan Voras /*
3333610a226SIvan Voras  * Sysctl stringiying handler for kern.vm_guest.
3343610a226SIvan Voras  */
3353610a226SIvan Voras static int
3363610a226SIvan Voras sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS)
3373610a226SIvan Voras {
3383610a226SIvan Voras 	return (SYSCTL_OUT(req, vm_guest_sysctl_names[vm_guest],
3393610a226SIvan Voras 	    strlen(vm_guest_sysctl_names[vm_guest])));
3403610a226SIvan Voras }
341