From f6aca5f050c326d8fba07282d2fc5b62a2d9289f Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 22 Sep 2016 04:15:43 +1000 Subject: [PATCH] ckdb - track ram usage for breakqueue --- src/ckdb.c | 8 ++++++++ src/ckdb.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ckdb.c b/src/ckdb.c index d80720b0..1b38ff00 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -6669,6 +6669,7 @@ skippy: if (dec_sockd) sockd_count--; cmd_processing--; + breakqueue_free->ram -= bq->bufsiz; k_add_head(breakqueue_free, bq_item); K_WUNLOCK(breakqueue_free); } @@ -6802,6 +6803,7 @@ static void *sockrun(void *arg) K_WUNLOCK(breakqueue_free); DATA_BREAKQUEUE(bq, bq_item); bq->buf = buf; + bq->bufsiz = strlen(buf)+1; bq->source = (char *)(this->gdata); bq->access = *(int *)(this->cdata); copy_tv(&(bq->accepted), &nowacc); @@ -6812,6 +6814,7 @@ static void *sockrun(void *arg) if (max_sockd_count < ++sockd_count) max_sockd_count = sockd_count; k_add_tail(cmd_breakqueue_store, bq_item); + breakqueue_free->ram += bq->bufsiz; K_WUNLOCK(breakqueue_free); setnow(&now2); sock_lock_br_us[thissock] += us_tvdiff(&now2, &now1); @@ -7025,6 +7028,7 @@ static void *process_reload(__maybe_unused void *arg) PGconn *conn = NULL; K_ITEM *bq_item = NULL; + BREAKQUEUE *bq; char buf[128]; time_t now; ts_t when, when_add; @@ -7169,8 +7173,10 @@ static void *process_reload(__maybe_unused void *arg) process_reload_item(conn, bq_item); + DATA_BREAKQUEUE(bq, bq_item); K_WLOCK(breakqueue_free); reload_processing--; + breakqueue_free->ram -= bq->bufsiz; k_add_head(breakqueue_free, bq_item); K_WUNLOCK(breakqueue_free); @@ -7246,6 +7252,7 @@ static void reload_line(char *filename, char *buf, uint64_t count) // release the lock since strdup could be slow, but rarely DATA_BREAKQUEUE(bq, bq_item); bq->buf = strdup(buf); + bq->bufsiz = strlen(buf)+1; // reloads are normally all pool data but access can be changed bq->source = (char *)ispool; bq->access = reload_access; @@ -7259,6 +7266,7 @@ static void reload_line(char *filename, char *buf, uint64_t count) K_WLOCK(breakqueue_free); k_add_tail(reload_breakqueue_store, bq_item); qcount = reload_breakqueue_store->count; + breakqueue_free->ram += bq->bufsiz; K_WUNLOCK(breakqueue_free); mutex_lock(&bq_reload_waitlock); diff --git a/src/ckdb.h b/src/ckdb.h index 884ccf81..135494ce 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.507" +#define CKDB_VERSION DB_VERSION"-2.508" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1376,6 +1376,7 @@ extern K_STORE *msgline_store; // BREAKQUEUE typedef struct breakqueue { char *buf; + size_t bufsiz; char *source; int access; tv_t accepted; // socket accepted or line read