From root@gits.dyndns.org  Sat Jun 22 17:15:12 2002
Return-Path: <root@gits.dyndns.org>
Received: from smtp.noos.fr (descartes.noos.net [212.198.2.74])
	by hub.freebsd.org (Postfix) with ESMTP id 15A5D37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 22 Jun 2002 17:15:11 -0700 (PDT)
Received: (qmail 40662461 invoked by uid 0); 23 Jun 2002 00:15:08 -0000
Received: from unknown (HELO gits.gits.dyndns.org) ([212.198.229.153]) (envelope-sender <root@gits.dyndns.org>)
          by 212.198.2.74 (qmail-ldap-1.03) with SMTP
          for <FreeBSD-gnats-submit@freebsd.org>; 23 Jun 2002 00:15:08 -0000
Received: from gits.gits.dyndns.org (jxvhvlq809q369ev@localhost [127.0.0.1])
	by gits.gits.dyndns.org (8.12.3/8.12.3) with ESMTP id g5N0F8AN008234
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Jun 2002 02:15:08 +0200 (CEST)
	(envelope-from root@gits.dyndns.org)
Received: (from root@localhost)
	by gits.gits.dyndns.org (8.12.3/8.12.3/Submit) id g5N0F71B008233;
	Sun, 23 Jun 2002 02:15:07 +0200 (CEST)
	(envelope-from root)
Message-Id: <200206230015.g5N0F71B008233@gits.gits.dyndns.org>
Date: Sun, 23 Jun 2002 02:15:07 +0200 (CEST)
From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
Reply-To: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: hidden kernel boot tunables added to sysctl as read-only mib
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         39681
>Category:       kern
>Synopsis:       [sysctl] [patch] add hidden kernel boot tunables to sysctl as read-only mib
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 22 17:20:01 PDT 2002
>Closed-Date:    Thu Oct 21 19:55:52 UTC 2010
>Last-Modified:  Thu Oct 21 19:55:52 UTC 2010
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 4.6-RC i386
>Organization:
ACME
>Environment:
System: FreeBSD gits 4.6-RC FreeBSD 4.6-RC #11: Sun Jun 9 19:48:37 CEST 2002 root@gits:/disk2/freebsd/src/sys/compile/CUSTOM i386

>Description:
	some kernel boot tunables aren't well documented nor viewabled
	using sysctl.  this patch set add them to the sysctl tree
	as read-only mib and document them in loader.conf.  this
	may help to tune them when necessary by knowing their current
	auto-configured values.

	sys/boot/forth/loader.conf
		hidden kernel boot tunables added.
	sys/sys/sysctl.h
	sys/kern/kern_sysctl.c
		sysctl quad handlers added.
	sys/kern/kern_malloc.c
		kern.vm.kmem.size mib added.
	sys/kern/subr_param.c
		kern.hz, kern.maxswzone, kern.maxbcache, kern.maxtsiz,
		kern.dfldsiz, kern.maxdsiz, kern.dflssiz, kern.maxssiz, 
		kern.sgrowsiz, kern.nbuf, kern.ncallout and kern.ipc.nsfbufs
		mibs added.
>How-To-Repeat:
	# sysctl kern.maxdsiz
	sysctl: unknown oid 'kern.maxdsiz'
>Fix:
Index: sys/boot/forth/loader.conf
===================================================================
RCS file: /home/ncvs/src/sys/boot/forth/loader.conf,v
retrieving revision 1.25.2.18
diff -u -r1.25.2.18 loader.conf
--- forth/loader.conf	28 Apr 2002 22:49:54 -0000	1.25.2.18
+++ forth/loader.conf	22 Jun 2002 23:30:17 -0000
@@ -71,9 +71,32 @@
 ###  Kernel tunables  ########################################
 ##############################################################
 
+#kern.hz="100"			# Granularity of operation
+#kern.maxswzone="73400320"	# Max swmeta KVA storage
+#kern.maxbcache="209715200"	# Max buffer cache KVA storage
+#kern.maxtsiz="134217728"	# Max text size
+#kern.dfldsiz="134217728"	# Initial max data size
+#kern.maxdsiz="536870912"	# Max data size
+#kern.dflssiz="8388608"		# Initial max stack size
+#kern.maxssiz="67108864"	# Max stack size
+#kern.sgrowsiz="131072"		# Amount to grow stack
 #kern.maxusers="32"		# Set size of various static tables
-#kern.ipc.nmbclusters=""	# Set the number of mbuf clusters
+				# defaulted to: physpages/2*1024*1024/PAGE_SIZE
+#kern.maxproc="560"		# Max # of procs per user
+				# defaulted to: 16+20*maxusers
+#kern.maxfiles="1120"		# System wide open files limit
+				# defaulted to: maxproc*2
+#kern.ipc.nsfbufs="1024"	# Max # of sendfile(2) zero-copy virtual buffers
+				# defaulted to: 512+maxusers*16
+#kern.nbuf="0"			# Number of buffer cache KVM reservation
+#kern.ncallout="1696"		# Max # of timer events
+				# defaulted to: 16+maxproc+maxfiles
 #kern.vm.kmem.size=""		# Sets the size of kernel memory (bytes)
+				# defaulted to: v_page_count*PAGE_SIZE/3
+#kern.ipc.nmbclusters="262144"	# Set the number of mbuf clusters
+				# defaulted to: 512+maxusers*16
+#kern.ipc.nmbufs=""		# Maximum number of mbufs available
+				# defaulted to: nmbclusters*4
 #machdep.pccard.pcic_irq="0"	# Assigns PCCARD controller IRQ (0=polled)
 #net.inet.tcp.tcbhashsize=""	# Set the value of TCBHASHSIZE
 #vfs.root.mountfrom=""		# Specify root partition in a way the
Index: sys/sys/sysctl.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/sysctl.h,v
retrieving revision 1.81.2.8
diff -u -r1.81.2.8 sysctl.h
--- sysctl.h	17 Mar 2002 11:08:38 -0000	1.81.2.8
+++ sysctl.h	18 Jun 2002 00:07:22 -0000
@@ -76,6 +76,7 @@
 #define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
 #define	CTLTYPE_LONG	7	/* name describes a long */
 #define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
+#define	CTLTYPE_UQUAD	9	/* name describes a 64-bit unsigned number */
 
 #define CTLFLAG_RD	0x80000000	/* Allow reads of variable */
 #define CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
@@ -140,6 +141,7 @@
 
 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_quad(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_intptr(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
@@ -235,6 +237,24 @@
 #define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	    \
 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|access,	    \
 	ptr, 0, sysctl_handle_long, "LU", descr);
+
+/* Oid for a quad.  The pointer must be non NULL. */
+#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \
+	SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
+		ptr, val, sysctl_handle_quad, "Q", descr)
+
+#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	    \
+	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_QUAD|access,	    \
+	ptr, 0, sysctl_handle_quad, "Q", descr);
+
+/* Oid for a quad.  The pointer must be non NULL. */
+#define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr) \
+	SYSCTL_OID(parent, nbr, name, CTLTYPE_UQUAD|access, \
+		ptr, val, sysctl_handle_quad, "QU", descr)
+
+#define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	    \
+	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UQUAD|access,	    \
+	ptr, 0, sysctl_handle_quad, "QU", descr);
 
 /* Oid for an opaque object.  Specified by a pointer and a length. */
 #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
Index: sys/kern/kern_malloc.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_malloc.c,v
retrieving revision 1.64.2.5
diff -u -r1.64.2.5 kern_malloc.c
--- kern_malloc.c	16 Mar 2002 02:19:51 -0000	1.64.2.5
+++ kern_malloc.c	18 Jun 2002 00:06:50 -0000
@@ -38,6 +38,7 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/sysctl.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
@@ -84,6 +85,11 @@
 static char *kmemlimit;
 
 u_int vm_kmem_size;
+
+SYSCTL_NODE(_kern, OID_AUTO, vm, CTLFLAG_RD, 0, "");
+SYSCTL_NODE(_kern_vm, OID_AUTO, kmem, CTLFLAG_RD, 0, "");
+SYSCTL_UINT(_kern_vm_kmem, OID_AUTO, size, CTLFLAG_RD,
+    &vm_kmem_size, 0, "Kernel VM size");
 
 #ifdef INVARIANTS
 /*
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.92.2.7
diff -u -r1.92.2.7 kern_sysctl.c
--- kern_sysctl.c	6 Mar 2002 05:43:51 -0000	1.92.2.7
+++ kern_sysctl.c	7 Jun 2002 09:10:28 -0000
@@ -771,6 +771,26 @@
 }
 
 /*
+ * Handle a quad, signed or unsigned.  arg1 points to it.
+ */
+
+int
+sysctl_handle_quad(SYSCTL_HANDLER_ARGS)
+{
+	int error = 0;
+
+	if (!arg1)
+		return (EINVAL);
+	error = SYSCTL_OUT(req, arg1, sizeof(quad_t));
+
+	if (error || !req->newptr)
+		return (error);
+
+	error = SYSCTL_IN(req, arg1, sizeof(quad_t));
+	return (error);
+}
+
+/*
  * Handle our generic '\0' terminated 'C' string.
  * Two cases:
  * 	a variable string:  point arg1 at it, arg2 is max length.
Index: sys/kern/subr_param.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_param.c,v
retrieving revision 1.42.2.10
diff -u -r1.42.2.10 subr_param.c
--- subr_param.c	9 Mar 2002 21:05:47 -0000	1.42.2.10
+++ subr_param.c	18 Jun 2002 00:06:24 -0000
@@ -44,6 +44,7 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/sysctl.h>
 #include <sys/kernel.h>
 
 #include <machine/vmparam.h>
@@ -76,7 +77,7 @@
 int	maxfilesperproc;		/* per-proc open files limit */
 int	ncallout;			/* maximum # of timer events */
 int	mbuf_wait = 32;			/* mbuf sleep time in ticks */
-int	nbuf;
+int	nbuf;			/* number of buffer cache KVM reservation */
 int	nswbuf;
 int	maxswzone;			/* max swmeta KVA storage */
 int	maxbcache;			/* max buffer cache KVA storage */
@@ -89,6 +90,33 @@
 
 /* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */
 int	nsfbufs;
+
+SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RD,
+    &hz, 0, "Granularity of operation");
+SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RD,
+    &maxswzone, 0, "Max swmeta KVA storage");
+SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RD,
+    &maxbcache, 0, "Max buffer cache KVA storage");
+SYSCTL_QUAD(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD,
+    &maxtsiz, 0, "Max text size");
+SYSCTL_QUAD(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD,
+    &dfldsiz, 0, "Initial max data size");
+SYSCTL_QUAD(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD,
+    &maxdsiz, 0, "Max data size");
+SYSCTL_QUAD(_kern, OID_AUTO, dflssiz, CTLFLAG_RD,
+    &dflssiz, 0, "Initial max stack size");
+SYSCTL_QUAD(_kern, OID_AUTO, maxssiz, CTLFLAG_RD,
+    &maxssiz, 0, "Max stack size");
+SYSCTL_QUAD(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD,
+    &sgrowsiz, 0, "Amount to grow stack");
+SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RD,
+    &nbuf, 0, "Number of buffer cache KVM reservation");
+SYSCTL_INT(_kern, OID_AUTO, ncallout, CTLFLAG_RD,
+    &ncallout, 0, "Max # of timer events");
+
+SYSCTL_DECL(_kern_ipc);
+SYSCTL_INT(_kern_ipc, OID_AUTO, nsfbufs, CTLFLAG_RD,
+    &nsfbufs, 0, "Max # of sendfile(2) zero-copy virtual buffers");
 
 /*
  * These have to be allocated somewhere; allocating
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: Cyrille Lefevre <cyrille.lefevre@laposte.net>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/39681: hidden kernel boot tunables added to sysctl as
 read-only mib
Date: Sun, 23 Jun 2002 16:42:09 +1000 (EST)

 On Sun, 23 Jun 2002, Cyrille Lefevre wrote:
 
 > >Description:
 >...
 > 	sys/sys/sysctl.h
 > 	sys/kern/kern_sysctl.c
 > 		sysctl quad handlers added.
 
 quad_t's shouldn't be used anywhere.  They are essentially an unportable
 onsolete version of intmax_t's.
 
 > ...
 > Index: sys/kern/subr_param.c
 > ===================================================================
 > RCS file: /home/ncvs/src/sys/kern/subr_param.c,v
 > retrieving revision 1.42.2.10
 > diff -u -r1.42.2.10 subr_param.c
 > --- subr_param.c	9 Mar 2002 21:05:47 -0000	1.42.2.10
 > +++ subr_param.c	18 Jun 2002 00:06:24 -0000
 > @@ -89,6 +90,33 @@
 >
 >  /* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */
 >  int	nsfbufs;
 > +
 > +SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RD,
 > +    &hz, 0, "Granularity of operation");
 > +SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RD,
 > +    &maxswzone, 0, "Max swmeta KVA storage");
 > +SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RD,
 > +    &maxbcache, 0, "Max buffer cache KVA storage");
 > +SYSCTL_QUAD(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD,
 > +    &maxtsiz, 0, "Max text size");
 > +SYSCTL_QUAD(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD,
 > +    &dfldsiz, 0, "Initial max data size");
 > +SYSCTL_QUAD(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD,
 > +    &maxdsiz, 0, "Max data size");
 > +SYSCTL_QUAD(_kern, OID_AUTO, dflssiz, CTLFLAG_RD,
 > +    &dflssiz, 0, "Initial max stack size");
 > +SYSCTL_QUAD(_kern, OID_AUTO, maxssiz, CTLFLAG_RD,
 > +    &maxssiz, 0, "Max stack size");
 > +SYSCTL_QUAD(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD,
 > +    &sgrowsiz, 0, "Amount to grow stack");
 > +SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RD,
 > +    &nbuf, 0, "Number of buffer cache KVM reservation");
 > +SYSCTL_INT(_kern, OID_AUTO, ncallout, CTLFLAG_RD,
 > +    &ncallout, 0, "Max # of timer events");
 
 Support for intmax_t's might not even be needed yet, or might not apply.
 Most of the `siz' variables here have a wrong type (u_quad_t).  They
 should have type vm_size_t or possibly size_t.  But there is a problem
 importing and exporting variables with a typedef'ed types via sysctl()
 and/or TUNABLE*_FETCH().  Sysctl and the tunable mechanism only support
 a limited number of types.  Even u_quad_t's are not supported.  Large
 u_quad_t's are clipped to QUAD_MAX, without checking for overflow of
 course.  u_quad_t's for the `siz' variables only work because the sizes
 are normally < QUAD_MAX even on 64-bit machines.
 
 Bruce
 

From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: Bruce Evans <bde@zeta.org.au>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/39681: hidden kernel boot tunables added to sysctl as read-only mib
Date: Tue, 25 Jun 2002 02:09:31 +0200

 On Sun, Jun 23, 2002 at 04:42:09PM +1000, Bruce Evans wrote:
 > On Sun, 23 Jun 2002, Cyrille Lefevre wrote:
 [snip]
 > > +SYSCTL_QUAD(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD,
 > > +    &maxtsiz, 0, "Max text size");
 > > +SYSCTL_QUAD(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD,
 > > +    &dfldsiz, 0, "Initial max data size");
 > > +SYSCTL_QUAD(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD,
 > > +    &maxdsiz, 0, "Max data size");
 > > +SYSCTL_QUAD(_kern, OID_AUTO, dflssiz, CTLFLAG_RD,
 > > +    &dflssiz, 0, "Initial max stack size");
 > > +SYSCTL_QUAD(_kern, OID_AUTO, maxssiz, CTLFLAG_RD,
 > > +    &maxssiz, 0, "Max stack size");
 > > +SYSCTL_QUAD(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD,
 > > +    &sgrowsiz, 0, "Amount to grow stack");
 [snip]
 > Support for intmax_t's might not even be needed yet, or might not apply.
 > Most of the `siz' variables here have a wrong type (u_quad_t).  They
 > should have type vm_size_t or possibly size_t.  But there is a problem
 > importing and exporting variables with a typedef'ed types via sysctl()
 > and/or TUNABLE*_FETCH().  Sysctl and the tunable mechanism only support
 > a limited number of types.  Even u_quad_t's are not supported.  Large
 > u_quad_t's are clipped to QUAD_MAX, without checking for overflow of
 > course.  u_quad_t's for the `siz' variables only work because the sizes
 > are normally < QUAD_MAX even on 64-bit machines.
 
 so, what to do ?
 
 Cyrille.
 -- 
 Cyrille Lefevre                 mailto:cyrille.lefevre@laposte.net
 12, Rue de Bizerte 75017 Paris  http://clefevre.fr.st
 tel/fax: +33 (0)1 45 22 83 85   gsm: +33 (0)6 80 94 76 63

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, cyrille.lefevre@laposte.net
Cc:  
Subject: Re: kern/39681: [sysctl] [patch] add hidden kernel boot tunables
	to sysctl as read-only mib
Date: Sat, 7 Nov 2009 15:46:39 +0100

 We seem to have had CTLFLAG_RDTUN/CTLFLAG_TUN for quite a while (added
 in -CURRENT on Tue Oct 21 16:48:33 2003), which also cause sysctl(8) to
 tell you you need to edit /boot/loader.conf if you try to set a
 read-only tunable.
 
 Can this be closed now?
 
 -- 
 Jilles Tjoelker
State-Changed-From-To: open->feedback 
State-Changed-By: jh 
State-Changed-When: Wed Oct 20 16:21:17 UTC 2010 
State-Changed-Why:  
Note that submitter has been asked for feedback. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=39681 

From: Jaakko Heinonen <jh@FreeBSD.org>
To: Cyrille Lefevre <cyrille.lefevre@laposte.net>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/39681: [sysctl] [patch] add hidden kernel boot tunables to
 sysctl as read-only mib
Date: Thu, 21 Oct 2010 16:12:43 +0300

 On 2010-10-21, Cyrille Lefevre wrote:
 > may be closed, except that ngroups_max seems to be missing a mib
 > registration such as :
 > 
 > SYSCTL_INT(_kern, OID_AUTO, ngroups, CTLFLAG_RDTUN, &ngroups_max, 0,
 >     "Max number groups per process");
 
 It already exists in sys/kern/kern_mib.c in head and stable/8:
 
    127	SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN,
    128	    &ngroups_max, 0,
    129	    "Maximum number of supplemental groups a user can belong to");
 
 -- 
 Jaakko
State-Changed-From-To: feedback->closed 
State-Changed-By: jh 
State-Changed-When: Thu Oct 21 19:55:51 UTC 2010 
State-Changed-Why:  
Submitter considers this resolved. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=39681 
>Unformatted:
