Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Jul 2020 21:19:33 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r363202 - head/sys/kern
Message-ID:  <202007142119.06ELJXtb022346@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Tue Jul 14 21:19:33 2020
New Revision: 363202
URL: https://svnweb.freebsd.org/changeset/base/363202

Log:
  cache: make negative shrinker round robin on all lists every time
  
  Previously it would check 4, 3, 2, 1 lists. In practice by the time
  it is getting called all lists have some elements and consequently
  this does not result in new evictions.
  
  Nonetheless, the code is clearer.
  
  Tested by:	pho

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c	Tue Jul 14 21:17:46 2020	(r363201)
+++ head/sys/kern/vfs_cache.c	Tue Jul 14 21:19:33 2020	(r363202)
@@ -262,7 +262,6 @@ static u_int __read_mostly	ncsize; /* the size as comp
 struct nchstats	nchstats;		/* cache effectiveness statistics */
 
 static struct mtx __exclusive_cache_line	ncneg_shrink_lock;
-static int	shrink_list_turn;
 
 struct neglist {
 	struct mtx		nl_lock;
@@ -815,18 +814,18 @@ cache_negative_remove(struct namecache *ncp)
 }
 
 static void
-cache_negative_shrink_select(int start, struct namecache **ncpp,
+cache_negative_shrink_select(struct namecache **ncpp,
     struct neglist **neglistpp)
 {
 	struct neglist *neglist;
 	struct namecache *ncp;
-	int i;
+	static u_int cycle;
+	u_int i;
 
 	*ncpp = ncp = NULL;
-	neglist = NULL;
 
-	for (i = start; i < numneglists; i++) {
-		neglist = &neglists[i];
+	for (i = 0; i < numneglists; i++) {
+		neglist = &neglists[(cycle + i) % numneglists];
 		if (TAILQ_FIRST(&neglist->nl_list) == NULL)
 			continue;
 		mtx_lock(&neglist->nl_lock);
@@ -838,6 +837,7 @@ cache_negative_shrink_select(int start, struct namecac
 
 	*neglistpp = neglist;
 	*ncpp = ncp;
+	cycle++;
 }
 
 static void
@@ -870,12 +870,8 @@ cache_negative_zap_one(void)
 	}
 	mtx_unlock(&ncneg_hot.nl_lock);
 
-	cache_negative_shrink_select(shrink_list_turn, &ncp, &neglist);
-	shrink_list_turn++;
-	if (shrink_list_turn == numneglists)
-		shrink_list_turn = 0;
-	if (ncp == NULL && shrink_list_turn == 0)
-		cache_negative_shrink_select(shrink_list_turn, &ncp, &neglist);
+	cache_negative_shrink_select(&ncp, &neglist);
+
 	mtx_unlock(&ncneg_shrink_lock);
 	if (ncp == NULL)
 		return;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007142119.06ELJXtb022346>