[master] c632af8 Pack the memitem a bit smarter and drop the payload element which costs us 8 bytes per allocation.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Jan 2 11:23:06 CET 2012
commit c632af8afa5976b05fe499c71d83f0bacde7de8d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jan 2 10:22:37 2012 +0000
Pack the memitem a bit smarter and drop the payload element which costs
us 8 bytes per allocation.
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index a9d4249..468d5a8 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -29,6 +29,7 @@
*/
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include "config.h"
@@ -40,10 +41,9 @@
struct memitem {
unsigned magic;
#define MEMITEM_MAGIC 0x42e55401
- VTAILQ_ENTRY(memitem) list;
unsigned size;
+ VTAILQ_ENTRY(memitem) list;
double touched;
- char payload;
};
VTAILQ_HEAD(memhead_s, memitem);
@@ -92,8 +92,6 @@ mpl_alloc(const struct mempool *mpl)
* of the list not getting too old.
*/
-#include <stdio.h>
-
static void *
mpl_guard(void *priv)
{
@@ -309,7 +307,7 @@ MPL_Get(struct mempool *mpl, unsigned *size)
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
/* Throw away sizeof info for FlexeLint: */
- return ((void*)(uintptr_t)&mi->payload);
+ return ((void*)(uintptr_t)(mi+1));
}
void
@@ -320,7 +318,7 @@ MPL_Free(struct mempool *mpl, void *item)
CHECK_OBJ_NOTNULL(mpl, MEMPOOL_MAGIC);
AN(item);
- mi = (void*)((uintptr_t)item - offsetof(struct memitem, payload));
+ mi = (void*)((uintptr_t)item - sizeof(*mi));
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
memset(item, 0, mi->size);
@@ -348,6 +346,6 @@ void
MPL_AssertSane(void *item)
{
struct memitem *mi;
- mi = (void*)((uintptr_t)item - offsetof(struct memitem, payload));
+ mi = (void*)((uintptr_t)item - sizeof(*mi));
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
}
More information about the varnish-commit
mailing list