mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-26 11:47:31 +00:00
7c45a9c446
and sgrowsiz via sysctl. MFC after: 1 week
200 lines
6.1 KiB
C
200 lines
6.1 KiB
C
/*-
|
|
* Copyright (c) 1980, 1986, 1989, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
* (c) UNIX System Laboratories, Inc.
|
|
* All or some portions of this file are derived from material licensed
|
|
* to the University of California by American Telephone and Telegraph
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* @(#)param.c 8.3 (Berkeley) 8/20/94
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#include "opt_param.h"
|
|
#include "opt_maxusers.h"
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/kernel.h>
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
/*
|
|
* System parameter formulae.
|
|
*/
|
|
|
|
#ifndef HZ
|
|
# if defined(__amd64__) || defined(__i386__) || defined(__ia64__) || defined(__sparc64__)
|
|
# define HZ 1000
|
|
# else
|
|
# define HZ 100
|
|
# endif
|
|
#endif
|
|
#define NPROC (20 + 16 * maxusers)
|
|
#ifndef NBUF
|
|
#define NBUF 0
|
|
#endif
|
|
#ifndef MAXFILES
|
|
#define MAXFILES (maxproc * 2)
|
|
#endif
|
|
|
|
int hz;
|
|
int tick;
|
|
int maxusers; /* base tunable */
|
|
int maxproc; /* maximum # of processes */
|
|
int maxprocperuid; /* max # of procs per user */
|
|
int maxfiles; /* sys. wide open files limit */
|
|
int maxfilesperproc; /* per-proc open files limit */
|
|
int ncallout; /* maximum # of timer events */
|
|
int nbuf;
|
|
int nswbuf;
|
|
int maxswzone; /* max swmeta KVA storage */
|
|
int maxbcache; /* max buffer cache KVA storage */
|
|
int maxpipekva; /* Limit on pipe KVA */
|
|
u_long maxtsiz; /* max text size */
|
|
u_long dfldsiz; /* initial data size limit */
|
|
u_long maxdsiz; /* max data size */
|
|
u_long dflssiz; /* initial stack size limit */
|
|
u_long maxssiz; /* max stack size */
|
|
u_long sgrowsiz; /* amount to grow stack */
|
|
|
|
SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RD, &maxswzone, 0, "");
|
|
SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RD, &maxbcache, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD, &maxtsiz, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD, &dfldsiz, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD, &maxdsiz, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RD, &dflssiz, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RD, &maxssiz, 0, "");
|
|
SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD, &sgrowsiz, 0, "");
|
|
|
|
/*
|
|
* These have to be allocated somewhere; allocating
|
|
* them here forces loader errors if this file is omitted
|
|
* (if they've been externed everywhere else; hah!).
|
|
*/
|
|
struct buf *swbuf;
|
|
|
|
/*
|
|
* Boot time overrides that are not scaled against main memory
|
|
*/
|
|
void
|
|
init_param1(void)
|
|
{
|
|
|
|
hz = HZ;
|
|
TUNABLE_INT_FETCH("kern.hz", &hz);
|
|
tick = 1000000 / hz;
|
|
|
|
#ifdef VM_SWZONE_SIZE_MAX
|
|
maxswzone = VM_SWZONE_SIZE_MAX;
|
|
#endif
|
|
TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
|
|
#ifdef VM_BCACHE_SIZE_MAX
|
|
maxbcache = VM_BCACHE_SIZE_MAX;
|
|
#endif
|
|
TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
|
|
|
|
maxtsiz = MAXTSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz);
|
|
dfldsiz = DFLDSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz);
|
|
maxdsiz = MAXDSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz);
|
|
dflssiz = DFLSSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz);
|
|
maxssiz = MAXSSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz);
|
|
sgrowsiz = SGROWSIZ;
|
|
TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz);
|
|
}
|
|
|
|
/*
|
|
* Boot time overrides that are scaled against main memory
|
|
*/
|
|
void
|
|
init_param2(long physpages)
|
|
{
|
|
|
|
/* Base parameters */
|
|
maxusers = MAXUSERS;
|
|
TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
|
|
if (maxusers == 0) {
|
|
maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
|
|
if (maxusers < 32)
|
|
maxusers = 32;
|
|
if (maxusers > 384)
|
|
maxusers = 384;
|
|
}
|
|
|
|
/*
|
|
* The following can be overridden after boot via sysctl. Note:
|
|
* unless overriden, these macros are ultimately based on maxusers.
|
|
*/
|
|
maxproc = NPROC;
|
|
TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
|
|
/*
|
|
* Limit maxproc so that kmap entries cannot be exhausted by
|
|
* processes.
|
|
*/
|
|
if (maxproc > (physpages / 12))
|
|
maxproc = physpages / 12;
|
|
maxfiles = MAXFILES;
|
|
TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
|
|
maxprocperuid = (maxproc * 9) / 10;
|
|
maxfilesperproc = (maxfiles * 9) / 10;
|
|
|
|
/*
|
|
* Cannot be changed after boot.
|
|
*/
|
|
nbuf = NBUF;
|
|
TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
|
|
|
|
ncallout = 16 + maxproc + maxfiles;
|
|
TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
|
|
}
|
|
|
|
/*
|
|
* Boot time overrides that are scaled against the kernel map
|
|
*/
|
|
void
|
|
init_param3(long kmempages)
|
|
{
|
|
|
|
/*
|
|
* The default for maxpipekva is max(5% of the kernel map, 512KB).
|
|
* See sys_pipe.c for more details.
|
|
*/
|
|
maxpipekva = (kmempages / 20) * PAGE_SIZE;
|
|
if (maxpipekva < 512 * 1024)
|
|
maxpipekva = 512 * 1024;
|
|
TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva);
|
|
}
|