From owner-svn-src-head@FreeBSD.ORG Wed Dec 25 16:58:43 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7DD26E43; Wed, 25 Dec 2013 16:58:43 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5E81F12B5; Wed, 25 Dec 2013 16:58:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBPGwhSh014358; Wed, 25 Dec 2013 16:58:43 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBPGwh1g014357; Wed, 25 Dec 2013 16:58:43 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201312251658.rBPGwh1g014357@svn.freebsd.org> From: Alexander Motin Date: Wed, 25 Dec 2013 16:58:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r259877 - head/sys/fs/nfsserver X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Dec 2013 16:58:43 -0000 Author: mav Date: Wed Dec 25 16:58:42 2013 New Revision: 259877 URL: http://svnweb.freebsd.org/changeset/base/259877 Log: 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. Modified: head/sys/fs/nfsserver/nfs_nfsdcache.c Modified: head/sys/fs/nfsserver/nfs_nfsdcache.c ============================================================================== --- head/sys/fs/nfsserver/nfs_nfsdcache.c Wed Dec 25 16:58:14 2013 (r259876) +++ head/sys/fs/nfsserver/nfs_nfsdcache.c Wed Dec 25 16:58:42 2013 (r259877) @@ -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, struc } 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, struc 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, struc * 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, struc * 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;