From ab9bceb9af3064c91be3599295ee0f2b3d91d0d0 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 18 Sep 2018 03:05:42 +0000 Subject: [PATCH] Account from the fact that we store ech entry three times when estimating the number of hash table elements. Also set the bucket size to be the optimal file system block size instead of hard-coding to 4096. OK tb@ --- usr.sbin/pwd_mkdb/pwd_mkdb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index 35648a44721..37bc4c829cc 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwd_mkdb.c,v 1.53 2015/11/05 15:10:11 semarie Exp $ */ +/* $OpenBSD: pwd_mkdb.c,v 1.54 2018/09/18 03:05:42 millert Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -188,8 +188,13 @@ main(int argc, char **argv) /* Tweak openinfo values for large passwd files. */ if (st.st_size > (off_t)100*1024) openinfo.cachesize = MINIMUM(st.st_size * 20, (off_t)12*1024*1024); - if (st.st_size / 128 > openinfo.nelem) - openinfo.nelem = st.st_size / 128; + /* Estimate number of elements based on a 128-byte average entry. */ + if (st.st_size / 128 * 3 > openinfo.nelem) + openinfo.nelem = st.st_size / 128 * 3; + + /* Use optimal filesystem block size. */ + if (st.st_blksize > openinfo.bsize) + openinfo.bsize = st.st_blksize; /* If only updating a single record, stash the old uid */ if (username) { -- 2.20.1