summaryrefslogtreecommitdiffstats
path: root/usr.sbin/kvm_mkdb
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-01-10 18:37:12 +0000
committerphk <phk@FreeBSD.org>1995-01-10 18:37:12 +0000
commita7c5c4d132309ac257df0af3d6eaad33133e9ba6 (patch)
tree7f71f0d01caa2f599795e6ba560f642e9620aaa1 /usr.sbin/kvm_mkdb
parent47bbf47f3cf8c044f276a2d32db2b4c6f533bfd1 (diff)
downloadFreeBSD-src-a7c5c4d132309ac257df0af3d6eaad33133e9ba6.zip
FreeBSD-src-a7c5c4d132309ac257df0af3d6eaad33133e9ba6.tar.gz
Speed kvm_mkdb up by a factor 5 or thereabout. Rewrote all the fseek/fread
nonsense to use a mmap'ed file instead and told the DB/hash what we are up to. dev_mkdb could maybe benefit from the same treatment.
Diffstat (limited to 'usr.sbin/kvm_mkdb')
-rw-r--r--usr.sbin/kvm_mkdb/kvm_mkdb.c10
-rw-r--r--usr.sbin/kvm_mkdb/nlist.c115
2 files changed, 48 insertions, 77 deletions
diff --git a/usr.sbin/kvm_mkdb/kvm_mkdb.c b/usr.sbin/kvm_mkdb/kvm_mkdb.c
index 2315352..9754af0 100644
--- a/usr.sbin/kvm_mkdb/kvm_mkdb.c
+++ b/usr.sbin/kvm_mkdb/kvm_mkdb.c
@@ -65,6 +65,7 @@ main(argc, argv)
DB *db;
int ch;
char *p, *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN];
+ HASHINFO hdefault;
while ((ch = getopt(argc, argv, "")) != EOF)
switch (ch) {
@@ -91,8 +92,15 @@ main(argc, argv)
(void)snprintf(dbname, sizeof(dbname), "%skvm_%s.db",
_PATH_VARDB, nlistname);
(void)umask(0);
+
+ /* don't handicap db/hash by using the defaults... */
+ memset(&hdefault,0,sizeof hdefault);
+ hdefault.bsize = NBPG;
+ hdefault.cachesize = 50*NBPG;
+ hdefault.nelem = 1000;
+
db = dbopen(dbtemp, O_CREAT | O_EXLOCK | O_TRUNC | O_RDWR,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, DB_HASH, NULL);
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, DB_HASH, &hdefault);
if (db == NULL)
err(1, "%s", dbtemp);
create_knlist(nlistpath, db);
diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c
index f1d004c..a606731 100644
--- a/usr.sbin/kvm_mkdb/nlist.c
+++ b/usr.sbin/kvm_mkdb/nlist.c
@@ -36,6 +36,8 @@ static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/param.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@@ -60,8 +62,6 @@ typedef struct nlist NLIST;
#define badfmt(str) errx(1, "%s: %s: %s", kfile, str, strerror(EFTYPE))
-static void badread __P((int, char *));
-
static char *kfile;
void
@@ -70,71 +70,56 @@ create_knlist(name, db)
DB *db;
{
register int nsyms;
- struct exec ebuf;
- FILE *fp;
- NLIST nbuf;
+ struct exec *ebuf;
+ NLIST *nbuf;
DBT data, key;
- int fd, nr, strsize;
- char *strtab, buf[1024];
+ int fd;
+ char *strtab;
+ u_char *filep;
+ char *vp;
+ struct stat sst;
+ long cur_off, voff;
kfile = name;
if ((fd = open(name, O_RDONLY, 0)) < 0)
err(1, "%s", name);
+
+ fstat(fd,&sst);
+
+ filep = (u_char*)mmap(0, sst.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
/* Read in exec structure. */
- nr = read(fd, &ebuf, sizeof(struct exec));
- if (nr != sizeof(struct exec))
- badfmt("no exec header");
+ ebuf = (struct exec *) filep;
/* Check magic number and symbol count. */
- if (N_BADMAG(ebuf))
+ if (N_BADMAG(*ebuf))
badfmt("bad magic number");
- if (!ebuf.a_syms)
+ if (!ebuf->a_syms)
badfmt("stripped");
- /* Seek to string table. */
- if (lseek(fd, N_STROFF(ebuf), SEEK_SET) == -1)
- badfmt("corrupted string table");
-
- /* Read in the size of the symbol table. */
- nr = read(fd, (char *)&strsize, sizeof(strsize));
- if (nr != sizeof(strsize))
- badread(nr, "no symbol table");
-
- /* Read in the string table. */
- strsize -= sizeof(strsize);
- if (!(strtab = malloc(strsize)))
- err(1, NULL);
- if ((nr = read(fd, strtab, strsize)) != strsize)
- badread(nr, "corrupted symbol table");
+ strtab = filep + N_STROFF(*ebuf) + sizeof (int);
/* Seek to symbol table. */
- if (!(fp = fdopen(fd, "r")))
- err(1, "%s", name);
- if (fseek(fp, N_SYMOFF(ebuf), SEEK_SET) == -1)
- err(1, "%s", name);
+ cur_off = N_SYMOFF(*ebuf);
- data.data = (u_char *)&nbuf;
- data.size = sizeof(NLIST);
-
/* Read each symbol and enter it into the database. */
- nsyms = ebuf.a_syms / sizeof(struct nlist);
+ nsyms = ebuf->a_syms / sizeof(struct nlist);
while (nsyms--) {
- if (fread((char *)&nbuf, sizeof (NLIST), 1, fp) != 1) {
- if (feof(fp))
- badfmt("corrupted symbol table");
- err(1, "%s", name);
- }
- if (!nbuf._strx || nbuf.n_type&N_STAB)
+
+ nbuf = (NLIST *)(filep + cur_off);
+ cur_off += sizeof(NLIST);
+
+ if (!nbuf->_strx || nbuf->n_type&N_STAB)
continue;
- key.data = (u_char *)strtab + nbuf._strx - sizeof(long);
+ key.data = (u_char *)strtab + nbuf->_strx - sizeof(long);
key.size = strlen((char *)key.data);
+ data.data = (u_char *)nbuf;
+ data.size = sizeof(NLIST);
if (db->put(db, &key, &data, 0))
err(1, "record enter");
- if (strcmp((char *)key.data, VRS_SYM) == 0) {
- long cur_off, voff;
+ if (1 && strcmp((char *)key.data, VRS_SYM) == 0) {
#ifndef KERNTEXTOFF
/*
* XXX
@@ -144,7 +129,7 @@ create_knlist(name, db)
* This may be introducing an i386 dependency.
*/
#if defined(__FreeBSD__)
-#define KERNTEXTOFF ebuf.a_entry
+#define KERNTEXTOFF ebuf->a_entry
#else
#define KERNTEXTOFF KERNBASE
#endif
@@ -155,46 +140,24 @@ create_knlist(name, db)
* loaded; N_TXTADDR is where a normal file is loaded.
* From there, locate file offset in text or data.
*/
- voff = nbuf.n_value - KERNTEXTOFF + N_TXTADDR(ebuf);
- if ((nbuf.n_type & N_TYPE) == N_TEXT)
- voff += N_TXTOFF(ebuf) - N_TXTADDR(ebuf);
+ voff = nbuf->n_value - KERNTEXTOFF + N_TXTADDR(*ebuf);
+ if ((nbuf->n_type & N_TYPE) == N_TEXT)
+ voff += N_TXTOFF(*ebuf) - N_TXTADDR(*ebuf);
else
- voff += N_DATOFF(ebuf) - N_DATADDR(ebuf);
- cur_off = ftell(fp);
- if (fseek(fp, voff, SEEK_SET) == -1)
- badfmt("corrupted string table");
-
- /*
- * Read version string up to, and including newline.
- * This code assumes that a newline terminates the
- * version line.
- */
- if (fgets(buf, sizeof(buf), fp) == NULL)
- badfmt("corrupted string table");
+ voff += N_DATOFF(*ebuf) - N_DATADDR(*ebuf);
+ vp = filep + voff;
+
key.data = (u_char *)VRS_KEY;
key.size = sizeof(VRS_KEY) - 1;
- data.data = (u_char *)buf;
- data.size = strlen(buf);
+ data.data = vp;
+ data.size = strchr(vp, '\n') - vp + 1;
+
if (db->put(db, &key, &data, 0))
err(1, "record enter");
/* Restore to original values. */
- data.data = (u_char *)&nbuf;
data.size = sizeof(NLIST);
- if (fseek(fp, cur_off, SEEK_SET) == -1)
- badfmt("corrupted string table");
}
}
- (void)fclose(fp);
-}
-
-static void
-badread(nr, p)
- int nr;
- char *p;
-{
- if (nr < 0)
- err(1, "%s", kfile);
- badfmt(p);
}
OpenPOWER on IntegriCloud