Add a -c flag to specify the size of cache to use. For very large databases,

increasing this value accordingly gives massive speed improvements.

Prompted by Greg Woods in PR/19387, although mostly taken from FreeBSD.
This commit is contained in:
sketch 2006-09-23 17:17:04 +00:00
parent 807fde634b
commit 4fea323db6
2 changed files with 27 additions and 12 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pwd_mkdb.8,v 1.21 2005/09/05 03:37:15 hubertf Exp $
.\" $NetBSD: pwd_mkdb.8,v 1.22 2006/09/23 17:17:04 sketch Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -64,6 +64,13 @@ The options are as follows:
Store data in big-endian format.
.It Fl L
Store data in little-endian format.
.It Fl c Ar cachesize
Specify in megabytes the size of the memory cache used by the hashing
library. On systems with a large user base, a small cache size can lead
to prohibitively long database file rebuild times. As a rough guide, the
memory usage of pwd_mkdb in megabytes will be a little bit more than twice
the figure specified here. If unspecified, this value will be calculated
based on the size of the input file up to a maximum of 8 megabytes.
.It Fl d Ar directory
Change the root directory of the generated files from
.Dq Pa /

View File

@ -1,4 +1,4 @@
/* $NetBSD: pwd_mkdb.c,v 1.30 2005/06/02 09:18:14 lukem Exp $ */
/* $NetBSD: pwd_mkdb.c,v 1.31 2006/09/23 17:17:04 sketch Exp $ */
/*
* Copyright (c) 1991, 1993, 1994
@ -65,7 +65,7 @@ __COPYRIGHT("@(#) Copyright (c) 2000\n\
Copyright (c) 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n");
__SCCSID("from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94");
__RCSID("$NetBSD: pwd_mkdb.c,v 1.30 2005/06/02 09:18:14 lukem Exp $");
__RCSID("$NetBSD: pwd_mkdb.c,v 1.31 2006/09/23 17:17:04 sketch Exp $");
#endif /* not lint */
#if HAVE_NBTOOL_CONFIG_H
@ -162,8 +162,9 @@ main(int argc, char *argv[])
found = 0;
newuser = 0;
dp = NULL;
cachesize = 0;
while ((ch = getopt(argc, argv, "BLd:psu:v")) != -1)
while ((ch = getopt(argc, argv, "BLc:d:psu:v")) != -1)
switch (ch) {
case 'B': /* big-endian output */
lorder = BIG_ENDIAN;
@ -171,6 +172,9 @@ main(int argc, char *argv[])
case 'L': /* little-endian output */
lorder = LITTLE_ENDIAN;
break;
case 'c':
cachesize = atoi(optarg) * 1024 * 1024;
break;
case 'd': /* set prefix */
strlcpy(prefix, optarg, sizeof(prefix));
break;
@ -230,13 +234,17 @@ main(int argc, char *argv[])
if (fstat(fileno(fp), &st) == -1)
error(pname);
/* Tweak openinfo values for large passwd files. */
cachesize = st.st_size * 20;
if (cachesize > MAX_CACHESIZE)
cachesize = MAX_CACHESIZE;
else if (cachesize < MIN_CACHESIZE)
cachesize = MIN_CACHESIZE;
openinfo.cachesize = cachesize;
if (cachesize) {
openinfo.cachesize = cachesize;
} else {
/* Tweak openinfo values for large passwd files. */
cachesize = st.st_size * 20;
if (cachesize > MAX_CACHESIZE)
cachesize = MAX_CACHESIZE;
else if (cachesize < MIN_CACHESIZE)
cachesize = MIN_CACHESIZE;
openinfo.cachesize = cachesize;
}
/* Open the temporary insecure password database. */
if (!secureonly) {
@ -813,6 +821,6 @@ usage(void)
{
(void)fprintf(stderr,
"usage: pwd_mkdb [-BLps] [-d directory] [-u user] file\n");
"usage: pwd_mkdb [-BLps] [-c cachesize] [-d directory] [-u user] file\n");
exit(EXIT_FAILURE);
}