Blame SOURCES/libdb-5.3.21-trickle_cpu.patch

bfb1ae
diff -up db-5.3.21/src/dbinc_auto/int_def.in.trickle db-5.3.21/src/dbinc_auto/int_def.in
bfb1ae
--- db-5.3.21/src/dbinc_auto/int_def.in.trickle	2018-08-21 10:54:06.066757392 +0200
bfb1ae
+++ db-5.3.21/src/dbinc_auto/int_def.in	2018-08-21 10:54:06.111756561 +0200
bfb1ae
@@ -1458,6 +1458,7 @@
bfb1ae
 #define	__memp_sync_int __memp_sync_int@DB_VERSION_UNIQUE_NAME@
bfb1ae
 #define	__memp_mf_sync __memp_mf_sync@DB_VERSION_UNIQUE_NAME@
bfb1ae
 #define	__memp_purge_dead_files __memp_purge_dead_files@DB_VERSION_UNIQUE_NAME@
bfb1ae
+#define	__memp_purge_dead_and_count __memp_purge_dead_and_count@DB_VERSION_UNIQUE_NAME@
bfb1ae
 #define	__memp_trickle_pp __memp_trickle_pp@DB_VERSION_UNIQUE_NAME@
bfb1ae
 #define	__mutex_alloc __mutex_alloc@DB_VERSION_UNIQUE_NAME@
bfb1ae
 #define	__mutex_alloc_int __mutex_alloc_int@DB_VERSION_UNIQUE_NAME@
bfb1ae
diff -up db-5.3.21/src/dbinc_auto/mp_ext.h.trickle db-5.3.21/src/dbinc_auto/mp_ext.h
bfb1ae
--- db-5.3.21/src/dbinc_auto/mp_ext.h.trickle	2018-08-21 10:54:06.103756709 +0200
bfb1ae
+++ db-5.3.21/src/dbinc_auto/mp_ext.h	2018-08-21 10:54:06.112756543 +0200
bfb1ae
@@ -101,6 +101,7 @@ int __mp_xxx_fh __P((DB_MPOOLFILE *, DB_
bfb1ae
 int __memp_sync_int __P((ENV *, DB_MPOOLFILE *, u_int32_t, u_int32_t, u_int32_t *, int *));
bfb1ae
 int __memp_mf_sync __P((DB_MPOOL *, MPOOLFILE *, int));
bfb1ae
 int __memp_purge_dead_files __P((ENV *));
bfb1ae
+int __memp_purge_dead_and_count __P((ENV *, u_int32_t *, u_int32_t *));
bfb1ae
 int __memp_trickle_pp __P((DB_ENV *, int, int *));
bfb1ae
 
bfb1ae
 #if defined(__cplusplus)
bfb1ae
diff -up db-5.3.21/src/mp/mp_sync.c.trickle db-5.3.21/src/mp/mp_sync.c
bfb1ae
--- db-5.3.21/src/mp/mp_sync.c.trickle	2018-08-21 10:54:06.105756672 +0200
bfb1ae
+++ db-5.3.21/src/mp/mp_sync.c	2018-09-04 09:43:57.502992291 +0200
bfb1ae
@@ -965,17 +965,34 @@ __bhcmp(p1, p2)
bfb1ae
 	return (0);
bfb1ae
 }
bfb1ae
 
bfb1ae
+
bfb1ae
 /*
bfb1ae
  * __memp_purge_dead_files --
bfb1ae
+ *  Thin wrapper over __memp_purge_dead_and_count. Does not return any
bfb1ae
+ *  information about the number of total/dirty buffers.
bfb1ae
+ *
bfb1ae
+ * PUBLIC: int __memp_purge_dead_files __P((ENV *));
bfb1ae
+ */
bfb1ae
+int
bfb1ae
+__memp_purge_dead_files(env)
bfb1ae
+    ENV *env;
bfb1ae
+{
bfb1ae
+    return __memp_purge_dead_and_count(env, NULL, NULL);
bfb1ae
+}
bfb1ae
+
bfb1ae
+/*
bfb1ae
+ * __memp_purge_dead_and_count --
bfb1ae
  *	Remove all dead files and their buffers from the mpool. The caller
bfb1ae
  *	cannot hold any lock on the dead MPOOLFILE handles, their buffers
bfb1ae
  *	or their hash buckets.
bfb1ae
  *
bfb1ae
- * PUBLIC: int __memp_purge_dead_files __P((ENV *));
bfb1ae
+ * PUBLIC: int __memp_purge_dead_and_count __P((ENV *, u_int32_t *, u_int32_t *));
bfb1ae
  */
bfb1ae
 int
bfb1ae
-__memp_purge_dead_files(env)
bfb1ae
+__memp_purge_dead_and_count(env, totalp, dirtyp)
bfb1ae
 	ENV *env;
bfb1ae
+    u_int32_t *totalp;
bfb1ae
+    u_int32_t *dirtyp;
bfb1ae
 {
bfb1ae
 	BH *bhp;
bfb1ae
 	DB_MPOOL *dbmp;
bfb1ae
@@ -983,7 +1000,7 @@ __memp_purge_dead_files(env)
bfb1ae
 	REGINFO *infop;
bfb1ae
 	MPOOL *c_mp, *mp;
bfb1ae
 	MPOOLFILE *mfp;
bfb1ae
-	u_int32_t i_cache;
bfb1ae
+	u_int32_t i_cache, dirty, total;
bfb1ae
 	int ret, t_ret, h_lock;
bfb1ae
 
bfb1ae
 	if (!MPOOL_ON(env))
bfb1ae
@@ -992,6 +1009,7 @@ __memp_purge_dead_files(env)
bfb1ae
 	dbmp = env->mp_handle;
bfb1ae
 	mp = dbmp->reginfo[0].primary;
bfb1ae
 	ret = t_ret = h_lock = 0;
bfb1ae
+    dirty = total = 0;
bfb1ae
 
bfb1ae
 	/*
bfb1ae
 	 * Walk each cache's list of buffers and free all buffers whose
bfb1ae
@@ -1000,6 +1018,7 @@ __memp_purge_dead_files(env)
bfb1ae
 	for (i_cache = 0; i_cache < mp->nreg; i_cache++) {
bfb1ae
 		infop = &dbmp->reginfo[i_cache]; 
bfb1ae
 		c_mp = infop->primary;
bfb1ae
+        total += c_mp->pages;
bfb1ae
 
bfb1ae
 		hp = R_ADDR(infop, c_mp->htab);
bfb1ae
 		hp_end = &hp[c_mp->htab_buckets];
bfb1ae
@@ -1008,6 +1027,9 @@ __memp_purge_dead_files(env)
bfb1ae
 			if (SH_TAILQ_FIRST(&hp->hash_bucket, __bh) == NULL)
bfb1ae
 				continue;
bfb1ae
 
bfb1ae
+            /* Count dirty pages first as we do not wait on mutex locks */
bfb1ae
+            dirty += (u_int32_t)atomic_read(&hp->hash_page_dirty);
bfb1ae
+
bfb1ae
 			/* 
bfb1ae
 			 * Search for a dead buffer. Other places that call
bfb1ae
 			 * __memp_bhfree() acquire the buffer lock before the
bfb1ae
@@ -1073,6 +1095,11 @@ __memp_purge_dead_files(env)
bfb1ae
 		}
bfb1ae
 	}
bfb1ae
 
bfb1ae
+    if (dirtyp != NULL)
bfb1ae
+		*dirtyp = dirty;
bfb1ae
+    if (totalp != NULL)
bfb1ae
+		*totalp = total;
bfb1ae
+
bfb1ae
 	return (ret);
bfb1ae
 }
bfb1ae
 
bfb1ae
diff -up db-5.3.21/src/mp/mp_trickle.c.trickle db-5.3.21/src/mp/mp_trickle.c
bfb1ae
--- db-5.3.21/src/mp/mp_trickle.c.trickle	2018-08-21 10:54:06.105756672 +0200
bfb1ae
+++ db-5.3.21/src/mp/mp_trickle.c	2018-08-21 10:54:06.112756543 +0200
bfb1ae
@@ -56,6 +56,7 @@ __memp_trickle(env, pct, nwrotep)
bfb1ae
 
bfb1ae
 	dbmp = env->mp_handle;
bfb1ae
 	mp = dbmp->reginfo[0].primary;
bfb1ae
+    dirty = total = 0;
bfb1ae
 
bfb1ae
 	if (nwrotep != NULL)
bfb1ae
 		*nwrotep = 0;
bfb1ae
@@ -67,12 +68,8 @@ __memp_trickle(env, pct, nwrotep)
bfb1ae
 		return (EINVAL);
bfb1ae
 	}
bfb1ae
 
bfb1ae
-	/* First we purge all dead files and their buffers. */
bfb1ae
-	if ((ret = __memp_purge_dead_files(env)) != 0)
bfb1ae
-		return (ret);
bfb1ae
-
bfb1ae
-	/*
bfb1ae
-	 * Loop through the caches counting total/dirty buffers.
bfb1ae
+	/* First we purge all dead files and their buffers and
bfb1ae
+	 * loop through the caches counting total/dirty buffers.
bfb1ae
 	 *
bfb1ae
 	 * XXX
bfb1ae
 	 * Using hash_page_dirty is our only choice at the moment, but it's not
bfb1ae
@@ -80,12 +77,8 @@ __memp_trickle(env, pct, nwrotep)
bfb1ae
 	 * than one page size, as a free 512B buffer may not be equivalent to
bfb1ae
 	 * having a free 8KB buffer.
bfb1ae
 	 */
bfb1ae
-	for (ret = 0, i = dirty = total = 0; i < mp->nreg; ++i) {
bfb1ae
-		c_mp = dbmp->reginfo[i].primary;
bfb1ae
-		total += c_mp->pages;
bfb1ae
-		__memp_stat_hash(&dbmp->reginfo[i], c_mp, &dtmp);
bfb1ae
-		dirty += dtmp;
bfb1ae
-	}
bfb1ae
+	if ((ret = __memp_purge_dead_and_count(env, &total, &dirty)) != 0)
bfb1ae
+		return (ret);
bfb1ae
 
bfb1ae
 	/*
bfb1ae
 	 * If there are sufficient clean buffers, no buffers or no dirty