]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/kern/subr_param.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / kern / subr_param.c
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  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *      @(#)param.c     8.3 (Berkeley) 8/20/94
35  */
36
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39
40 #include "opt_param.h"
41 #include "opt_maxusers.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/sysctl.h>
47
48 #include <vm/vm_param.h>
49
50 /*
51  * System parameter formulae.
52  */
53
54 #ifndef HZ
55 #  if defined(__amd64__) || defined(__i386__) || defined(__ia64__) || defined(__sparc64__)
56 #    define     HZ 1000
57 #  else
58 #    define     HZ 100
59 #  endif
60 #endif
61 #define NPROC (20 + 16 * maxusers)
62 #ifndef NBUF
63 #define NBUF 0
64 #endif
65 #ifndef MAXFILES
66 #define MAXFILES (maxproc * 2)
67 #endif
68
69 int     hz;
70 int     tick;
71 int     maxusers;                       /* base tunable */
72 int     maxproc;                        /* maximum # of processes */
73 int     maxprocperuid;                  /* max # of procs per user */
74 int     maxfiles;                       /* sys. wide open files limit */
75 int     maxfilesperproc;                /* per-proc open files limit */
76 int     ncallout;                       /* maximum # of timer events */
77 int     nbuf;
78 int     nswbuf;
79 int     maxswzone;                      /* max swmeta KVA storage */
80 int     maxbcache;                      /* max buffer cache KVA storage */
81 int     maxpipekva;                     /* Limit on pipe KVA */
82 u_long  maxtsiz;                        /* max text size */
83 u_long  dfldsiz;                        /* initial data size limit */
84 u_long  maxdsiz;                        /* max data size */
85 u_long  dflssiz;                        /* initial stack size limit */
86 u_long  maxssiz;                        /* max stack size */
87 u_long  sgrowsiz;                       /* amount to grow stack */
88
89 SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RDTUN, &hz, 0,
90     "Number of clock ticks per second");
91 SYSCTL_INT(_kern, OID_AUTO, ncallout, CTLFLAG_RDTUN, &ncallout, 0,
92     "Number of pre-allocated timer events");
93 SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RDTUN, &nbuf, 0,
94     "Number of buffers in the buffer cache");
95 SYSCTL_INT(_kern, OID_AUTO, nswbuf, CTLFLAG_RDTUN, &nswbuf, 0,
96     "Number of swap buffers");
97 SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RDTUN, &maxswzone, 0,
98     "Maximum memory for swap metadata");
99 SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RDTUN, &maxbcache, 0,
100     "Maximum value of vfs.maxbufspace");
101 SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RDTUN, &maxtsiz, 0,
102     "Maximum text size");
103 SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RDTUN, &dfldsiz, 0,
104     "Initial data size limit");
105 SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RDTUN, &maxdsiz, 0,
106     "Maximum data size");
107 SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RDTUN, &dflssiz, 0,
108     "Initial stack size limit");
109 SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RDTUN, &maxssiz, 0,
110     "Maximum stack size");
111 SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RDTUN, &sgrowsiz, 0,
112     "Amount to grow stack on a stack fault");
113
114 /*
115  * These have to be allocated somewhere; allocating
116  * them here forces loader errors if this file is omitted
117  * (if they've been externed everywhere else; hah!).
118  */
119 struct  buf *swbuf;
120
121 /*
122  * Boot time overrides that are not scaled against main memory
123  */
124 void
125 init_param1(void)
126 {
127
128         hz = HZ;
129         TUNABLE_INT_FETCH("kern.hz", &hz);
130         tick = 1000000 / hz;
131
132 #ifdef VM_SWZONE_SIZE_MAX
133         maxswzone = VM_SWZONE_SIZE_MAX;
134 #endif
135         TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
136 #ifdef VM_BCACHE_SIZE_MAX
137         maxbcache = VM_BCACHE_SIZE_MAX;
138 #endif
139         TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
140
141         maxtsiz = MAXTSIZ;
142         TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz);
143         dfldsiz = DFLDSIZ;
144         TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz);
145         maxdsiz = MAXDSIZ;
146         TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz);
147         dflssiz = DFLSSIZ;
148         TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz);
149         maxssiz = MAXSSIZ;
150         TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz);
151         sgrowsiz = SGROWSIZ;
152         TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz);
153 }
154
155 /*
156  * Boot time overrides that are scaled against main memory
157  */
158 void
159 init_param2(long physpages)
160 {
161
162         /* Base parameters */
163         maxusers = MAXUSERS;
164         TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
165         if (maxusers == 0) {
166                 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
167                 if (maxusers < 32)
168                         maxusers = 32;
169                 if (maxusers > 384)
170                         maxusers = 384;
171         }
172
173         /*
174          * The following can be overridden after boot via sysctl.  Note:
175          * unless overriden, these macros are ultimately based on maxusers.
176          */
177         maxproc = NPROC;
178         TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
179         /*
180          * Limit maxproc so that kmap entries cannot be exhausted by
181          * processes.
182          */
183         if (maxproc > (physpages / 12))
184                 maxproc = physpages / 12;
185         maxfiles = MAXFILES;
186         TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
187         maxprocperuid = (maxproc * 9) / 10;
188         maxfilesperproc = (maxfiles * 9) / 10;
189         
190         /*
191          * Cannot be changed after boot.
192          */
193         nbuf = NBUF;
194         TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
195
196         ncallout = 16 + maxproc + maxfiles;
197         TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
198 }
199
200 /*
201  * Boot time overrides that are scaled against the kmem map
202  */
203 void
204 init_param3(long kmempages)
205 {
206
207         /*
208          * The default for maxpipekva is max(5% of the kmem map, 512KB).
209          * See sys_pipe.c for more details.
210          */
211         maxpipekva = (kmempages / 20) * PAGE_SIZE;
212         if (maxpipekva < 512 * 1024)
213                 maxpipekva = 512 * 1024;
214         TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva);
215 }