From f075b542fec9aa8682aecf8c7ad80ead2577ffea Mon Sep 17 00:00:00 2001 From: simon987 Date: Sat, 19 Feb 2022 14:05:50 -0500 Subject: [PATCH] Tweak mem-throttle option --- src/cli.c | 10 +++++----- src/cli.h | 4 ++-- src/main.c | 12 +++++++----- src/tpool.c | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/cli.c b/src/cli.c index edca900..694372d 100644 --- a/src/cli.c +++ b/src/cli.c @@ -261,12 +261,12 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) { args->treemap_threshold = atof(args->treemap_threshold_str); } - if (args->max_memory_buffer == OPTION_VALUE_UNSPECIFIED) { - args->max_memory_buffer = DEFAULT_MAX_MEM_BUFFER; + if (args->max_memory_buffer_mib == OPTION_VALUE_UNSPECIFIED) { + args->max_memory_buffer_mib = DEFAULT_MAX_MEM_BUFFER; } - if (args->scan_mem_limit <= 0) { - args->scan_mem_limit = DEFAULT_THROTTLE_MEMORY_THRESHOLD; + if (args->scan_mem_limit_mib == OPTION_VALUE_UNSPECIFIED || args->scan_mem_limit_mib == OPTION_VALUE_DISABLE) { + args->scan_mem_limit_mib = DEFAULT_THROTTLE_MEMORY_THRESHOLD; } if (args->list_path != OPTION_VALUE_UNSPECIFIED) { @@ -301,7 +301,7 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) { LOG_DEBUGF("cli.c", "arg fast=%d", args->fast) LOG_DEBUGF("cli.c", "arg fast_epub=%d", args->fast_epub) LOG_DEBUGF("cli.c", "arg treemap_threshold=%f", args->treemap_threshold) - LOG_DEBUGF("cli.c", "arg max_memory_buffer=%d", args->max_memory_buffer) + LOG_DEBUGF("cli.c", "arg max_memory_buffer_mib=%d", args->max_memory_buffer_mib) LOG_DEBUGF("cli.c", "arg list_path=%s", args->list_path) return 0; diff --git a/src/cli.h b/src/cli.h index cf53fd0..cdf22b6 100644 --- a/src/cli.h +++ b/src/cli.h @@ -13,7 +13,7 @@ typedef struct scan_args { int tn_size; int content_size; int threads; - int scan_mem_limit; + int scan_mem_limit_mib; char *incremental; char *output; char *rewrite_url; @@ -31,7 +31,7 @@ typedef struct scan_args { int fast; const char* treemap_threshold_str; double treemap_threshold; - int max_memory_buffer; + int max_memory_buffer_mib; int read_subtitles; /** Number of thumbnails to generate */ int tn_count; diff --git a/src/main.c b/src/main.c index d8e481d..481257c 100644 --- a/src/main.c +++ b/src/main.c @@ -221,7 +221,7 @@ void initialize_scan_context(scan_args_t *args) { ScanCtx.media_ctx.log = _log; ScanCtx.media_ctx.logf = _logf; ScanCtx.media_ctx.store = _store; - ScanCtx.media_ctx.max_media_buffer = (long) args->max_memory_buffer * 1024 * 1024; + ScanCtx.media_ctx.max_media_buffer = (long) args->max_memory_buffer_mib * 1024 * 1024; ScanCtx.media_ctx.read_subtitles = args->read_subtitles; ScanCtx.media_ctx.read_subtitles = args->tn_count; @@ -259,7 +259,7 @@ void initialize_scan_context(scan_args_t *args) { ScanCtx.threads = args->threads; ScanCtx.depth = args->depth; - ScanCtx.mem_limit = args->scan_mem_limit * 1024 * 1024; + ScanCtx.mem_limit = (size_t) args->scan_mem_limit_mib * 1024 * 1024; strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path)); strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name)); @@ -620,7 +620,9 @@ int main(int argc, const char *argv[]) { OPT_GROUP("Scan options"), OPT_INTEGER('t', "threads", &common_threads, "Number of threads. DEFAULT=1"), - OPT_STRING(0, "mem-throttle", &scan_args->scan_mem_limit, "Total memory threshold in MB for scan throttling. DEFAULT=0"), + OPT_INTEGER(0, "mem-throttle", &scan_args->scan_mem_limit_mib, + "Total memory threshold in MiB for scan throttling. DEFAULT=0", + set_to_negative_if_value_is_zero, (intptr_t) &scan_args->scan_mem_limit_mib), OPT_FLOAT('q', "thumbnail-quality", &scan_args->tn_quality, "Thumbnail quality, on a scale of 1.0 to 31.0, 1.0 being the best. DEFAULT=1", set_to_negative_if_value_is_zero, (intptr_t) &scan_args->tn_quality), @@ -655,8 +657,8 @@ int main(int argc, const char *argv[]) { OPT_BOOLEAN(0, "fast", &scan_args->fast, "Only index file names & mime type"), OPT_STRING(0, "treemap-threshold", &scan_args->treemap_threshold_str, "Relative size threshold for treemap " "(see USAGE.md). DEFAULT: 0.0005"), - OPT_INTEGER(0, "mem-buffer", &scan_args->max_memory_buffer, - "Maximum memory buffer size per thread in MB for files inside archives " + OPT_INTEGER(0, "mem-buffer", &scan_args->max_memory_buffer_mib, + "Maximum memory buffer size per thread in MiB for files inside archives " "(see USAGE.md). DEFAULT: 2000"), OPT_BOOLEAN(0, "read-subtitles", &scan_args->read_subtitles, "Read subtitles from media files."), OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub, diff --git a/src/tpool.c b/src/tpool.c index 970d8c3..883d49f 100644 --- a/src/tpool.c +++ b/src/tpool.c @@ -154,7 +154,7 @@ static void *tpool_worker(void *arg) { int stuck_notified = 0; int throttle_ms = 0; - while (1) { + while (TRUE) { pthread_mutex_lock(&pool->work_mutex); if (pool->stop) { break;