[master] cb7c470 Move LRU Nuking into the stevedores, while preserving the current stevedore selection algorithm exactly.

Poul-Henning Kamp phk at FreeBSD.org
Wed Dec 16 01:24:34 CET 2015


commit cb7c47046e810c703295a66164d761abc2e925a4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Dec 16 00:24:02 2015 +0000

    Move LRU Nuking into the stevedores, while preserving the current
    stevedore selection algorithm exactly.

diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index b924c4a..e761f89 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -142,7 +142,7 @@ STV_NewObject(struct worker *wrk, struct objcore *oc,
     const char *hint, unsigned wsl)
 {
 	struct stevedore *stv, *stv0;
-	int i, j;
+	int j;
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -158,13 +158,9 @@ STV_NewObject(struct worker *wrk, struct objcore *oc,
 			j = stv->allocobj(wrk, stv, oc, wsl, 0);
 		} while (j == 0 && stv != stv0);
 	}
-	if (j == 0) {
+	if (j == 0 && cache_param->nuke_limit > 0) {
 		/* no luck; try to free some space and keep trying */
-		for (i = 0; j == 0 && i < cache_param->nuke_limit; i++) {
-			if (EXP_NukeOne(wrk, stv->lru) == -1)
-				break;
-			j = stv->allocobj(wrk, stv, oc, wsl, 0);
-		}
+		j = stv->allocobj(wrk, stv, oc, wsl, cache_param->nuke_limit);
 	}
 
 	if (j == 0)
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 2ec51d3..dd0c66b 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -517,8 +517,8 @@ smp_allocobj(struct worker *wrk, const struct stevedore *stv,
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	(void)really;
 	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
+	assert(really >= 0);
 
 	/* Don't entertain already dead objects */
 	if ((oc->exp.ttl + oc->exp.grace + oc->exp.keep) <= 0.)
@@ -527,10 +527,24 @@ smp_allocobj(struct worker *wrk, const struct stevedore *stv,
 	ltot = sizeof(struct object) + PRNDUP(wsl);
 	ltot = IRNUP(sc, ltot);
 
-	st = smp_allocx(stv, ltot, ltot, &so, &objidx, &sg);
-	if (st == NULL)
-		return (0);
+	while (1) {
+		if (really > 0) {
+			if (EXP_NukeOne(wrk, stv->lru) == -1)
+				return (0);
+			really--;
+		}
+		st = smp_allocx(stv, ltot, ltot, &so, &objidx, &sg);
+		if (st != NULL && st->space < ltot) {
+			stv->free(st);		// NOP
+			st = NULL;
+		}
+		if (st != NULL)
+			break;
+		if (!really)
+			return (0);
+	}
 
+	AN(st);
 	assert(st->space >= ltot);
 
 	o = SML_MkObject(stv, oc, st->ptr);
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index 63a1117..0092d0e 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -84,15 +84,25 @@ SML_allocobj(struct worker *wrk, const struct stevedore *stv,
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	(void)really;
+	assert(really >= 0);
 	ltot = sizeof(struct object) + PRNDUP(wsl);
-	st = stv->alloc(stv, ltot);
-	if (st == NULL)
-		return (0);
-	if (st->space < ltot) {
-		stv->free(st);
-		return (0);
+	while (1) {
+		if (really > 0) {
+			if (EXP_NukeOne(wrk, stv->lru) == -1)
+				return (0);
+			really--;
+		}
+		st = stv->alloc(stv, ltot);
+		if (st != NULL && st->space < ltot) {
+			stv->free(st);
+			st = NULL;
+		}
+		if (st != NULL)
+			break;
+		if (!really)
+			return (0);
 	}
+	AN(st);
 	o = SML_MkObject(stv, oc, st->ptr);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	st->len = sizeof(*o);



More information about the varnish-commit mailing list