Commit 837bf1e1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Clean up SMA and SMF stats



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5220 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4f04b127
......@@ -302,7 +302,7 @@ STV_config(const char *spec)
AN(stv->alloc);
if (p == NULL)
bprintf(stv->ident, "storage_%u", seq++);
bprintf(stv->ident, "s%u", seq++);
else {
l = p - spec;
if (l > sizeof stv->ident - 1)
......
......@@ -90,6 +90,11 @@ struct smf {
};
struct smf_sc {
unsigned magic;
#define SMF_SC_MAGIC 0x52962ee7
struct lock mtx;
struct vsc_smf *stats;
const char *filename;
int fd;
unsigned pagesize;
......@@ -97,18 +102,17 @@ struct smf_sc {
struct smfhead order;
struct smfhead free[NBUCKET];
struct smfhead used;
struct lock mtx;
};
/*--------------------------------------------------------------------*/
static void
smf_initfile(struct smf_sc *sc, const char *size)
smf_initfile(struct stevedore *st, struct smf_sc *sc, const char *size)
{
sc->filesize = STV_FileSize(sc->fd, size, &sc->pagesize, "-sfile");
printf("storage_file: filename: %s size %ju MB.\n",
sc->filename, sc->filesize / (1024 * 1024));
printf("SMF.%s: filename: %s size %ju MB.\n",
st->ident, sc->filename, sc->filesize / (1024 * 1024));
AZ(ftruncate(sc->fd, (off_t)sc->filesize));
......@@ -148,7 +152,7 @@ smf_init(struct stevedore *parent, int ac, char * const *av)
AN(fn);
AN(size);
sc = calloc(sizeof *sc, 1);
ALLOC_OBJ(sc, SMF_SC_MAGIC);
XXXAN(sc);
VTAILQ_INIT(&sc->order);
for (u = 0; u < NBUCKET; u++)
......@@ -161,7 +165,7 @@ smf_init(struct stevedore *parent, int ac, char * const *av)
(void)STV_GetFile(fn, &sc->fd, &sc->filename, "-sfile");
mgt_child_inherit(sc->fd, "storage_file");
smf_initfile(sc, size);
smf_initfile(parent, sc, size);
}
/*--------------------------------------------------------------------
......@@ -181,9 +185,9 @@ insfree(struct smf_sc *sc, struct smf *sp)
b = sp->size / sc->pagesize;
if (b >= NBUCKET) {
b = NBUCKET - 1;
VSC_main->n_smf_large++;
sc->stats->n_smf_large++;
} else {
VSC_main->n_smf_frag++;
sc->stats->n_smf_frag++;
}
sp->flist = &sc->free[b];
ns = b * sc->pagesize;
......@@ -211,9 +215,9 @@ remfree(const struct smf_sc *sc, struct smf *sp)
b = sp->size / sc->pagesize;
if (b >= NBUCKET) {
b = NBUCKET - 1;
VSC_main->n_smf_large--;
sc->stats->n_smf_large--;
} else {
VSC_main->n_smf_frag--;
sc->stats->n_smf_frag--;
}
assert(sp->flist == &sc->free[b]);
VTAILQ_REMOVE(sp->flist, sp, status);
......@@ -259,7 +263,7 @@ alloc_smf(struct smf_sc *sc, size_t bytes)
/* Split from front */
sp2 = malloc(sizeof *sp2);
XXXAN(sp2);
VSC_main->n_smf++;
sc->stats->n_smf++;
*sp2 = *sp;
sp->offset += bytes;
......@@ -301,7 +305,7 @@ free_smf(struct smf *sp)
VTAILQ_REMOVE(&sc->order, sp2, order);
remfree(sc, sp2);
free(sp2);
VSC_main->n_smf--;
sc->stats->n_smf--;
}
sp2 = VTAILQ_PREV(sp, smfhead, order);
......@@ -313,7 +317,7 @@ free_smf(struct smf *sp)
sp2->size += sp->size;
VTAILQ_REMOVE(&sc->order, sp, order);
free(sp);
VSC_main->n_smf--;
sc->stats->n_smf--;
sp = sp2;
}
......@@ -338,7 +342,7 @@ trim_smf(struct smf *sp, size_t bytes)
CHECK_OBJ_NOTNULL(sp, SMF_MAGIC);
sp2 = malloc(sizeof *sp2);
XXXAN(sp2);
VSC_main->n_smf++;
sc->stats->n_smf++;
*sp2 = *sp;
sp2->size -= bytes;
......@@ -364,7 +368,7 @@ new_smf(struct smf_sc *sc, unsigned char *ptr, off_t off, size_t len)
XXXAN(sp);
sp->magic = SMF_MAGIC;
sp->s.magic = STORAGE_MAGIC;
VSC_main->n_smf++;
sc->stats->n_smf++;
sp->sc = sc;
sp->size = len;
......@@ -437,20 +441,21 @@ smf_open(const struct stevedore *st)
off_t fail = 1 << 30; /* XXX: where is OFF_T_MAX ? */
off_t sum = 0;
sc = st->priv;
CAST_OBJ_NOTNULL(sc, st->priv, SMF_SC_MAGIC);
sc->stats = VSM_Alloc(sizeof *sc->stats,
VSC_CLASS, VSC_TYPE_SMF, st->ident);
Lck_New(&sc->mtx, lck_smf);
Lck_Lock(&sc->mtx);
smf_open_chunk(sc, sc->filesize, 0, &fail, &sum);
Lck_Unlock(&sc->mtx);
printf("managed to mmap %ju bytes of %ju\n",
(uintmax_t)sum, sc->filesize);
printf("SMF.%s mmap'ed %ju bytes of %ju\n",
st->ident, (uintmax_t)sum, sc->filesize);
/* XXX */
if (sum < MINPAGES * (off_t)getpagesize())
exit (2);
VSC_main->sm_bfree += sc->filesize;
sc->stats->bfree += sc->filesize;
}
/*--------------------------------------------------------------------*/
......@@ -459,23 +464,24 @@ static struct storage *
smf_alloc(struct stevedore *st, size_t size, struct objcore *oc)
{
struct smf *smf;
struct smf_sc *sc = st->priv;
struct smf_sc *sc;
(void)oc;
CAST_OBJ_NOTNULL(sc, st->priv, SMF_SC_MAGIC);
assert(size > 0);
size += (sc->pagesize - 1);
size &= ~(sc->pagesize - 1);
Lck_Lock(&sc->mtx);
VSC_main->sm_nreq++;
sc->stats->nreq++;
smf = alloc_smf(sc, size);
if (smf == NULL) {
Lck_Unlock(&sc->mtx);
return (NULL);
}
CHECK_OBJ_NOTNULL(smf, SMF_MAGIC);
VSC_main->sm_nobj++;
VSC_main->sm_balloc += smf->size;
VSC_main->sm_bfree -= smf->size;
sc->stats->nobj++;
sc->stats->balloc += smf->size;
sc->stats->bfree -= smf->size;
Lck_Unlock(&sc->mtx);
CHECK_OBJ_NOTNULL(&smf->s, STORAGE_MAGIC); /*lint !e774 */
XXXAN(smf);
......@@ -509,8 +515,8 @@ smf_trim(struct storage *s, size_t size)
size &= ~(sc->pagesize - 1);
if (smf->size > size) {
Lck_Lock(&sc->mtx);
VSC_main->sm_balloc -= (smf->size - size);
VSC_main->sm_bfree += (smf->size - size);
sc->stats->balloc -= (smf->size - size);
sc->stats->bfree += (smf->size - size);
trim_smf(smf, size);
assert(smf->size == size);
Lck_Unlock(&sc->mtx);
......@@ -531,9 +537,9 @@ smf_free(struct storage *s)
CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC);
sc = smf->sc;
Lck_Lock(&sc->mtx);
VSC_main->sm_nobj--;
VSC_main->sm_balloc -= smf->size;
VSC_main->sm_bfree += smf->size;
sc->stats->nobj--;
sc->stats->balloc -= smf->size;
sc->stats->bfree += smf->size;
free_smf(smf);
Lck_Unlock(&sc->mtx);
}
......
......@@ -47,7 +47,7 @@ struct sma_sc {
#define SMA_SC_MAGIC 0x1ac8a345
struct lock sma_mtx;
size_t sma_max;
struct vsc_sma *stats;
struct vsc_sma *stats;
};
struct sma {
......@@ -67,13 +67,13 @@ sma_alloc(struct stevedore *st, size_t size, struct objcore *oc)
CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
(void)oc;
Lck_Lock(&sma_sc->sma_mtx);
sma_sc->stats->sma_nreq++;
if (sma_sc->stats->sma_nbytes + size > sma_sc->sma_max)
sma_sc->stats->nreq++;
if (sma_sc->stats->nbytes + size > sma_sc->sma_max)
size = 0;
else {
sma_sc->stats->sma_nobj++;
sma_sc->stats->sma_nbytes += size;
sma_sc->stats->sma_balloc += size;
sma_sc->stats->nobj++;
sma_sc->stats->nbytes += size;
sma_sc->stats->balloc += size;
}
Lck_Unlock(&sma_sc->sma_mtx);
......@@ -117,9 +117,9 @@ sma_free(struct storage *s)
sma_sc = sma->sc;
assert(sma->sz == sma->s.space);
Lck_Lock(&sma_sc->sma_mtx);
sma_sc->stats->sma_nobj--;
sma_sc->stats->sma_nbytes -= sma->sz;
sma_sc->stats->sma_bfree += sma->sz;
sma_sc->stats->nobj--;
sma_sc->stats->nbytes -= sma->sz;
sma_sc->stats->bfree += sma->sz;
Lck_Unlock(&sma_sc->sma_mtx);
free(sma->s.ptr);
free(sma);
......@@ -140,8 +140,8 @@ sma_trim(struct storage *s, size_t size)
assert(size < sma->sz);
if ((p = realloc(sma->s.ptr, size)) != NULL) {
Lck_Lock(&sma_sc->sma_mtx);
sma_sc->stats->sma_nbytes -= (sma->sz - size);
sma_sc->stats->sma_bfree += sma->sz - size;
sma_sc->stats->nbytes -= (sma->sz - size);
sma_sc->stats->bfree += sma->sz - size;
sma->sz = size;
Lck_Unlock(&sma_sc->sma_mtx);
sma->s.ptr = p;
......@@ -175,7 +175,7 @@ sma_init(struct stevedore *parent, int ac, char * const *av)
if ((u != (uintmax_t)(size_t)u))
ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]);
printf("storage.malloc.%s: max size %ju MB.\n", parent->ident,
printf("SMA.%s: max size %ju MB.\n", parent->ident,
u / (1024 * 1024));
sc->sma_max = u;
......
......@@ -35,6 +35,7 @@
#define VSC_TYPE_MAIN ""
#define VSC_TYPE_SMA "SMA"
#define VSC_TYPE_SMF "SMF"
#define VSC_TYPE_VBE "VBE"
#define VSC_TYPE_LCK "LCK"
......
......@@ -29,6 +29,13 @@
*/
VSC_DO(LCK, lck, VSC_TYPE_LCK)
#define VSC_DO_LCK
#include "vsc_fields.h"
#undef VSC_DO_LCK
VSC_DONE(LCK, lck, VSC_TYPE_LCK)
VSC_DO(MAIN, main, VSC_TYPE_MAIN)
#define VSC_DO_MAIN
#include "vsc_fields.h"
......@@ -41,14 +48,14 @@ VSC_DO(SMA, sma, VSC_TYPE_SMA)
#undef VSC_DO_SMA
VSC_DONE(SMA, sma, VSC_TYPE_SMA)
VSC_DO(SMF, smf, VSC_TYPE_SMF)
#define VSC_DO_SMF
#include "vsc_fields.h"
#undef VSC_DO_SMF
VSC_DONE(SMF, smf, VSC_TYPE_SMF)
VSC_DO(VBE, vbe, VSC_TYPE_VBE)
#define VSC_DO_VBE
#include "vsc_fields.h"
#undef VSC_DO_VBE
VSC_DONE(VBE, vbe, VSC_TYPE_VBE)
VSC_DO(LCK, lck, VSC_TYPE_LCK)
#define VSC_DO_LCK
#include "vsc_fields.h"
#undef VSC_DO_LCK
VSC_DONE(LCK, lck, VSC_TYPE_LCK)
......@@ -72,9 +72,7 @@ VSC_F(n_object, uint64_t, 1, 'i', "N struct object")
VSC_F(n_vampireobject, uint64_t, 1, 'i', "N unresurrected objects")
VSC_F(n_objectcore, uint64_t, 1, 'i', "N struct objectcore")
VSC_F(n_objecthead, uint64_t, 1, 'i', "N struct objecthead")
VSC_F(n_smf, uint64_t, 0, 'i', "N struct smf")
VSC_F(n_smf_frag, uint64_t, 0, 'i', "N small free smf")
VSC_F(n_smf_large, uint64_t, 0, 'i', "N large free smf")
VSC_F(n_vbc, uint64_t, 0, 'i', "N struct vbc")
VSC_F(n_wrk, uint64_t, 0, 'i', "N worker threads")
VSC_F(n_wrk_create, uint64_t, 0, 'a', "N worker threads created")
......@@ -117,11 +115,6 @@ VSC_F(shm_flushes, uint64_t, 0, 'a', "SHM flushes due to overflow")
VSC_F(shm_cont, uint64_t, 0, 'a', "SHM MTX contention")
VSC_F(shm_cycles, uint64_t, 0, 'a', "SHM cycles through buffer")
VSC_F(sm_nreq, uint64_t, 0, 'a', "allocator requests")
VSC_F(sm_nobj, uint64_t, 0, 'i', "outstanding allocations")
VSC_F(sm_balloc, uint64_t, 0, 'i', "bytes allocated")
VSC_F(sm_bfree, uint64_t, 0, 'i', "bytes free")
VSC_F(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests")
VSC_F(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations")
VSC_F(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes")
......@@ -163,32 +156,48 @@ VSC_F(vmods, uint64_t, 0, 'i', "Loaded VMODs")
/**********************************************************************/
#ifdef VSC_DO_SMA
#ifdef VSC_DO_LCK
VSC_F(sma_nreq, uint64_t, 0, 'a', "Allocator requests")
VSC_F(sma_nobj, uint64_t, 0, 'i', "Outstanding allocations")
VSC_F(sma_nbytes, uint64_t, 0, 'i', "Outstanding bytes")
VSC_F(sma_balloc, uint64_t, 0, 'i', "Bytes allocated")
VSC_F(sma_bfree, uint64_t, 0, 'i', "Bytes free")
VSC_F(creat, uint64_t, 0, 'a', "Created locks")
VSC_F(destroy, uint64_t, 0, 'a', "Destroyed locks")
VSC_F(locks, uint64_t, 0, 'a', "Lock Operations")
VSC_F(colls, uint64_t, 0, 'a', "Collisions")
#endif
/**********************************************************************
* All Stevedores support these counters
*/
#if defined(VSC_DO_SMA) || defined (VSC_DO_SMF)
VSC_F(nreq, uint64_t, 0, 'a', "Allocator requests")
VSC_F(nobj, uint64_t, 0, 'i', "Outstanding allocations")
VSC_F(nbytes, uint64_t, 0, 'i', "Outstanding bytes")
VSC_F(balloc, uint64_t, 0, 'i', "Bytes allocated")
VSC_F(bfree, uint64_t, 0, 'i', "Bytes free")
#endif
/**********************************************************************/
#ifdef VSC_DO_VBE
#ifdef VSC_DO_SMA
/* No SMA specific counters */
#endif
VSC_F(vcls, uint64_t, 0, 'i', "VCL references")
VSC_F(happy, uint64_t, 0, 'b', "Happy health probes")
/**********************************************************************/
#ifdef VSC_DO_SMF
VSC_F(n_smf, uint64_t, 0, 'i', "N struct smf")
VSC_F(n_smf_frag, uint64_t, 0, 'i', "N small free smf")
VSC_F(n_smf_large, uint64_t, 0, 'i', "N large free smf")
#endif
/**********************************************************************/
#ifdef VSC_DO_LCK
#ifdef VSC_DO_VBE
VSC_F(creat, uint64_t, 0, 'a', "Created locks")
VSC_F(destroy, uint64_t, 0, 'a', "Destroyed locks")
VSC_F(locks, uint64_t, 0, 'a', "Lock Operations")
VSC_F(colls, uint64_t, 0, 'a', "Collisions")
VSC_F(vcls, uint64_t, 0, 'i', "VCL references")
VSC_F(happy, uint64_t, 0, 'b', "Happy health probes")
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment