Followings are our kernel variables' default:

  - sb_max: 256K
  - tcbhash_size: 128
  - udbhash_size: 128

These variables are sometime too small for busy server or gateway.

I'd like to modify config(8) to customize these variables without
recompiling the kernel. 

Comment or ok?

Index: usr.sbin/config/cmd.c
===================================================================
RCS file: /disk/cvs/openbsd/src/usr.sbin/config/cmd.c,v
retrieving revision 1.20
diff -u -p -r1.20 cmd.c
--- usr.sbin/config/cmd.c       23 Nov 2013 17:38:15 -0000      1.20
+++ usr.sbin/config/cmd.c       16 Jun 2014 12:25:59 -0000
@@ -24,7 +24,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/device.h>
 #include <sys/time.h>
 
@@ -61,6 +61,11 @@ cmd_table_t cmd_table[] = {
        {"bufcachepercent", Xbufcachepct, "[number]",
         "Show/change BUFCACHEPERCENT"},
        {"nkmempg", Xnkmempg,   "[number]",     "Show/change NKMEMPAGES"},
+       {"sb_max", Xsb_max,     "[number]",     "Show/change sb_max"},
+       {"udbhashsize", Xudbhashsize, "[number]",
+        "Show/change udbhashsize"},
+       {"tcbhashsize", Xtcbhashsize, "[number]",
+        "Show/change tcbhashsize"},
        {NULL,     NULL,        NULL,           NULL}
 };
 
@@ -313,5 +318,58 @@ int
 Xnkmempg(cmd_t *cmd)
 {
        int_variable_adjust(cmd, I_NKMEMPG, "nkmempages");
+       return (CMD_CONT);
+}
+
+int
+Xsb_max(cmd_t *cmd)
+{
+       int_variable_adjust(cmd, I_SB_MAX, "sb_max");
+       return (CMD_CONT);
+}
+
+void
+pow2_variable_adjust(const cmd_t *cmd, int idx, const char *name)
+{
+       int i, *v, num;
+
+       if (nl[idx].n_type != 0) {
+               ukc_mod_kernel = 1;
+
+               v = (int *)adjust((caddr_t)(nl[idx].n_value));
+
+               if (strlen(cmd->args) == 0) {
+                       printf("%s = %d\n", name, *v);
+               } else {
+                       if (number(cmd->args, &num) == 0) {
+                                if (!powerof2(num)) {
+                                       for (i = 0; num; num = num >> 1)
+                                               i++;
+                                       num = 1 << i;
+                                       printf("Warning: number must be "
+                                           "power of 2.  Rounded up to %d\n",
+                                           num);
+                               }
+                               *v = num;
+                               printf("%s = %d\n", name, num);
+                       } else
+                               printf("Unknown argument\n");
+               }
+       } else
+               printf("This kernel does not support modification of %s.\n",
+                   name);
+}
+
+int
+Xudbhashsize(cmd_t *cmd)
+{
+       pow2_variable_adjust(cmd, I_UDBHASHSIZE, "udbhashsize");
+       return (CMD_CONT);
+}
+
+int
+Xtcbhashsize(cmd_t *cmd)
+{
+       pow2_variable_adjust(cmd, I_TCBHASHSIZE, "tcbhashsize");
        return (CMD_CONT);
 }
Index: usr.sbin/config/cmd.h
===================================================================
RCS file: /disk/cvs/openbsd/src/usr.sbin/config/cmd.h,v
retrieving revision 1.7
diff -u -p -r1.7 cmd.h
--- usr.sbin/config/cmd.h       3 Jun 2003 00:52:35 -0000       1.7
+++ usr.sbin/config/cmd.h       16 Jun 2014 11:58:37 -0000
@@ -72,6 +72,9 @@ int Xbufcachepct(cmd_t *);
 int Xnkmempg(cmd_t *);
 int Xshmseg(cmd_t *);
 int Xshmmaxpgs(cmd_t *);
+int Xsb_max(cmd_t *);
+int Xudbhashsize(cmd_t *);
+int Xtcbhashsize(cmd_t *);
 
 #endif /* _CMD_H */
 
Index: usr.sbin/config/config.8
===================================================================
RCS file: /disk/cvs/openbsd/src/usr.sbin/config/config.8,v
retrieving revision 1.60
diff -u -p -r1.60 config.8
--- usr.sbin/config/config.8    20 Jan 2014 01:11:49 -0000      1.60
+++ usr.sbin/config/config.8    16 Jun 2014 11:58:37 -0000
@@ -321,6 +321,21 @@ is the number of minutes west of GMT and
 .Va dst
 is non-zero if Daylight Saving Time is in effect.
 Without arguments, displays its current value.
+.It Ic sb_max Op Ar number
+Change the sb_max value.
+Without arguments, displays its current value.
+.It Ic tcbhashsize Op Ar number
+Change the tcbhashsize value.
+Without arguments, displays its current value.
+The
+.Ar number
+should be power of 2, otherwise it will be rounded up forcibly.
+.It Ic udbhashsize Op Ar number
+Change the tcbhashsize value.
+Without arguments, displays its current value.
+The
+.Ar number
+should be power of 2, otherwise it will be rounded up forcibly.
 .El
 .Sh EXAMPLES (kernel building)
 Note:
Index: usr.sbin/config/ukc.h
===================================================================
RCS file: /disk/cvs/openbsd/src/usr.sbin/config/ukc.h,v
retrieving revision 1.12
diff -u -p -r1.12 ukc.h
--- usr.sbin/config/ukc.h       10 Dec 2009 22:07:19 -0000      1.12
+++ usr.sbin/config/ukc.h       16 Jun 2014 11:58:37 -0000
@@ -48,7 +48,10 @@
 #define I_NMBCLUSTERS  18
 #define I_BUFCACHEPCT  19
 #define I_NKMEMPG      20
-#define NLENTRIES      21
+#define I_SB_MAX       21
+#define I_UDBHASHSIZE  22
+#define I_TCBHASHSIZE  23
+#define NLENTRIES      24
 
 #ifdef UKC_MAIN
 struct nlist nl[] = {
@@ -73,6 +76,9 @@ struct nlist nl[] = {
        { "_nmbclust" },
        { "_bufcachepercent" },
        { "_nkmempages" },
+       { "_sb_max" },
+       { "_udbhashsize" },
+       { "_tcbhashsize" },
        { NULL },
 };
 struct nlist knl[] = {
@@ -97,6 +103,9 @@ struct nlist knl[] = {
        { "_nmbclust" },
        { "_bufcachepercent" },
        { "_nkmempages" },
+       { "_sbmax" },
+       { "_udbhashsize" },
+       { "_tcbhashsize" },
        { NULL },
 };
 int    maxdev = 0;

Reply via email to