Blame SOURCES/libdb-5.3.21-trickle_cpu.patch

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