[master] af3e3a6 Take the mempool overhead out of the allocation, so that setting a workspace to 2^N doesn't result in 2^N+a allocations.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Apr 8 14:07:15 CEST 2015
commit af3e3a6f65370056c3c68871ecb4138501f3cfc9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Apr 8 12:05:45 2015 +0000
Take the mempool overhead out of the allocation, so that setting
a workspace to 2^N doesn't result in 2^N+a allocations.
Report "sz_wanted" and "sz_actual" in VSC.
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 74e7c12..472441c 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -75,12 +75,12 @@ mpl_alloc(const struct mempool *mpl)
CHECK_OBJ_NOTNULL(mpl, MEMPOOL_MAGIC);
tsz = *mpl->cur_size;
- mi = calloc(sizeof *mi + tsz, 1);
+ mi = calloc(tsz, 1);
AN(mi);
mi->magic = MEMITEM_MAGIC;
mi->size = tsz;
mpl->vsc->sz_wanted = tsz;
- mpl->vsc->sz_needed = tsz + sizeof *mi;
+ mpl->vsc->sz_actual = tsz - sizeof *mi;
return (mi);
}
@@ -116,7 +116,6 @@ mpl_guard(void *priv)
if (mi == NULL && mpl->n_pool < mpl->param->min_pool)
mi = mpl_alloc(mpl);
-
if (mpl->n_pool < mpl->param->min_pool && mi != NULL) {
/* can do */
} else if (mpl->n_pool > mpl->param->max_pool && mi == NULL) {
@@ -273,6 +272,7 @@ MPL_Get(struct mempool *mpl, unsigned *size)
struct memitem *mi;
CHECK_OBJ_NOTNULL(mpl, MEMPOOL_MAGIC);
+ AN(size);
Lck_Lock(&mpl->mtx);
@@ -301,8 +301,7 @@ MPL_Get(struct mempool *mpl, unsigned *size)
if (mi == NULL)
mi = mpl_alloc(mpl);
- if (size != NULL)
- *size = mi->size;
+ *size = mi->size - sizeof *mi;
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
/* Throw away sizeof info for FlexeLint: */
@@ -319,7 +318,7 @@ MPL_Free(struct mempool *mpl, void *item)
mi = (void*)((uintptr_t)item - sizeof(*mi));
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
- memset(item, 0, mi->size);
+ memset(item, 0, mi->size - sizeof *mi);
Lck_Lock(&mpl->mtx);
diff --git a/include/tbl/vsc_fields.h b/include/tbl/vsc_fields.h
index b456d9f..7d45f5c 100644
--- a/include/tbl/vsc_fields.h
+++ b/include/tbl/vsc_fields.h
@@ -239,7 +239,7 @@ VSC_F(sz_wanted, uint64_t, 0, 'g', 'B', debug,
"Size requested",
""
)
-VSC_F(sz_needed, uint64_t, 0, 'g', 'B', debug,
+VSC_F(sz_actual, uint64_t, 0, 'g', 'B', debug,
"Size allocated",
""
)
More information about the varnish-commit
mailing list