Subject: db(3) parameters and cap_mkdb
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 08/19/2003 15:17:54
--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

A while ago I was playing around with the size of cap_mkdb'd files (and
then forgot all about it).  There's two parameters that govern the size
of the resultant db hash files - the bucket size (bsize) and the density
(ffactor).  The defaults for these are 4096 and 16 respectively.  With a
little bit of experimenting, we can get the size of the largest .db file
(termcap) to nearly half the size that we currently ship:

bigkev 116> wc termcap.src
   13016   60260  554120 termcap.src
bigkev 117> ./cap_mkdb -l -f termcap termcap.src ; ls -l termcap.db
-rw-r--r--  1 simonb  wheel  2351104 Aug 15 23:08 termcap.db
bigkev 118> ./cap_mkdb -B 32768 -F 256 -l -f termcap termcap.src ; ls -l termcap.db
-rw-r--r--  1 simonb  wheel  1212416 Aug 15 23:08 termcap.db

The following patch adds -B and -F flags to set these parameters (yes,
need to update the man page as well).  Any objections to doing this and
also changing share/termcap/Makefile to use the different parameters so
we can ship a smaller termcap.db?

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/

--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: cap_mkdb.c
===================================================================
RCS file: /cvsroot/src/usr.bin/cap_mkdb/cap_mkdb.c,v
retrieving revision 1.17
diff -d -p -u -r1.17 cap_mkdb.c
--- cap_mkdb.c	2003/01/31 20:50:30	1.17
+++ cap_mkdb.c	2003/08/19 05:14:56
@@ -90,12 +90,23 @@ HASHINFO openinfo = {
 int
 main(int argc, char *argv[])
 {
-	int c, byteorder;
+	char *p;
+	int byteorder, c, num;
 
 	capname = NULL;
 	byteorder = 0;
-	while ((c = getopt(argc, argv, "bf:lv")) != -1) {
+	while ((c = getopt(argc, argv, "B:bF:f:lv")) != -1) {
 		switch(c) {
+		case 'B':
+		case 'F':
+			num = strtol(optarg, &p, 10);
+			if (*p)
+				errx(1, "illegal number: %s", optarg);
+			if (c == 'B')
+				openinfo.bsize = num;
+			else
+				openinfo.ffactor = num;
+			break;
 		case 'b':
 		case 'l':
 			if (byteorder != 0)

--Nq2Wo0NMKNjxTN9z--