[experimental-ims] 2362e93 Add a call-back function to memory pools, which can be used to update the desired size of objects from the guard thread.

Geoff Simmons geoff at varnish-cache.org
Tue Feb 14 17:49:18 CET 2012


commit 2362e936e03bf3ee2093efe3aa663c9c998b272b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 8 22:03:39 2012 +0000

    Add a call-back function to memory pools, which can be used to
    update the desired size of objects from the guard thread.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f7bef9d..6338750 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -884,9 +884,10 @@ int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, struct timespec *ts);
 #undef LOCK
 
 /* cache_mempool.c */
+typedef void mpl_poll_f(volatile unsigned *);
 void MPL_AssertSane(void *item);
 struct mempool * MPL_New(const char *name, volatile struct poolparam *pp,
-    volatile unsigned *cur_size);
+    volatile unsigned *cur_size, mpl_poll_f *poll_f);
 void MPL_Destroy(struct mempool **mpp);
 void *MPL_Get(struct mempool *mpl, unsigned *size);
 void MPL_Free(struct mempool *mpl, void *item);
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index b683300..2610b06 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -519,6 +519,6 @@ void
 VDI_Init(void)
 {
 
-	vbcpool = MPL_New("vbc", &cache_param->vbc_pool, &vbcps);
+	vbcpool = MPL_New("vbc", &cache_param->vbc_pool, &vbcps, NULL);
 	AN(vbcpool);
 }
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 468d5a8..ec0d36b 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -57,6 +57,7 @@ struct mempool {
 	struct lock			mtx;
 	volatile struct poolparam	*param;
 	volatile unsigned		*cur_size;
+	mpl_poll_f			*poll_func;
 	uint64_t			live;
 	struct VSC_C_mempool		*vsc;
 	unsigned			n_pool;
@@ -104,6 +105,8 @@ mpl_guard(void *priv)
 	mpl_slp = 0.15;	// random
 	while (1) {
 		VTIM_sleep(mpl_slp);
+		if (mpl->poll_func != NULL)
+			mpl->poll_func(mpl->cur_size);
 		mpl_slp = 0.814;	// random
 		mpl->t_now = VTIM_real();
 
@@ -224,7 +227,7 @@ mpl_guard(void *priv)
 struct mempool *
 MPL_New(const char *name,
 	volatile struct poolparam *pp,
-	volatile unsigned *cur_size)
+	volatile unsigned *cur_size, mpl_poll_f *poll_f)
 {
 	struct mempool *mpl;
 
@@ -233,6 +236,7 @@ MPL_New(const char *name,
 	bprintf(mpl->name, "%s", name);
 	mpl->param = pp;
 	mpl->cur_size = cur_size;
+	mpl->poll_func = poll_f;
 	VTAILQ_INIT(&mpl->list);
 	VTAILQ_INIT(&mpl->surplus);
 	Lck_New(&mpl->mtx, lck_mempool);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 3e144c1..2e080f1 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -383,9 +383,9 @@ SES_NewPool(struct pool *wp, unsigned pool_no)
 	pp->pool = wp;
 	bprintf(nb, "req%u", pool_no);
 	pp->mpl_req = MPL_New(nb, &cache_param->req_pool,
-	    &cache_param->workspace_client);
+	    &cache_param->workspace_client, NULL);
 	bprintf(nb, "sess%u", pool_no);
-	pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool, &ses_size);
+	pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool, &ses_size, NULL);
 	return (pp);
 }
 



More information about the varnish-commit mailing list