[experimental-ims] fb3d538 SMA->trim() did not return the trimmed space to the pool causing the SMA to run out of space eventually.
Geoff Simmons
geoff at varnish-cache.org
Wed Aug 31 16:03:44 CEST 2011
commit fb3d5385f088f1af009f993df5d0ca345aa81c0c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Aug 22 11:41:53 2011 +0000
SMA->trim() did not return the trimmed space to the pool causing
the SMA to run out of space eventually.
diff --git a/bin/varnishd/storage_malloc.c b/bin/varnishd/storage_malloc.c
index 1cbfc10..0057867 100644
--- a/bin/varnishd/storage_malloc.c
+++ b/bin/varnishd/storage_malloc.c
@@ -153,6 +153,7 @@ sma_trim(struct storage *s, size_t size)
struct sma_sc *sma_sc;
struct sma *sma;
void *p;
+ size_t delta;
CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC);
CAST_OBJ_NOTNULL(sma, s->priv, SMA_MAGIC);
@@ -160,12 +161,16 @@ sma_trim(struct storage *s, size_t size)
assert(sma->sz == sma->s.space);
assert(size < sma->sz);
+ delta = sma->sz - size;
+ if (delta < 256)
+ return;
if ((p = realloc(sma->s.ptr, size)) != NULL) {
Lck_Lock(&sma_sc->sma_mtx);
- sma_sc->stats->g_bytes -= (sma->sz - size);
- sma_sc->stats->c_freed += sma->sz - size;
+ sma_sc->sma_alloc -= delta;
+ sma_sc->stats->g_bytes -= delta;
+ sma_sc->stats->c_freed += delta;
if (sma_sc->sma_max != SIZE_MAX)
- sma_sc->stats->g_space += sma->sz - size;
+ sma_sc->stats->g_space += delta;
sma->sz = size;
Lck_Unlock(&sma_sc->sma_mtx);
sma->s.ptr = p;
More information about the varnish-commit
mailing list