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 .\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" 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. Store data in big-endian format.
.It Fl L .It Fl L
Store data in little-endian format. 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 .It Fl d Ar directory
Change the root directory of the generated files from Change the root directory of the generated files from
.Dq Pa / .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 * Copyright (c) 1991, 1993, 1994
@ -65,7 +65,7 @@ __COPYRIGHT("@(#) Copyright (c) 2000\n\
Copyright (c) 1991, 1993, 1994\n\ Copyright (c) 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n"); The Regents of the University of California. All rights reserved.\n");
__SCCSID("from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94"); __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 */ #endif /* not lint */
#if HAVE_NBTOOL_CONFIG_H #if HAVE_NBTOOL_CONFIG_H
@ -162,8 +162,9 @@ main(int argc, char *argv[])
found = 0; found = 0;
newuser = 0; newuser = 0;
dp = NULL; 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) { switch (ch) {
case 'B': /* big-endian output */ case 'B': /* big-endian output */
lorder = BIG_ENDIAN; lorder = BIG_ENDIAN;
@ -171,6 +172,9 @@ main(int argc, char *argv[])
case 'L': /* little-endian output */ case 'L': /* little-endian output */
lorder = LITTLE_ENDIAN; lorder = LITTLE_ENDIAN;
break; break;
case 'c':
cachesize = atoi(optarg) * 1024 * 1024;
break;
case 'd': /* set prefix */ case 'd': /* set prefix */
strlcpy(prefix, optarg, sizeof(prefix)); strlcpy(prefix, optarg, sizeof(prefix));
break; break;
@ -230,13 +234,17 @@ main(int argc, char *argv[])
if (fstat(fileno(fp), &st) == -1) if (fstat(fileno(fp), &st) == -1)
error(pname); error(pname);
/* Tweak openinfo values for large passwd files. */ if (cachesize) {
cachesize = st.st_size * 20; openinfo.cachesize = cachesize;
if (cachesize > MAX_CACHESIZE) } else {
cachesize = MAX_CACHESIZE; /* Tweak openinfo values for large passwd files. */
else if (cachesize < MIN_CACHESIZE) cachesize = st.st_size * 20;
cachesize = MIN_CACHESIZE; if (cachesize > MAX_CACHESIZE)
openinfo.cachesize = cachesize; cachesize = MAX_CACHESIZE;
else if (cachesize < MIN_CACHESIZE)
cachesize = MIN_CACHESIZE;
openinfo.cachesize = cachesize;
}
/* Open the temporary insecure password database. */ /* Open the temporary insecure password database. */
if (!secureonly) { if (!secureonly) {
@ -813,6 +821,6 @@ usage(void)
{ {
(void)fprintf(stderr, (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); exit(EXIT_FAILURE);
} }