summaryrefslogtreecommitdiffstats
path: root/sys/fs
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2013-12-25 16:58:42 +0000
committermav <mav@FreeBSD.org>2013-12-25 16:58:42 +0000
commit723d6ab041aae81720f6bfc576e458da69f709ff (patch)
tree19f9b27d00df430778af48fe08b7c3c4ac4304bf /sys/fs
parent7f369bb9c6c0fb9e7c137d161d7d490c0e44b554 (diff)
downloadFreeBSD-src-723d6ab041aae81720f6bfc576e458da69f709ff.zip
FreeBSD-src-723d6ab041aae81720f6bfc576e458da69f709ff.tar.gz
Slightly simplify expiration logic introduced in r254337.
- Do not update the histogram for items we are any way deleting from cache. - Do not update the histogram if nfsrc_tcphighwater is not set. - Remove some extra math operations.
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/nfsserver/nfs_nfsdcache.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/sys/fs/nfsserver/nfs_nfsdcache.c b/sys/fs/nfsserver/nfs_nfsdcache.c
index 32a053d..04f7231 100644
--- a/sys/fs/nfsserver/nfs_nfsdcache.c
+++ b/sys/fs/nfsserver/nfs_nfsdcache.c
@@ -832,6 +832,7 @@ nfsrvd_cleancache(void)
nfsrc_tcpsavedreplies = 0;
}
+#define HISTSIZE 16
/*
* The basic rule is to get rid of entries that are expired.
*/
@@ -839,7 +840,7 @@ static void
nfsrc_trimcache(u_int64_t sockref, struct socket *so)
{
struct nfsrvcache *rp, *nextrp;
- int i, j, k, time_histo[10];
+ int i, j, k, tto, time_histo[HISTSIZE];
time_t thisstamp;
static time_t udp_lasttrim = 0, tcp_lasttrim = 0;
static int onethread = 0;
@@ -863,8 +864,9 @@ nfsrc_trimcache(u_int64_t sockref, struct socket *so)
}
if (NFSD_MONOSEC != tcp_lasttrim ||
nfsrc_tcpsavedreplies >= nfsrc_tcphighwater) {
- for (i = 0; i < 10; i++)
+ for (i = 0; i < HISTSIZE; i++)
time_histo[i] = 0;
+ tto = nfsrc_tcptimeout;
for (i = 0; i < NFSRVCACHE_HASHSIZE; i++) {
mtx_lock(&nfsrchash_table[i].mtx);
if (i == 0)
@@ -874,6 +876,15 @@ nfsrc_trimcache(u_int64_t sockref, struct socket *so)
if (!(rp->rc_flag &
(RC_INPROG|RC_LOCKED|RC_WANTED))
&& rp->rc_refcnt == 0) {
+ if ((rp->rc_flag & RC_REFCNT) ||
+ tcp_lasttrim > rp->rc_timestamp ||
+ nfsrc_activesocket(rp, sockref, so)) {
+ nfsrc_freecache(rp);
+ continue;
+ }
+
+ if (nfsrc_tcphighwater == 0)
+ continue;
/*
* The timestamps range from roughly the
* present (tcp_lasttrim) to the present
@@ -881,16 +892,13 @@ nfsrc_trimcache(u_int64_t sockref, struct socket *so)
* histogram of where the timeouts fall.
*/
j = rp->rc_timestamp - tcp_lasttrim;
- if (j >= nfsrc_tcptimeout)
- j = nfsrc_tcptimeout - 1;
- if (j < 0)
+ if (j >= tto)
+ j = HISTSIZE - 1;
+ else if (j < 0)
j = 0;
- j = (j * 10 / nfsrc_tcptimeout) % 10;
+ else
+ j = j * HISTSIZE / tto;
time_histo[j]++;
- if ((rp->rc_flag & RC_REFCNT) ||
- tcp_lasttrim > rp->rc_timestamp ||
- nfsrc_activesocket(rp, sockref, so))
- nfsrc_freecache(rp);
}
}
mtx_unlock(&nfsrchash_table[i].mtx);
@@ -903,12 +911,12 @@ nfsrc_trimcache(u_int64_t sockref, struct socket *so)
* 80% of the nfsrc_tcphighwater.
*/
k = 0;
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < (HISTSIZE - 2); i++) {
k += time_histo[i];
if (k > j)
break;
}
- k = nfsrc_tcptimeout * (i + 1) / 10;
+ k = tto * (i + 1) / HISTSIZE;
if (k < 1)
k = 1;
thisstamp = tcp_lasttrim + k;
OpenPOWER on IntegriCloud