Commit 1366473e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Allocate busyobj with a mempool, instead of a private one-item pool.

parent 2362e936
......@@ -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);
}
}
......@@ -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);
......
......@@ -201,4 +201,5 @@ struct params {
struct poolparam vbc_pool;
struct poolparam req_pool;
struct poolparam sess_pool;
struct poolparam vbo_pool;
};
......@@ -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", ""},
......
......@@ -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", "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment