[master] c5a1c75 With streaming, we cannot allow a storage chunk to move once we have started to fill it. Add a param to the STV_trim() method to indicate acceptability of move.
Poul-Henning Kamp
phk at varnish-cache.org
Tue Mar 27 13:32:13 CEST 2012
commit c5a1c750982d6a758715b1ad69ea9373521ea6e7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Mar 27 08:09:39 2012 +0000
With streaming, we cannot allow a storage chunk to move once we
have started to fill it. Add a param to the STV_trim() method
to indicate acceptability of move.
The only reason I don't remove STV_trim() entirely, is that a site
with gazillions very small objects, will want to disable streaming
and use malloc to squeeze as many objects into memory as possible.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 0bb75df..8f9b6d9 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1013,7 +1013,7 @@ int RFC2616_Do_Cond(const struct sess *sp);
struct object *STV_NewObject(struct busyobj *, struct objcore **,
const char *hint, unsigned len, uint16_t nhttp);
struct storage *STV_alloc(struct busyobj *, size_t size);
-void STV_trim(struct storage *st, size_t size);
+void STV_trim(struct storage *st, size_t size, int move_ok);
void STV_free(struct storage *st);
void STV_open(void);
void STV_close(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index eb7b855..0246f1b 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -195,7 +195,7 @@ vfp_nop_end(struct busyobj *bo)
return (0);
}
if (st->len < st->space)
- STV_trim(st, st->len);
+ STV_trim(st, st->len, 1);
return (0);
}
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index b71401d..f1cbe94 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -391,13 +391,13 @@ STV_alloc(struct busyobj *bo, size_t size)
}
void
-STV_trim(struct storage *st, size_t size)
+STV_trim(struct storage *st, size_t size, int move_ok)
{
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
AN(st->stevedore);
if (st->stevedore->trim)
- st->stevedore->trim(st, size);
+ st->stevedore->trim(st, size, move_ok);
}
void
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 6994314..aae9186 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -42,7 +42,7 @@ struct lru;
typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
-typedef void storage_trim_f(struct storage *, size_t size);
+typedef void storage_trim_f(struct storage *, size_t size, int move_ok);
typedef void storage_free_f(struct storage *);
typedef struct object *storage_allocobj_f(struct stevedore *, struct busyobj *,
struct objcore **, unsigned ltot, const struct stv_objsecrets *);
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index 680b870..3d422fe 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -488,7 +488,7 @@ smf_alloc(struct stevedore *st, size_t size)
/*--------------------------------------------------------------------*/
static void
-smf_trim(struct storage *s, size_t size)
+smf_trim(struct storage *s, size_t size, int move_ok)
{
struct smf *smf;
struct smf_sc *sc;
@@ -499,6 +499,10 @@ smf_trim(struct storage *s, size_t size)
xxxassert(size > 0); /* XXX: seen */
CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC);
assert(size <= smf->size);
+
+ if (!move_ok)
+ return; /* XXX: trim_smf needs fixed */
+
sc = smf->sc;
size += (sc->pagesize - 1);
size &= ~(sc->pagesize - 1);
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index 2f34c98..0470093 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -145,7 +145,7 @@ sma_free(struct storage *s)
}
static void
-sma_trim(struct storage *s, size_t size)
+sma_trim(struct storage *s, size_t size, int move_ok)
{
struct sma_sc *sma_sc;
struct sma *sma;
@@ -158,6 +158,10 @@ sma_trim(struct storage *s, size_t size)
assert(sma->sz == sma->s.space);
assert(size < sma->sz);
+
+ if (!move_ok)
+ return;
+
delta = sma->sz - size;
if (delta < 256)
return;
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 35845f0..d206a86 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -523,19 +523,6 @@ smp_alloc(struct stevedore *st, size_t size)
}
/*--------------------------------------------------------------------
- * Trim a bite
- * XXX: We could trim the last allocation.
- */
-
-static void
-smp_trim(struct storage *ss, size_t size)
-{
-
- (void)ss;
- (void)size;
-}
-
-/*--------------------------------------------------------------------
* We don't track frees of storage, we track the objects which own the
* storage and when there are no more objects in in the first segment,
* it can be reclaimed.
@@ -562,7 +549,6 @@ const struct stevedore smp_stevedore = {
.alloc = smp_alloc,
.allocobj = smp_allocobj,
.free = smp_free,
- .trim = smp_trim,
};
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list