Deleted Added
full compact
subr_param.c (242847) subr_param.c (243631)
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.

--- 21 unchanged lines hidden (view full) ---

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>
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.

--- 21 unchanged lines hidden (view full) ---

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: head/sys/kern/subr_param.c 242847 2012-11-10 02:08:40Z alfred $");
38__FBSDID("$FreeBSD: head/sys/kern/subr_param.c 243631 2012-11-27 21:19:58Z andre $");
39
40#include "opt_param.h"
41#include "opt_msgbuf.h"
42#include "opt_maxusers.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>

--- 41 unchanged lines hidden (view full) ---

88int maxprocperuid; /* max # of procs per user */
89int maxfiles; /* sys. wide open files limit */
90int maxfilesperproc; /* per-proc open files limit */
91int msgbufsize; /* size of kernel message buffer */
92int ncallout; /* maximum # of timer events */
93int nbuf;
94int ngroups_max; /* max # groups per process */
95int nswbuf;
39
40#include "opt_param.h"
41#include "opt_msgbuf.h"
42#include "opt_maxusers.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>

--- 41 unchanged lines hidden (view full) ---

88int maxprocperuid; /* max # of procs per user */
89int maxfiles; /* sys. wide open files limit */
90int maxfilesperproc; /* per-proc open files limit */
91int msgbufsize; /* size of kernel message buffer */
92int ncallout; /* maximum # of timer events */
93int nbuf;
94int ngroups_max; /* max # groups per process */
95int nswbuf;
96long maxmbufmem; /* max mbuf memory */
96pid_t pid_max = PID_MAX;
97long maxswzone; /* max swmeta KVA storage */
98long maxbcache; /* max buffer cache KVA storage */
99long maxpipekva; /* Limit on pipe KVA */
100int vm_guest; /* Running as virtual machine guest? */
101u_long maxtsiz; /* max text size */
102u_long dfldsiz; /* initial data size limit */
103u_long maxdsiz; /* max data size */

--- 161 unchanged lines hidden (view full) ---

265}
266
267/*
268 * Boot time overrides that are scaled against main memory
269 */
270void
271init_param2(long physpages)
272{
97pid_t pid_max = PID_MAX;
98long maxswzone; /* max swmeta KVA storage */
99long maxbcache; /* max buffer cache KVA storage */
100long maxpipekva; /* Limit on pipe KVA */
101int vm_guest; /* Running as virtual machine guest? */
102u_long maxtsiz; /* max text size */
103u_long dfldsiz; /* initial data size limit */
104u_long maxdsiz; /* max data size */

--- 161 unchanged lines hidden (view full) ---

266}
267
268/*
269 * Boot time overrides that are scaled against main memory
270 */
271void
272init_param2(long physpages)
273{
274 long realmem;
273
274 /* Base parameters */
275 maxusers = MAXUSERS;
276 TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
277 if (maxusers == 0) {
278 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
279 if (maxusers < 32)
280 maxusers = 32;

--- 7 unchanged lines hidden (view full) ---

288 */
289 if (maxusers > 384)
290 maxusers = 384 + ((maxusers - 384) / 8);
291 }
292
293 /*
294 * The following can be overridden after boot via sysctl. Note:
295 * unless overriden, these macros are ultimately based on maxusers.
275
276 /* Base parameters */
277 maxusers = MAXUSERS;
278 TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
279 if (maxusers == 0) {
280 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
281 if (maxusers < 32)
282 maxusers = 32;

--- 7 unchanged lines hidden (view full) ---

290 */
291 if (maxusers > 384)
292 maxusers = 384 + ((maxusers - 384) / 8);
293 }
294
295 /*
296 * The following can be overridden after boot via sysctl. Note:
297 * unless overriden, these macros are ultimately based on maxusers.
296 */
297 maxproc = NPROC;
298 TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
299 /*
300 * Limit maxproc so that kmap entries cannot be exhausted by
301 * processes.
302 */
298 * Limit maxproc so that kmap entries cannot be exhausted by
299 * processes.
300 */
301 maxproc = NPROC;
302 TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
303 if (maxproc > (physpages / 12))
304 maxproc = physpages / 12;
303 if (maxproc > (physpages / 12))
304 maxproc = physpages / 12;
305 maxfiles = MAXFILES;
306 TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
307 maxprocperuid = (maxproc * 9) / 10;
305 maxprocperuid = (maxproc * 9) / 10;
308 maxfilesperproc = (maxfiles * 9) / 10;
306
307 /*
308 * The default limit for maxfiles is 1/12 of the number of
309 * physical page but not less than 16 times maxusers.
310 * At most it can be 1/6 the number of physical pages.
311 */
312 maxfiles = imax(MAXFILES, physpages / 8);
313 TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
314 if (maxfiles > (physpages / 4))
315 maxfiles = physpages / 4;
316 maxfilesperproc = (maxfiles / 10) * 9;
309
310 /*
311 * Cannot be changed after boot.
312 */
313 nbuf = NBUF;
314 TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
315
317
318 /*
319 * Cannot be changed after boot.
320 */
321 nbuf = NBUF;
322 TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
323
324 /*
325 * XXX: Does the callout wheel have to be so big?
326 */
316 ncallout = 16 + maxproc + maxfiles;
317 TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
318
319 /*
327 ncallout = 16 + maxproc + maxfiles;
328 TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
329
330 /*
331 * The default limit for all mbuf related memory is 1/2 of all
332 * available kernel memory (physical or kmem).
333 * At most it can be 3/4 of available kernel memory.
334 */
335 realmem = lmin(physpages * PAGE_SIZE,
336 VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS);
337 maxmbufmem = realmem / 2;
338 TUNABLE_LONG_FETCH("kern.maxmbufmem", &maxmbufmem);
339 if (maxmbufmem > (realmem / 4) * 3)
340 maxmbufmem = (realmem / 4) * 3;
341
342 /*
320 * The default for maxpipekva is min(1/64 of the kernel address space,
321 * max(1/64 of main memory, 512KB)). See sys_pipe.c for more details.
322 */
323 maxpipekva = (physpages / 64) * PAGE_SIZE;
343 * The default for maxpipekva is min(1/64 of the kernel address space,
344 * max(1/64 of main memory, 512KB)). See sys_pipe.c for more details.
345 */
346 maxpipekva = (physpages / 64) * PAGE_SIZE;
347 TUNABLE_LONG_FETCH("kern.ipc.maxpipekva", &maxpipekva);
324 if (maxpipekva < 512 * 1024)
325 maxpipekva = 512 * 1024;
326 if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64)
327 maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) /
328 64;
348 if (maxpipekva < 512 * 1024)
349 maxpipekva = 512 * 1024;
350 if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64)
351 maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) /
352 64;
329 TUNABLE_LONG_FETCH("kern.ipc.maxpipekva", &maxpipekva);
330}
331
332/*
333 * Sysctl stringiying handler for kern.vm_guest.
334 */
335static int
336sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS)
337{
338 return (SYSCTL_OUT(req, vm_guest_sysctl_names[vm_guest],
339 strlen(vm_guest_sysctl_names[vm_guest])));
340}
353}
354
355/*
356 * Sysctl stringiying handler for kern.vm_guest.
357 */
358static int
359sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS)
360{
361 return (SYSCTL_OUT(req, vm_guest_sysctl_names[vm_guest],
362 strlen(vm_guest_sysctl_names[vm_guest])));
363}