[PATCH 1/5] Keep track of persisted ban byte usage, and it's overhead.
Martin Blix Grydeland
martin at varnish-software.com
Fri Dec 14 18:40:59 CET 2012
---
bin/varnishd/cache/cache_ban.c | 15 ++++++++++++---
include/tbl/vsc_f_main.h | 9 +++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 47e4f70..a96bc9c 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -262,13 +262,16 @@ ban_equal(const uint8_t *bs1, const uint8_t *bs2)
static void
ban_mark_gone(struct ban *b)
{
+ unsigned ln;
CHECK_OBJ_NOTNULL(b, BAN_MAGIC);
+ ln = ban_len(b->spec);
b->flags |= BAN_F_GONE;
b->spec[BANS_FLAGS] |= BANS_FLAG_GONE;
VWMB();
vbe32enc(b->spec + BANS_LENGTH, 0);
VSC_C_main->bans_gone++;
+ VSC_C_main->bans_bytes_overhead += ln - ban_len(b->spec);
}
/*--------------------------------------------------------------------
@@ -484,6 +487,7 @@ BAN_Insert(struct ban *b)
* the stevedores has been opened, but before any new objects
* can have entered the cache (thus no objects in the mean
* time depending on ban_magic in the list) */
+ VSC_C_main->bans_bytes_persisted += ln;
if (b != ban_magic)
ban_info(BI_NEW, b->spec, ln); /* Notify stevedores */
Lck_Unlock(&ban_mtx);
@@ -584,17 +588,20 @@ ban_export(void)
{
struct ban *b;
struct vsb vsb;
+ unsigned ln;
Lck_AssertHeld(&ban_mtx);
- /* XXX: Use the ban entry size measurements to hit the target
- * and avoid multiple allocations */
- AN(VSB_new(&vsb, NULL, 64 * VSC_C_main->bans, VSB_AUTOEXTEND));
+ ln = VSC_C_main->bans_bytes_persisted - VSC_C_main->bans_bytes_overhead;
+ AN(VSB_new(&vsb, NULL, ln, VSB_AUTOEXTEND));
VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list) {
AZ(VSB_bcat(&vsb, b->spec, ban_len(b->spec)));
}
AZ(VSB_finish(&vsb));
+ assert(VSB_len(&vsb) == ln);
STV_BanExport((const uint8_t *)VSB_data(&vsb), VSB_len(&vsb));
VSB_delete(&vsb);
+ VSC_C_main->bans_bytes_persisted = ln;
+ VSC_C_main->bans_bytes_overhead = 0;
}
static void
@@ -665,6 +672,7 @@ ban_reload(const uint8_t *ban, unsigned len)
VTAILQ_INSERT_TAIL(&ban_head, b2, list);
else
VTAILQ_INSERT_BEFORE(b, b2, list);
+ VSC_C_main->bans_bytes_persisted += len;
/* Hunt down older duplicates */
for (b = VTAILQ_NEXT(b2, list); b != NULL; b = VTAILQ_NEXT(b, list)) {
@@ -930,6 +938,7 @@ ban_cleantail(void)
VSC_C_main->bans--;
VSC_C_main->bans_deleted++;
VTAILQ_REMOVE(&ban_head, b, list);
+ VSC_C_main->bans_bytes_overhead += ban_len(b->spec);
ban_info(BI_DROP, b->spec, ban_len(b->spec));
} else {
b = NULL;
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index d9c78ce..a7de6e0 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -467,6 +467,15 @@ VSC_F(bans_dups, uint64_t, 0, 'c',
"Bans superseded by other bans",
"Count of bans replaced by later identical bans."
)
+VSC_F(bans_bytes_persisted, uint64_t, 0, 'g',
+ "Bytes used by the persisted ban lists",
+ "Number of bytes used by the persisted ban lists."
+)
+VSC_F(bans_bytes_overhead, uint64_t, 0, 'g',
+ "Bytes of overhead in the persisted ban lists",
+ "Number of bytes of overhead accumulated through dropped and"
+ " gone bans in the persistent ban lists."
+)
/**********************************************************************/
--
1.7.10.4
More information about the varnish-dev
mailing list