Add a precise gauge of the number of objects in memory (in fdb tree)

Related to #45
parent 434b43bd
......@@ -25,6 +25,8 @@ fellow
* Improved code coverage and added Coverity for additional linting.
* Added g_mem_obj gauge.
* Added an absolute maximum of 31 and dynamic maximum to the readahead
parameter to avoid single object deliveries holding more than 1/16
of the available memory cache.
......
......@@ -120,6 +120,13 @@
Note: This number is only approximate
.. varnish_vsc:: g_mem_obj
:type: gauge
:level: info
:oneliner: Objects in memory
Exact number of objects currently in memory (fco_infdb).
.. varnish_vsc:: g_dsk_bytes
:type: gauge
:level: info
......
......@@ -759,6 +759,7 @@ struct fellow_cache {
pthread_mutex_t fdb_mtx;
struct fellow_cache_fdb_head fdb_head;
uint64_t *g_mem_obj; // stats
struct fellow_cache_lrus lrus[1];
......@@ -1600,6 +1601,8 @@ fellow_cache_obj_evict_mutate(const struct fellow_cache_lru *lru,
AN(FCO_REFCNT(fco));
AZ(pthread_mutex_lock(&fc->fdb_mtx));
(void) VRBT_REMOVE(fellow_cache_fdb_head, &fc->fdb_head, fco);
AN(*fc->g_mem_obj);
(*fc->g_mem_obj)--;
AZ(pthread_mutex_unlock(&fc->fdb_mtx));
// state, oc (relevant for lru)
......@@ -2655,6 +2658,7 @@ fellow_cache_obj_unbusy(struct fellow_busy *fbo, enum fcol_state wantlog)
AZ(pthread_mutex_lock(&fc->fdb_mtx));
ofco = VRBT_INSERT(fellow_cache_fdb_head, &fc->fdb_head, fco);
AZ(ofco);
(*fc->g_mem_obj)++;
AZ(pthread_mutex_unlock(&fc->fdb_mtx));
if (likely(fco->logstate == FCOL_DUNNO))
......@@ -4864,6 +4868,8 @@ fellow_cache_obj_deref_locked(struct fellow_lru_chgbatch *lcb,
/* REF_FDB_REMOVE */
AZ(pthread_mutex_lock(&fc->fdb_mtx));
(void) VRBT_REMOVE(fellow_cache_fdb_head, &fc->fdb_head, fco);
AN(*fc->g_mem_obj);
(*fc->g_mem_obj)--;
AZ(pthread_mutex_unlock(&fc->fdb_mtx));
}
return (refcnt);
......@@ -4947,6 +4953,7 @@ struct objcore **ocp, uintptr_t priv2, unsigned crit)
else if (ocp) {
AZ(nfco->oc);
TAKE_OBJ_NOTNULL(nfco->oc, ocp, OBJCORE_MAGIC);
(*fc->g_mem_obj)++;
}
AZ(pthread_mutex_unlock(&fc->fdb_mtx));
......@@ -5389,7 +5396,7 @@ fellow_cache_assert_disk_fmt(void)
struct fellow_cache *
fellow_cache_init(struct fellow_fd *ffd, buddy_t *membuddy,
struct stvfe_tune *tune, fellow_task_run_t taskrun)
struct stvfe_tune *tune, fellow_task_run_t taskrun, uint64_t *g_mem_obj)
{
struct fellow_cache *fc;
......@@ -5410,6 +5417,8 @@ fellow_cache_init(struct fellow_fd *ffd, buddy_t *membuddy,
AZ(pthread_mutex_init(&fc->fdb_mtx, &fc_mtxattr_errorcheck));
VRBT_INIT(&fc->fdb_head);
fc->g_mem_obj = g_mem_obj;
AZ(*g_mem_obj);
fellow_cache_async_init(fc, taskrun);
......@@ -5435,6 +5444,7 @@ fellow_cache_fini(struct fellow_cache **fcp)
fellow_cache_lrus_fini(fc->lrus);
assert(VRBT_EMPTY(&fc->fdb_head));
AZ(*fc->g_mem_obj);
fellow_cache_async_fini(fc);
......@@ -6119,6 +6129,7 @@ t_cache(const char *fn, unsigned chksum)
struct fellow_cache_res fcr;
int injcount;
char *ptr;
uint64_t g_mem_obj = 0;
DBGSZ(fellow_disk_seg);
DBGSZ(fellow_disk_seglist);
......@@ -6152,7 +6163,8 @@ t_cache(const char *fn, unsigned chksum)
XXXAN(ffd);
fellow_log_open(ffd, resurrect_discard, &resur_priv);
fc = fellow_cache_init(ffd, membuddy, tune, fellow_simple_task_run);
fc = fellow_cache_init(ffd, membuddy, tune, fellow_simple_task_run,
&g_mem_obj);
t_lcb(fc);
......@@ -6439,8 +6451,9 @@ t_cache(const char *fn, unsigned chksum)
XXXAN(ffd);
fellow_log_open(ffd, resurrect_keep, &resur_priv);
AZ(g_mem_obj);
fc = fellow_cache_init(ffd, membuddy, tune,
fellow_simple_task_run);
fellow_simple_task_run, &g_mem_obj);
}
}
......
......@@ -49,7 +49,7 @@ struct fellow_cache_res {
struct fellow_cache *
fellow_cache_init(struct fellow_fd *, buddy_t *, struct stvfe_tune *,
fellow_task_run_t);
fellow_task_run_t, uint64_t *);
void fellow_cache_fini(struct fellow_cache **);
void fellow_cache_obj_delete(struct fellow_cache *fc,
......
......@@ -2415,7 +2415,7 @@ sfe_open_scope(struct stevedore *stv)
}
fc = fellow_cache_init(ffd, stvfe->membuddy, &stvfe->tune,
sfe_taskrun);
sfe_taskrun, &stvfe->stats->g_mem_obj);
if (fc == NULL) {
/* should never happen, unless we turn assertions into
* errors */
......
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