xref: /freebsd/sys/kern/subr_param.c (revision ef5d438ed4bc17ad7ece3e40fe4d1f9baf3aadf7)
1 /*
2  * Copyright (c) 1980, 1986, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)param.c	8.2 (Berkeley) 1/21/94
39  * $Id: param.c,v 1.13 1995/12/10 13:44:55 phk Exp $
40  */
41 
42 #include "opt_sysvipc.h"
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/proc.h>
48 #include <sys/vnode.h>
49 #include <sys/file.h>
50 #include <sys/callout.h>
51 #include <sys/clist.h>
52 #include <sys/mbuf.h>
53 #include <sys/kernel.h>
54 
55 #include <ufs/ufs/quota.h>
56 
57 #ifdef SYSVSHM
58 #include <machine/vmparam.h>
59 #include <sys/shm.h>
60 #endif
61 #ifdef SYSVSEM
62 #include <sys/sem.h>
63 #endif
64 #ifdef SYSVMSG
65 #include <sys/msg.h>
66 #endif
67 
68 /*
69  * System parameter formulae.
70  *
71  * This file is copied into each directory where we compile
72  * the kernel; it should be modified there to suit local taste
73  * if necessary.
74  *
75  * Compiled with -DMAXUSERS=xx
76  */
77 
78 #ifndef HZ
79 #define	HZ 100
80 #endif
81 int	hz = HZ;
82 int	tick = 1000000 / HZ;
83 int	tickadj = 30000 / (60 * HZ);		/* can adjust 30ms in 60s */
84 #define	NPROC (20 + 16 * MAXUSERS)
85 int	maxproc = NPROC;			/* maximum # of processes */
86 int	maxprocperuid = NPROC-1;		/* maximum # of processes per user */
87 int	maxfiles = NPROC*2;			/* system wide open files limit */
88 int	maxfilesperproc = NPROC*2;		/* per-process open files limit */
89 int	ncallout = 16 + NPROC;			/* maximum # of timer events */
90 
91 /* maximum # of mbuf clusters */
92 #ifndef NMBCLUSTERS
93 int	nmbclusters = 512 + MAXUSERS * 16;
94 #else
95 int	nmbclusters = NMBCLUSTERS;
96 #endif
97 
98 int	fscale = FSCALE;	/* kernel uses `FSCALE', user uses `fscale' */
99 
100 /*
101  * Values in support of System V compatible shared memory.	XXX
102  */
103 #ifdef SYSVSHM
104 #ifndef SHMMAX
105 #define	SHMMAX	(SHMMAXPGS*NBPG)
106 #endif
107 #ifndef SHMMIN
108 #define	SHMMIN	1
109 #endif
110 #ifndef SHMMNI
111 #define	SHMMNI	32			/* <= SHMMMNI in shm.h */
112 #endif
113 #ifndef SHMSEG
114 #define	SHMSEG	8
115 #endif
116 #ifndef SHMALL
117 #define	SHMALL	(SHMMAXPGS/CLSIZE)
118 #endif
119 
120 struct	shminfo shminfo = {
121 	SHMMAX,
122 	SHMMIN,
123 	SHMMNI,
124 	SHMSEG,
125 	SHMALL
126 };
127 #endif
128 
129 /*
130  * Values in support of System V compatible semaphores.
131  */
132 
133 #ifdef SYSVSEM
134 
135 struct seminfo seminfo = {
136                 SEMMAP,         /* # of entries in semaphore map */
137                 SEMMNI,         /* # of semaphore identifiers */
138                 SEMMNS,         /* # of semaphores in system */
139                 SEMMNU,         /* # of undo structures in system */
140                 SEMMSL,         /* max # of semaphores per id */
141                 SEMOPM,         /* max # of operations per semop call */
142                 SEMUME,         /* max # of undo entries per process */
143                 SEMUSZ,         /* size in bytes of undo structure */
144                 SEMVMX,         /* semaphore maximum value */
145                 SEMAEM          /* adjust on exit max value */
146 };
147 #endif
148 
149 /*
150  * Values in support of System V compatible messages.
151  */
152 
153 #ifdef SYSVMSG
154 
155 struct msginfo msginfo = {
156                 MSGMAX,         /* max chars in a message */
157                 MSGMNI,         /* # of message queue identifiers */
158                 MSGMNB,         /* max chars in a queue */
159                 MSGTQL,         /* max messages in system */
160                 MSGSSZ,         /* size of a message segment */
161                 		/* (must be small power of 2 greater than 4) */
162                 MSGSEG          /* number of message segments */
163 };
164 #endif
165 
166 /*
167  * These may be set to nonzero here or by patching.
168  * If they are nonzero at bootstrap time then they are
169  * initialized to values dependent on the memory size.
170  */
171 #ifdef	NBUF
172 int	nbuf = NBUF;
173 #else
174 int	nbuf = 0;
175 #endif
176 int	nswbuf = 0;
177 
178 /*
179  * These have to be allocated somewhere; allocating
180  * them here forces loader errors if this file is omitted
181  * (if they've been externed everywhere else; hah!).
182  */
183 struct	buf *swbuf;
184 
185 /*
186  * Proc/pgrp hashing.
187  * Here so that hash table sizes can depend on MAXUSERS/NPROC.
188  * Hash size must be a power of two.
189  * NOW omission of this file will cause loader errors!
190  */
191 
192 #if NPROC > 1024
193 #define	PIDHSZ		512
194 #else
195 #if NPROC > 512
196 #define	PIDHSZ		256
197 #else
198 #if NPROC > 256
199 #define	PIDHSZ		128
200 #else
201 #define	PIDHSZ		64
202 #endif
203 #endif
204 #endif
205 
206 struct	proc *pidhash[PIDHSZ];
207 struct	pgrp *pgrphash[PIDHSZ];
208 int	pidhashmask = PIDHSZ - 1;
209