[PATCH 01/13] Add a EXP_NukeLRU() function to nuke an entire LRU structure at a time.

Poul-Henning Kamp phk at phk.freebsd.dk
Tue Oct 9 09:20:16 CEST 2012


In message <1349087180-11089-1-git-send-email-martin at varnish-software.com>, Mar
tin Blix Grydeland writes:

I may have asked this before, but why not simply make a
local VTAILQ_HEAD on the stack and move everything there in one
iteration ?

Is it to not block the mutex'es too long ?

Poul-Henning

PS: This email is _also_ a sort of test of patchwork :-)

>+#define NUKEBUF 10
>+
>+void
>+EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru)
>+{
>+	struct objcore *oc;
>+	struct objcore *oc_array[NUKEBUF];
>+	struct object *o;
>+	int i, n;
>+	double t;
>+
>+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
>+	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
>+
>+	t = VTIM_real();
>+	Lck_Lock(&lru->mtx);
>+	while (!VTAILQ_EMPTY(&lru->lru_head)) {
>+		Lck_Lock(&exp_mtx);
>+		n = 0;
>+		while (n < NUKEBUF) {
>+			oc = VTAILQ_FIRST(&lru->lru_head);
>+			if (oc == NULL)
>+				break;
>+			CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
>+			assert(oc_getlru(oc) == lru);
>+
>+			/* Remove from the LRU and binheap */
>+			VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
>+			assert(oc->timer_idx != BINHEAP_NOIDX);
>+			binheap_delete(exp_heap, oc->timer_idx);
>+			assert(oc->timer_idx == BINHEAP_NOIDX);
>+
>+			oc_array[n++] = oc;
>+			VSC_C_main->n_lru_nuked++;
>+		}




-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-dev mailing list