
phk at varnish-cache
Feb 8, 2012, 2:29 PM
Post #1 of 1
(26 views)
Permalink
|
|
[master] 1366473 Allocate busyobj with a mempool, instead of a private one-item pool.
|
|
commit 1366473e5a52b2425e6348c395c74fe5381c4140 Author: Poul-Henning Kamp <phk [at] FreeBSD> Date: Wed Feb 8 22:28:58 2012 +0000 Allocate busyobj with a mempool, instead of a private one-item pool. diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index ab4db76..51207df 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -38,6 +38,10 @@ #include "cache.h" +static struct mempool *vbopool; + +static volatile unsigned vbosize; + struct vbo { unsigned magic; #define VBO_MAGIC 0xde3d8223 @@ -48,13 +52,35 @@ struct vbo { }; static struct lock vbo_mtx; -static struct vbo *nvbo; + +/*-------------------------------------------------------------------- + */ + +static void +vbo_size_calc(volatile unsigned *u) +{ + uint16_t nhttp; + ssize_t http_space; + + assert(cache_param->http_max_hdr < 65536); + nhttp = (uint16_t)cache_param->http_max_hdr; + + http_space = HTTP_estimate(nhttp); + + *u = sizeof(struct vbo) + http_space * 2L; +} + +/*-------------------------------------------------------------------- + */ void VBO_Init(void) { + + vbopool = MPL_New("vbo", &cache_param->vbo_pool, &vbosize, + vbo_size_calc); + AN(vbopool); Lck_New(&vbo_mtx, lck_busyobj); - nvbo = NULL; } /*-------------------------------------------------------------------- @@ -67,16 +93,19 @@ vbo_New(void) struct vbo *vbo; uint16_t nhttp; ssize_t http_space; + unsigned sz; - assert(cache_param->http_max_hdr < 65536); + vbo = MPL_Get(vbopool, &sz); nhttp = (uint16_t)cache_param->http_max_hdr; - http_space = HTTP_estimate(nhttp); - - vbo = malloc(sizeof *vbo + 2 * http_space); + if (sizeof *vbo + 2 * http_space > sz) { + /* Could be transient, try again */ + MPL_Free(vbopool, vbo); + vbo_size_calc(&vbosize); + vbo = MPL_Get(vbopool, &sz); + assert (sizeof *vbo + 2 * http_space <= sz); + } AN(vbo); - - memset(vbo, 0, sizeof *vbo); vbo->magic = VBO_MAGIC; vbo->nhttp = nhttp; Lck_New(&vbo->mtx, lck_busyobj); @@ -94,7 +123,7 @@ VBO_Free(struct vbo **vbop) CHECK_OBJ_NOTNULL(vbo, VBO_MAGIC); AZ(vbo->refcount); Lck_Delete(&vbo->mtx); - FREE_OBJ(vbo); + MPL_Free(vbopool, vbo); } struct busyobj * @@ -110,21 +139,6 @@ VBO_GetBusyObj(struct worker *wrk) wrk->nvbo = NULL; } - if (vbo == NULL) { - Lck_Lock(&vbo_mtx); - - vbo = nvbo; - nvbo = NULL; - - if (vbo == NULL) - VSC_C_main->busyobj_alloc++; - - Lck_Unlock(&vbo_mtx); - } - - if (vbo != NULL && vbo->nhttp != cache_param->http_max_hdr) - VBO_Free(&vbo); - if (vbo == NULL) vbo = vbo_New(); @@ -181,19 +195,9 @@ VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo) /* XXX: Sanity checks & cleanup */ memset(&vbo->bo, 0, sizeof vbo->bo); - if (cache_param->bo_cache && wrk->nvbo == NULL) { + if (cache_param->bo_cache && wrk->nvbo == NULL) wrk->nvbo = vbo; - } else { - Lck_Lock(&vbo_mtx); - if (nvbo == NULL) { - nvbo = vbo; - vbo = NULL; - } else - VSC_C_main->busyobj_free++; - Lck_Unlock(&vbo_mtx); - - if (vbo != NULL) - VBO_Free(&vbo); - } + else + VBO_Free(&vbo); } } diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c index ec0d36b..4b8ed07 100644 --- a/bin/varnishd/cache/cache_mempool.c +++ b/bin/varnishd/cache/cache_mempool.c @@ -237,6 +237,8 @@ MPL_New(const char *name, mpl->param = pp; mpl->cur_size = cur_size; mpl->poll_func = poll_f; + if (poll_f != NULL) + poll_f(mpl->cur_size); VTAILQ_INIT(&mpl->list); VTAILQ_INIT(&mpl->surplus); Lck_New(&mpl->mtx, lck_mempool); diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h index 015e5d2..40fcf1d 100644 --- a/bin/varnishd/common/params.h +++ b/bin/varnishd/common/params.h @@ -201,4 +201,5 @@ struct params { struct poolparam vbc_pool; struct poolparam req_pool; struct poolparam sess_pool; + struct poolparam vbo_pool; }; diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 60d49f8..56c8336 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -662,6 +662,12 @@ tweak_poolparam(struct cli *cli, const struct parspec *par, const char *arg) "\nNB: Do not change this parameter, unless a developer tell " \ "you to do so." +#define MEMPOOL_TEXT \ + "The three numbers are:\n" \ + " min_pool -- minimum size of free pool.\n" \ + " max_pool -- maximum size of free pool.\n" \ + " max_age -- max age of free element.\n" + /* * Remember to update varnishd.1 whenever you add / remove a parameter or * change its default value. @@ -1192,27 +1198,23 @@ static const struct parspec input_parspec[] = { { "pool_vbc", tweak_poolparam, &mgt_param.vbc_pool, 0, 10000, "Parameters for backend connection memory pool.\n" - "The three numbers are:\n" - " min_pool -- minimum size of free pool.\n" - " max_pool -- maximum size of free pool.\n" - " max_age -- max age of free element.\n", + MEMPOOL_TEXT, 0, "10,100,10", ""}, { "pool_req", tweak_poolparam, &mgt_param.req_pool, 0, 10000, "Parameters for per worker pool request memory pool.\n" - "The three numbers are:\n" - " min_pool -- minimum size of free pool.\n" - " max_pool -- maximum size of free pool.\n" - " max_age -- max age of free element.\n", + MEMPOOL_TEXT, 0, "10,100,10", ""}, { "pool_sess", tweak_poolparam, &mgt_param.sess_pool, 0, 10000, "Parameters for per worker pool session memory pool.\n" - "The three numbers are:\n" - " min_pool -- minimum size of free pool.\n" - " max_pool -- maximum size of free pool.\n" - " max_age -- max age of free element.\n", + MEMPOOL_TEXT, + 0, + "10,100,10", ""}, + { "pool_vbo", tweak_poolparam, &mgt_param.vbo_pool, 0, 10000, + "Parameters for backend object fetch memory pool.\n" + MEMPOOL_TEXT, 0, "10,100,10", ""}, diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h index df7984a..1188903 100644 --- a/include/tbl/vsc_f_main.h +++ b/include/tbl/vsc_f_main.h @@ -206,20 +206,6 @@ VSC_F(sess_dropped, uint64_t, 0, 'c', " See also param queue_max." ) -/*--------------------------------------------------------------------- - * BusyObj - */ - -VSC_F(busyobj_alloc, uint64_t, 0, 'c', - "Busyobj allocations", - "Number of busyobj structures allocated." -) - -VSC_F(busyobj_free, uint64_t, 0, 'c', - "Busyobj freed", - "Number of busyobj structures freed." -) - /*---------------------------------------------------------------------*/ VSC_F(n_object, uint64_t, 1, 'i', "N struct object", "") _______________________________________________ varnish-commit mailing list varnish-commit [at] varnish-cache https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit
|