From ae11bd403d138d554a37862e203b533cc7776798 Mon Sep 17 00:00:00 2001 From: "Liu, Xinwu" Date: Fri, 19 Apr 2019 14:12:13 +0800 Subject: [PATCH] tools:acrn-crashlog: check the folder size by calculating the increment This patch refines the process of log space check. Check a folder's size need to traverse all nodes of files and subdirs, in the case of extreme memory strain, accessing these log file nodes frequently will increase the IO pressure on the eMMC. Previously, all log files will be accessed and counted in each space check, this patch refines it by only calculating the increment of new logs. Tracked-On: #1024 Signed-off-by: Liu, Xinwu Reviewed-by: Liu, Xiaojing Acked-by: Chen, Gang --- .../acrnprobe/include/load_conf.h | 1 + tools/acrn-crashlog/acrnprobe/sender.c | 38 +++++++++++++++---- tools/acrn-crashlog/data/acrnprobe.xml | 1 - 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/acrn-crashlog/acrnprobe/include/load_conf.h b/tools/acrn-crashlog/acrnprobe/include/load_conf.h index 57e6191bb..877fced82 100644 --- a/tools/acrn-crashlog/acrnprobe/include/load_conf.h +++ b/tools/acrn-crashlog/acrnprobe/include/load_conf.h @@ -137,6 +137,7 @@ struct sender_t { void (*send)(struct event_t *); struct vmrecord_t vmrecord; + size_t outdir_blocks_size; int sw_updated; /* each sender has their own record */ }; diff --git a/tools/acrn-crashlog/acrnprobe/sender.c b/tools/acrn-crashlog/acrnprobe/sender.c index 9deac3f28..9c57d48fa 100644 --- a/tools/acrn-crashlog/acrnprobe/sender.c +++ b/tools/acrn-crashlog/acrnprobe/sender.c @@ -43,7 +43,6 @@ static int crashlog_check_space(void) { struct sender_t *crashlog = get_sender_by_name("crashlog"); int quota; - size_t dsize; int cfg_size; @@ -57,19 +56,34 @@ static int crashlog_check_space(void) if (!space_available(crashlog->outdir, quota)) return -1; - if (dir_blocks_size(crashlog->outdir, crashlog->outdir_len, - &dsize) == -1) { - LOGE("failed to check outdir size\n"); - return -1; - } - if (cfg_atoi(crashlog->foldersize, crashlog->foldersize_len, &cfg_size) == -1) return -1; - if (dsize/MB >= (size_t)cfg_size) + if (crashlog->outdir_blocks_size/MB >= (size_t)cfg_size) { + LOGD("the total blocks size (%zu) meets the quota (%zu)\n", + crashlog->outdir_blocks_size/MB, (size_t)cfg_size); + return -1; + } + return 0; +} + +static int log_grows(char *dir, size_t len) +{ + size_t add; + struct sender_t *crashlog = get_sender_by_name("crashlog"); + + if (!crashlog) return -1; + if (dir_blocks_size(dir, len, &add) == -1) { + LOGE("failed to check outdir size\n"); + return -1; + } + + add += 4 * KB; + crashlog->outdir_blocks_size += add; + LOGD("log size + %zu = %zu\n", add, crashlog->outdir_blocks_size); return 0; } @@ -1127,6 +1141,8 @@ static void crashlog_send(struct event_t *e) default: LOGE("unsupoorted event type %d\n", e->event_type); } + if (e->dir) + log_grows(e->dir, e->dlen); if (eid) free(eid); if (result) @@ -1179,6 +1195,12 @@ int init_sender(void) return -1; } pthread_mutex_init(&sender->vmrecord.mtx, NULL); + if (dir_blocks_size(sender->outdir, sender->outdir_len, + &sender->outdir_blocks_size) + == -1) { + LOGE("failed to init outdir size\n"); + return -1; + } #ifdef HAVE_TELEMETRICS_CLIENT } else if (!strcmp(sender->name, "telemd")) { diff --git a/tools/acrn-crashlog/data/acrnprobe.xml b/tools/acrn-crashlog/data/acrnprobe.xml index 0939cf94b..defcedbd1 100644 --- a/tools/acrn-crashlog/data/acrnprobe.xml +++ b/tools/acrn-crashlog/data/acrnprobe.xml @@ -17,7 +17,6 @@ telemd /var/log/acrnprobe - 10 UPTIME 5