diff options
author | davide <davide@FreeBSD.org> | 2014-11-22 00:37:37 +0000 |
---|---|---|
committer | davide <davide@FreeBSD.org> | 2014-11-22 00:37:37 +0000 |
commit | 12cc45e8da0a2e67e92afeba49cb9e1a7a32c807 (patch) | |
tree | b401c14a0a454f15656827ce992bf6cc28a06696 | |
parent | bc153a3d362e6906a9d3c335684d79fd090ab7c2 (diff) | |
download | FreeBSD-src-12cc45e8da0a2e67e92afeba49cb9e1a7a32c807.zip FreeBSD-src-12cc45e8da0a2e67e92afeba49cb9e1a7a32c807.tar.gz |
Make ufs_dirhashreclaimperc a percentage for real and
rename it to ufs_dirhashreclaimpercent, as suggested
by jhb@. As an added bonus this avoids divide-by-zero
errors.
Requested by: jhb, markj
Reviewied by: jhb, markj
-rw-r--r-- | sys/ufs/ufs/ufs_dirhash.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/sys/ufs/ufs/ufs_dirhash.c b/sys/ufs/ufs/ufs_dirhash.c index 476ec38..a747334 100644 --- a/sys/ufs/ufs/ufs_dirhash.c +++ b/sys/ufs/ufs/ufs_dirhash.c @@ -85,10 +85,11 @@ SYSCTL_INT(_vfs_ufs, OID_AUTO, dirhash_docheck, CTLFLAG_RW, &ufs_dirhashcheck, static int ufs_dirhashlowmemcount = 0; SYSCTL_INT(_vfs_ufs, OID_AUTO, dirhash_lowmemcount, CTLFLAG_RD, &ufs_dirhashlowmemcount, 0, "number of times low memory hook called"); -static int ufs_dirhash_reclaimperc = 10; -SYSCTL_INT(_vfs_ufs, OID_AUTO, dirhash_reclaimperc, CTLFLAG_RW, - &ufs_dirhash_reclaimperc, 0, - "percentage of dirhash cache to be removed in low VM events"); +static int ufs_dirhashreclaimpercent = 10; +static int ufsdirhash_set_reclaimpercent(SYSCTL_HANDLER_ARGS); +SYSCTL_PROC(_vfs_ufs, OID_AUTO, dirhash_reclaimpercent, + CTLTYPE_INT | CTLFLAG_RW, 0, 0, ufsdirhash_set_reclaimpercent, "I", + "set percentage of dirhash cache to be removed in low VM events"); static int ufsdirhash_hash(struct dirhash *dh, char *name, int namelen); @@ -1251,7 +1252,7 @@ ufsdirhash_lowmem() ufs_dirhashlowmemcount++; memfreed = 0; - memwanted = ufs_dirhashmem / ufs_dirhash_reclaimperc; + memwanted = ufs_dirhashmem * ufs_dirhash_reclaimpercent / 100; DIRHASHLIST_LOCK(); @@ -1273,6 +1274,26 @@ ufsdirhash_lowmem() DIRHASHLIST_UNLOCK(); } +static int +ufsdirhash_set_reclaimpercent(SYSCTL_HANDLER_ARGS) +{ + int error, v; + + v = ufs_dirhashreclaimpercent; + error = sysctl_handle_int(oidp, &v, v, req); + if (error) + return (error); + if (req->newptr == NULL) + return (error); + if (v == ufs_dirhashreclaimpercent) + return (0); + + /* Refuse invalid percentages */ + if (v < 0 || v > 100) + return (EINVAL); + ufs_dirhashreclaimpercent = v; + return (0); +} void ufsdirhash_init() |