xref: /illumos-gate/usr/src/uts/common/conf/param.c (revision 9174bfaa08ca3aa4c0a12e840c4bd4f2570237a0)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
24  * Copyright (c) 1983, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Copyright 2012 Milan Jurik. All rights reserved.
26  * Copyright 2022 Garrett D'Amore <garrett@damore.org>
27  */
28 
29 #include <sys/types.h>
30 #include <sys/time.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/signal.h>
34 #include <sys/sysmacros.h>
35 #include <sys/cmn_err.h>
36 #include <sys/user.h>
37 #include <sys/proc.h>
38 #include <sys/task.h>
39 #include <sys/project.h>
40 #include <sys/klwp.h>
41 #include <sys/vnode.h>
42 #include <sys/file.h>
43 #include <sys/fcntl.h>
44 #include <sys/flock.h>
45 #include <sys/var.h>
46 #include <sys/stream.h>
47 #include <sys/strsubr.h>
48 #include <sys/conf.h>
49 #include <sys/class.h>
50 #include <sys/ts.h>
51 #include <sys/rt.h>
52 #include <sys/exec.h>
53 #include <sys/exechdr.h>
54 #include <sys/buf.h>
55 #include <sys/resource.h>
56 #include <vm/seg.h>
57 #include <vm/pvn.h>
58 #include <vm/seg_kmem.h>
59 #include <sys/vmparam.h>
60 #include <sys/machparam.h>
61 #include <sys/utsname.h>
62 #include <sys/kmem.h>
63 #include <sys/stack.h>
64 #include <sys/modctl.h>
65 #include <sys/fdbuffer.h>
66 #include <sys/cyclic_impl.h>
67 #include <sys/disp.h>
68 #include <sys/tuneable.h>
69 #include <sys/systeminfo.h>
70 
71 #include <sys/vmem.h>
72 #include <sys/clock.h>
73 #include <sys/clock_impl.h>
74 #include <sys/serializer.h>
75 
76 /*
77  * The following few lines describe generic things that must be compiled
78  * into the booted executable (unix) rather than genunix or any other
79  * module because they're required by crash dump readers, etc.
80  */
81 struct modctl modules;		/* head of linked list of modules */
82 char *default_path;		/* default module loading path */
83 struct swapinfo *swapinfo;	/* protected by the swapinfo_lock */
84 proc_t *practive;		/* active process list */
85 uint_t nproc;			/* current number of processes */
86 proc_t p0;			/* process 0 */
87 struct plock p0lock;		/* p0's p_lock */
88 klwp_t lwp0;			/* t0's lwp */
89 task_t *task0p;			/* task 0 */
90 kproject_t *proj0p;		/* location of project 0 */
91 
92 /*
93  * The following are "implementation architecture" dependent constants made
94  * available here in the form of initialized data for use by "implementation
95  * architecture" independent modules. See machparam.h.
96  */
97 const unsigned long	_pagesize	= (unsigned long)PAGESIZE;
98 const unsigned int	_pageshift	= (unsigned int)PAGESHIFT;
99 const unsigned long	_pageoffset	= (unsigned long)PAGEOFFSET;
100 /*
101  * XXX - This value pagemask has to be a 64bit size because
102  * large file support uses this mask on offsets which are 64 bit size.
103  * using unsigned leaves the higher 32 bits value as zero thus
104  * corrupting offset calculations in the file system and VM.
105  */
106 const u_longlong_t	_pagemask	= (u_longlong_t)PAGEMASK;
107 const unsigned long	_mmu_pagesize	= (unsigned long)MMU_PAGESIZE;
108 const unsigned int	_mmu_pageshift	= (unsigned int)MMU_PAGESHIFT;
109 const unsigned long	_mmu_pageoffset	= (unsigned long)MMU_PAGEOFFSET;
110 const unsigned long	_mmu_pagemask	= (unsigned long)MMU_PAGEMASK;
111 uintptr_t		_kernelbase	= (uintptr_t)KERNELBASE;
112 uintptr_t		_userlimit	= (uintptr_t)USERLIMIT;
113 uintptr_t		_userlimit32	= (uintptr_t)USERLIMIT32;
114 const uintptr_t		_argsbase	= (uintptr_t)ARGSBASE;
115 const unsigned int	_diskrpm	= (unsigned int)DISKRPM;
116 const unsigned long	_pgthresh	= (unsigned long)PGTHRESH;
117 const unsigned int	_maxslp		= (unsigned int)MAXSLP;
118 const unsigned long	_maxhandspreadpages = (unsigned long)MAXHANDSPREADPAGES;
119 const int		_ncpu		= (int)NCPU;
120 const int		_ncpu_log2	= (int)NCPU_LOG2;
121 const int		_ncpu_p2	= (int)NCPU_P2;
122 const unsigned long	_defaultstksz	= (unsigned long)DEFAULTSTKSZ;
123 const unsigned int	_nbpg		= (unsigned int)MMU_PAGESIZE;
124 
125 /*
126  * System parameter formulae.
127  *
128  * This file is copied into each directory where we compile
129  * the kernel; it should be modified there to suit local taste
130  * if necessary.
131  */
132 
133 /*
134  * hz is 100, but we set hires_tick to get higher resolution clock behavior
135  * (currently defined to be 1000 hz).  Higher values seem to work, but are not
136  * supported.
137  *
138  * This is configured via hires_tick to allow users to explicitly customize it
139  * to 0 should the need arise.
140  *
141  * If we do decide to play with higher values, remember that hz should
142  * satisfy the following constraints to avoid integer round-off problems:
143  *
144  * (1) hz should be in the range 100 <= hz <= MICROSEC.  If hz exceeds
145  *     MICROSEC, usec_per_tick will be zero and lots of stuff will break.
146  *     Similarly, if hz < 100 then hz / 100 == 0 and stuff will break.
147  *
148  * (2) If hz <= 1000, it should be both a multiple of 100 and a
149  *	divisor of 1000.
150  *
151  * (3) If hz > 1000, it should be both a multiple of 1000 and a
152  *	divisor of MICROSEC.
153  *
154  * Thus the only reasonable values of hz (i.e. the values that won't
155  * cause roundoff error) are: 100, 200, 500, 1000, 2000, 4000, 5000,
156  * 8000, 10000, 20000, 25000, 40000, 50000, 100000, 125000, 200000,
157  * 250000, 500000, 1000000.  As of this writing (1996) a clock rate
158  * of more than about 10 kHz seems utterly ridiculous, although
159  * this observation will no doubt seem quaintly amusing one day.
160  */
161 #define	HIRES_HZ_DEFAULT	1000
162 
163 int hz = HZ_DEFAULT;
164 int hires_hz = HIRES_HZ_DEFAULT;
165 
166 int hires_tick = 1;
167 int cpu_decay_factor = 10;	/* this is no longer tied to clock */
168 int max_hres_adj;	/* maximum adjustment of hrtime per tick */
169 int tick_per_msec;	/* clock ticks per millisecond (zero if hz < 1000) */
170 
171 /*
172  * Milliseconds, Microseconds, and Nanoseconds per clock tick
173  *
174  * Note:
175  *  msec_per_tick is zero if hz > 1000
176  */
177 int msec_per_tick;
178 int usec_per_tick;
179 int nsec_per_tick;
180 
181 /*
182  * Time Resolution values. These are defined in condvar.h and initialized in
183  * param_init(). Consumers of cv_reltimedwait() and cv_reltimedwait_sig()
184  * need to specify how accurate the timeout argument should be through
185  * one of these values. The intention is to allow the underlying implementation
186  * to anticipate or defer the expiration of timeouts, preventing unnecessary
187  * wakeups by batch processing similarly expiring events.
188  */
189 time_res_t time_res[TR_COUNT];
190 
191 /*
192  * Setting "snooping" to a non-zero value will cause a deadman panic if
193  * snoop_interval microseconds elapse without lbolt increasing.  The default
194  * snoop_interval is 50 seconds.
195  */
196 #define	SNOOP_INTERVAL_MIN	(MICROSEC)
197 #define	SNOOP_INTERVAL_DEFAULT	(50 * MICROSEC)
198 
199 int snooping = 0;
200 uint_t snoop_interval = SNOOP_INTERVAL_DEFAULT;
201 
202 /*
203  * Tables of initialization functions, called from main().
204  */
205 
206 extern void system_taskq_init(void);
207 extern void binit(void);
208 extern void space_init(void);
209 extern void dnlc_init(void);
210 extern void vfsinit(void);
211 extern void finit(void);
212 extern void strinit(void);
213 extern void flk_init(void);
214 extern void ftrace_init(void);
215 extern void softcall_init(void);
216 extern void ttyinit(void);
217 extern void schedctl_init(void);
218 extern void deadman_init(void);
219 extern void clock_timer_init(void);
220 extern void clock_realtime_init(void);
221 extern void clock_highres_init(void);
222 extern void clock_thread_init(void);
223 extern void clock_process_init(void);
224 extern void clock_tick_mp_init(void);
225 extern void cu_init(void);
226 extern void callout_mp_init(void);
227 extern void cpu_seq_tbl_init(void);
228 
229 void	(*init_tbl[])(void) = {
230 	system_taskq_init,
231 	binit,
232 	space_init,
233 	dnlc_init,
234 	vfsinit,
235 	finit,
236 	strinit,
237 	serializer_init,
238 	softcall_init,
239 	ttyinit,
240 	as_init,
241 	pvn_init,
242 	anon_init,
243 	segvn_init,
244 	flk_init,
245 	cpu_seq_tbl_init,
246 	schedctl_init,
247 	fdb_init,
248 	deadman_init,
249 	clock_timer_init,
250 	clock_realtime_init,
251 	clock_highres_init,
252 	clock_thread_init,
253 	clock_process_init,
254 	NULL
255 };
256 
257 
258 #if defined(__sparc)
259 	extern void siron_mp_init();
260 #endif
261 
262 /*
263  * Any per cpu resources should be initialized via
264  * an entry in mp_init_tbl().
265  */
266 void	(*mp_init_tbl[])(void) = {
267 	ftrace_init,
268 	cyclic_mp_init,
269 #if defined(__sparc)
270 	siron_mp_init,
271 #endif
272 	clock_tick_mp_init,
273 	cu_init,
274 	callout_mp_init,
275 	0
276 };
277 
278 int maxusers;		/* kitchen-sink knob for dynamic configuration */
279 
280 /*
281  * pidmax -- highest pid value assigned by the system
282  * Settable in /etc/system
283  */
284 int pidmax = DEFAULT_MAXPID;
285 
286 /*
287  * jump_pid - if set, this value is where pid numbers should start
288  * after the first few system pids (0-3) are used.  If 0, pids are
289  * chosen in the usual way. This variable can be used to quickly
290  * create large pids (by setting it to 100000, for example). pids
291  * less than this value will never be chosen.
292  */
293 pid_t jump_pid = DEFAULT_JUMPPID;
294 
295 /*
296  * autoup -- used in struct var for dynamic config of the age a delayed-write
297  * buffer must be in seconds before bdflush will write it out.
298  */
299 #define	DEFAULT_AUTOUP	30
300 int autoup = DEFAULT_AUTOUP;
301 
302 /*
303  * bufhwm -- tuneable variable for struct var for v_bufhwm.
304  * high water mark for buffer cache mem usage in units of K bytes.
305  *
306  * bufhwm_pct -- ditto, but given in % of physmem.
307  */
308 int bufhwm = 0;
309 int bufhwm_pct = 0;
310 
311 /*
312  * Process table.
313  */
314 int maxpid;
315 int max_nprocs;		/* set in param_init() */
316 int maxuprc;		/* set in param_init() */
317 int reserved_procs;
318 int nthread = 1;
319 
320 /*
321  * UFS tunables
322  */
323 int ufs_ninode;		/* declared here due to backwards compatibility */
324 int ndquot;		/* declared here due to backwards compatibility */
325 
326 /*
327  * Exec switch table. This is used by the generic exec module
328  * to switch out to the desired executable type, based on the
329  * magic number. The currently supported types are ELF, a.out
330  * (both NMAGIC and ZMAGIC), interpreter (#!) files,
331  * and Java executables.
332  */
333 /*
334  * Magic numbers
335  */
336 short elfmagic = 0x7f45;
337 short intpmagic = 0x2321;
338 short jmagic = 0x504b;
339 
340 short nomagic = 0;
341 
342 /*
343  * Magic strings
344  */
345 #define	ELF32MAGIC_STRING	"\x7f""ELF\x1"
346 #define	ELF64MAGIC_STRING	"\x7f""ELF\x2"
347 #define	INTPMAGIC_STRING	"#!"
348 #define	JAVAMAGIC_STRING	"PK\003\004"
349 #define	NOMAGIC_STRING		""
350 
351 #define	SHBIN_CNTL(x)	((x)&037)
352 #define	SHBINMAGIC_STRING {SHBIN_CNTL('k'), SHBIN_CNTL('s'), SHBIN_CNTL('h'), 0}
353 #define	SHBINMAGIC_LEN	4
354 
355 char elf32magicstr[] = ELF32MAGIC_STRING;
356 char elf64magicstr[] = ELF64MAGIC_STRING;
357 char intpmagicstr[] = INTPMAGIC_STRING;
358 char shbinmagicstr[] = SHBINMAGIC_STRING;
359 char javamagicstr[] = JAVAMAGIC_STRING;
360 char nomagicstr[] = NOMAGIC_STRING;
361 
362 char *execswnames[] = {
363 	"elfexec",	/* Elf32 */
364 #ifdef _LP64
365 	"elfexec",	/* Elf64 */
366 #endif
367 	"intpexec",
368 	"shbinexec",
369 	"javaexec",
370 	NULL,
371 	NULL,
372 	NULL
373 };
374 
375 struct execsw execsw[] = {
376 	{ elf32magicstr, 0, 5, NULL, NULL, NULL },
377 #ifdef _LP64
378 	{ elf64magicstr, 0, 5, NULL, NULL, NULL },
379 #endif
380 	{ intpmagicstr, 0, 2, NULL, NULL, NULL },
381 	{ shbinmagicstr, 0, SHBINMAGIC_LEN, NULL, NULL, NULL },
382 	{ javamagicstr, 0, 4, NULL, NULL, NULL },
383 	{ nomagicstr, 0, 0, NULL, NULL, NULL },
384 	{ nomagicstr, 0, 0, NULL, NULL, NULL },
385 	{ nomagicstr, 0, 0, NULL, NULL, NULL },
386 	{ nomagicstr, 0, 0, NULL, NULL, NULL }
387 };
388 int nexectype = sizeof (execsw) / sizeof (execsw[0]);	/* # of exec types */
389 kmutex_t execsw_lock;	/* Used for allocation of execsw entries */
390 
391 /*
392  * symbols added to make changing proc.max-file-descriptor
393  * simple via /etc/system
394  */
395 #define	RLIM_FD_CUR 0x10000
396 #define	RLIM_FD_MAX 0x10000
397 
398 uint_t rlim_fd_cur = RLIM_FD_CUR;
399 uint_t rlim_fd_max = RLIM_FD_MAX;
400 
401 /*
402  * (Default resource limits were formerly declared here, but are now provided by
403  * the more general resource controls framework.)
404  */
405 
406 /*
407  * STREAMS tunables
408  */
409 int	nstrpush = 9;		/* maximum # of modules/drivers on a stream */
410 ssize_t	strctlsz = 1024;	/* maximum size of user-generated M_PROTO */
411 ssize_t	strmsgsz = 0x10000;	/* maximum size of user-generated M_DATA */
412 				/* for `strmsgsz', zero means unlimited */
413 /*
414  * Filesystem tunables
415  */
416 int	rstchown = 1;		/* POSIX_CHOWN_RESTRICTED is enabled */
417 int	ngroups_max = NGROUPS_MAX_DEFAULT;
418 
419 /*
420  * generic scheduling stuff
421  *
422  * Configurable parameters for RT and TS are in the respective
423  * scheduling class modules.
424  */
425 
426 pri_t maxclsyspri = MAXCLSYSPRI;
427 pri_t minclsyspri = MINCLSYSPRI;
428 char sys_name[] = "SYS";
429 
430 extern pri_t sys_init(id_t, int, classfuncs_t **);
431 extern classfuncs_t sys_classfuncs;
432 
433 sclass_t sclass[] = {
434 	{ "SYS",	sys_init,	&sys_classfuncs, STATIC_SCHED, 0 },
435 	{ "",	NULL,	NULL,	NULL, 0 },
436 	{ "",	NULL,	NULL,	NULL, 0 },
437 	{ "",	NULL,	NULL,	NULL, 0 },
438 	{ "",	NULL,	NULL,	NULL, 0 },
439 	{ "",	NULL,	NULL,	NULL, 0 },
440 	{ "",	NULL,	NULL,	NULL, 0 },
441 	{ "",	NULL,	NULL,	NULL, 0 },
442 	{ "",	NULL,	NULL,	NULL, 0 },
443 	{ "",	NULL,	NULL,	NULL, 0 }
444 };
445 
446 int loaded_classes = 1;		/* for loaded classes */
447 kmutex_t class_lock;		/* lock for class[] */
448 
449 int nclass = sizeof (sclass) / sizeof (sclass_t);
450 char initcls[] = "TS";
451 char *defaultclass = initcls;
452 
453 /*
454  * Tunable system parameters.
455  */
456 
457 /*
458  * The integers tune_* are done this way so that the tune
459  * data structure may be "tuned" if necessary from the /etc/system
460  * file. The tune data structure is initialized in param_init();
461  */
462 
463 tune_t tune;
464 
465 /*
466  * If freemem < t_getpgslow, then start to steal pages from processes.
467  */
468 int tune_t_gpgslo = 25;
469 
470 /*
471  * Rate at which fsflush is run, in seconds.
472  */
473 #define	DEFAULT_TUNE_T_FSFLUSHR	1
474 int tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR;
475 
476 /*
477  * The minimum available resident (not swappable) memory to maintain
478  * in order to avoid deadlock.  In pages.
479  */
480 int tune_t_minarmem = 25;
481 
482 /*
483  * The minimum available swappable memory to maintain in order to avoid
484  * deadlock.  In pages.
485  */
486 int tune_t_minasmem = 25;
487 
488 int tune_t_flckrec = 512;	/* max # of active frlocks */
489 
490 /*
491  * Number of currently available pages that cannot be 'locked'
492  * This is set in init_pages_pp_maximum, and must be initialized
493  * to zero here to detect an override in /etc/system
494  */
495 pgcnt_t pages_pp_maximum = 0;
496 
497 int boothowto;			/* boot flags passed to kernel */
498 struct var v;			/* System Configuration Information */
499 
500 /*
501  * System Configuration Information
502  */
503 
504 /*
505  * The physical system's host identifier, expressed as a decimal string.
506  * Code should only directly access this value when writing to it (setting the
507  * physical system's host identifier).  Code that reads the physical system's
508  * host identifier should use zone_get_hostid(NULL) instead.
509  */
510 char hw_serial[HW_HOSTID_LEN] = "0";
511 
512 #if defined(__sparc)
513 
514 /*
515  * On sparc machines, read hw_serial from the firmware at boot time
516  * and simply assert Oracle is the hardware provider.
517  */
518 char architecture[] = "sparcv9";
519 char architecture_32[] = "sparc";
520 char hw_provider[] = "Oracle Corporation";
521 
522 #elif defined(__amd64)
523 
524 char architecture[] = "amd64";
525 char architecture_32[] = "i386";
526 char hw_provider[SYS_NMLN] = "";
527 
528 #else
529 #error "unknown processor architecture"
530 #endif
531 
532 char srpc_domain[SYS_NMLN] = "";
533 char platform[SYS_NMLN] = "";	/* read from the devinfo root node */
534 
535 /* Initialize isa_list */
536 char *isa_list = architecture;
537 
538 static pgcnt_t original_physmem = 0;
539 
540 #define	MIN_DEFAULT_MAXUSERS	8u
541 #define	MAX_DEFAULT_MAXUSERS	2048u
542 #define	MAX_MAXUSERS		4096u
543 
544 void
param_preset(void)545 param_preset(void)
546 {
547 	original_physmem = physmem;
548 }
549 
550 void
param_calc(int platform_max_nprocs)551 param_calc(int platform_max_nprocs)
552 {
553 	/*
554 	 * Default to about one "user" per megabyte, taking into
555 	 * account both physical and virtual constraints.
556 	 * Note: 2^20 is a meg; shifting right by (20 - PAGESHIFT)
557 	 * converts pages to megs without integer overflow.
558 	 */
559 #if defined(__sparc)
560 	if (physmem > original_physmem) {
561 		physmem = original_physmem;
562 		cmn_err(CE_NOTE, "physmem limited to %ld", physmem);
563 	}
564 #endif
565 	if (maxusers == 0) {
566 		pgcnt_t physmegs = physmem >> (20 - PAGESHIFT);
567 		pgcnt_t virtmegs = vmem_size(heap_arena, VMEM_FREE) >> 20;
568 		maxusers = MIN(MAX(MIN(physmegs, virtmegs),
569 		    MIN_DEFAULT_MAXUSERS), MAX_DEFAULT_MAXUSERS);
570 	}
571 	if (maxusers > MAX_MAXUSERS) {
572 		maxusers = MAX_MAXUSERS;
573 		cmn_err(CE_NOTE, "maxusers limited to %d", MAX_MAXUSERS);
574 	}
575 
576 #ifdef DEBUG
577 	/*
578 	 * The purpose of maxusers is to prevent memory overcommit.
579 	 * DEBUG kernels take more space, so reduce maxusers a bit.
580 	 */
581 	maxusers = (3 * maxusers) / 4;
582 #endif
583 
584 	/*
585 	 * We need to dynamically change any variables now so that
586 	 * the setting of maxusers and pidmax propagate to the other
587 	 * variables that are dependent on them.
588 	 */
589 	if (reserved_procs == 0)
590 		reserved_procs = 5;
591 	if (pidmax < reserved_procs || pidmax > MAX_MAXPID)
592 		maxpid = MAX_MAXPID;
593 	else
594 		maxpid = pidmax;
595 
596 	/*
597 	 * This allows platform-dependent code to constrain the maximum
598 	 * number of processes allowed in case there are e.g. VM limitations
599 	 * with how many contexts are available.
600 	 */
601 	if (max_nprocs == 0)
602 		max_nprocs = (10 + 16 * maxusers);
603 	if (platform_max_nprocs > 0 && max_nprocs > platform_max_nprocs)
604 		max_nprocs = platform_max_nprocs;
605 	if (max_nprocs > maxpid)
606 		max_nprocs = maxpid;
607 
608 	if (maxuprc == 0)
609 		maxuprc = (max_nprocs - reserved_procs);
610 }
611 
612 void
param_init(void)613 param_init(void)
614 {
615 	/*
616 	 * Set each individual element of struct var v to be the
617 	 * default value. This is done this way
618 	 * so that a user can set the assigned integer value in the
619 	 * /etc/system file *IF* tuning is needed.
620 	 */
621 	v.v_proc = max_nprocs;	/* v_proc - max # of processes system wide */
622 	v.v_maxupttl = max_nprocs - reserved_procs;
623 	v.v_maxsyspri = (int)maxclsyspri;  /* max global pri for sysclass */
624 	v.v_maxup = MIN(maxuprc, v.v_maxupttl); /* max procs per user */
625 	v.v_autoup = autoup;	/* v_autoup - delay for delayed writes */
626 
627 	/*
628 	 * Set each individual element of struct tune to be the
629 	 * default value. Each struct element This is done this way
630 	 *  so that a user can set the assigned integer value in the
631 	 * /etc/system file *IF* tuning is needed.
632 	 */
633 	tune.t_gpgslo = tune_t_gpgslo;
634 	tune.t_fsflushr = tune_t_fsflushr;
635 	tune.t_minarmem = tune_t_minarmem;
636 	tune.t_minasmem = tune_t_minasmem;
637 	tune.t_flckrec = tune_t_flckrec;
638 
639 	/*
640 	 * Initialization for file descriptors to correct mistaken settings in
641 	 * /etc/system.  Initialization of limits performed by resource control
642 	 * system.
643 	 */
644 	if (rlim_fd_cur > rlim_fd_max)
645 		rlim_fd_cur = rlim_fd_max;
646 
647 	/*
648 	 * calculations needed if hz was set in /etc/system
649 	 */
650 	if (hires_tick)
651 		hz = hires_hz;
652 
653 	tick_per_msec = hz / MILLISEC;
654 	msec_per_tick = MILLISEC / hz;
655 	usec_per_tick = MICROSEC / hz;
656 	nsec_per_tick = NANOSEC / hz;
657 	max_hres_adj = nsec_per_tick >> ADJ_SHIFT;
658 
659 	/*
660 	 * Consumers of relative timedwait functions must specify how accurately
661 	 * the given timeout must expire. This is currently TR_CLOCK_TICK for
662 	 * the vast majority of consumers, but nsec_per_tick becomes an
663 	 * artificial value in a tickless world. Each caller of such routines
664 	 * should re-evaluate their usage and specify the appropriate
665 	 * resolution.
666 	 */
667 	time_res[TR_NANOSEC] = NANOSEC / NANOSEC;
668 	time_res[TR_MICROSEC] = NANOSEC / MICROSEC;
669 	time_res[TR_MILLISEC] = NANOSEC / MILLISEC;
670 	time_res[TR_SEC] = NANOSEC / SEC;
671 	time_res[TR_CLOCK_TICK] = nsec_per_tick;
672 }
673 
674 /*
675  * Validate tuneable parameters following /etc/system processing,
676  * but prior to param_init().
677  */
678 void
param_check(void)679 param_check(void)
680 {
681 #if defined(__x86)
682 	if (physmem != original_physmem) {
683 		cmn_err(CE_NOTE, "physmem cannot be modified to 0x%lx"
684 		    " via /etc/system. Please use eeprom(8) instead.",
685 		    physmem);
686 		physmem = original_physmem;
687 	}
688 #endif
689 	if (ngroups_max < NGROUPS_UMIN)
690 		ngroups_max = NGROUPS_UMIN;
691 	if (ngroups_max > NGROUPS_UMAX)
692 		ngroups_max = NGROUPS_UMAX;
693 
694 	/* If we have many groups then the ucred proto message also grows. */
695 	if (ngroups_max > NGROUPS_OLDMAX &&
696 	    strctlsz < (ngroups_max - NGROUPS_OLDMAX) * sizeof (gid_t) + 1024) {
697 		strctlsz = (ngroups_max - NGROUPS_OLDMAX) * sizeof (gid_t) +
698 		    1024;
699 	}
700 
701 	if (autoup <= 0) {
702 		autoup = DEFAULT_AUTOUP;
703 		cmn_err(CE_WARN, "autoup <= 0; defaulting to %d", autoup);
704 	}
705 
706 	if (tune_t_fsflushr <= 0) {
707 		tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR;
708 		cmn_err(CE_WARN, "tune_t_fsflushr <= 0; defaulting to %d",
709 		    tune_t_fsflushr);
710 	}
711 
712 	if (jump_pid < 0 || jump_pid >= pidmax) {
713 		jump_pid = 0;
714 		cmn_err(CE_WARN, "jump_pid < 0 or >= pidmax; ignored");
715 	}
716 
717 	if (snoop_interval < SNOOP_INTERVAL_MIN) {
718 		snoop_interval = SNOOP_INTERVAL_DEFAULT;
719 		cmn_err(CE_WARN, "snoop_interval < minimum (%d); defaulting"
720 		    " to %d", SNOOP_INTERVAL_MIN, SNOOP_INTERVAL_DEFAULT);
721 	}
722 }
723