-/* $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
/* 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) {