Tweak mem-throttle option

This commit is contained in:
simon987 2022-02-19 14:05:50 -05:00
parent 3d4331b27d
commit f075b542fe
4 changed files with 15 additions and 13 deletions

View File

@ -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); args->treemap_threshold = atof(args->treemap_threshold_str);
} }
if (args->max_memory_buffer == OPTION_VALUE_UNSPECIFIED) { if (args->max_memory_buffer_mib == OPTION_VALUE_UNSPECIFIED) {
args->max_memory_buffer = DEFAULT_MAX_MEM_BUFFER; args->max_memory_buffer_mib = DEFAULT_MAX_MEM_BUFFER;
} }
if (args->scan_mem_limit <= 0) { if (args->scan_mem_limit_mib == OPTION_VALUE_UNSPECIFIED || args->scan_mem_limit_mib == OPTION_VALUE_DISABLE) {
args->scan_mem_limit = DEFAULT_THROTTLE_MEMORY_THRESHOLD; args->scan_mem_limit_mib = DEFAULT_THROTTLE_MEMORY_THRESHOLD;
} }
if (args->list_path != OPTION_VALUE_UNSPECIFIED) { 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=%d", args->fast)
LOG_DEBUGF("cli.c", "arg fast_epub=%d", args->fast_epub) 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 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) LOG_DEBUGF("cli.c", "arg list_path=%s", args->list_path)
return 0; return 0;

View File

@ -13,7 +13,7 @@ typedef struct scan_args {
int tn_size; int tn_size;
int content_size; int content_size;
int threads; int threads;
int scan_mem_limit; int scan_mem_limit_mib;
char *incremental; char *incremental;
char *output; char *output;
char *rewrite_url; char *rewrite_url;
@ -31,7 +31,7 @@ typedef struct scan_args {
int fast; int fast;
const char* treemap_threshold_str; const char* treemap_threshold_str;
double treemap_threshold; double treemap_threshold;
int max_memory_buffer; int max_memory_buffer_mib;
int read_subtitles; int read_subtitles;
/** Number of thumbnails to generate */ /** Number of thumbnails to generate */
int tn_count; int tn_count;

View File

@ -221,7 +221,7 @@ void initialize_scan_context(scan_args_t *args) {
ScanCtx.media_ctx.log = _log; ScanCtx.media_ctx.log = _log;
ScanCtx.media_ctx.logf = _logf; ScanCtx.media_ctx.logf = _logf;
ScanCtx.media_ctx.store = _store; 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->read_subtitles;
ScanCtx.media_ctx.read_subtitles = args->tn_count; 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.threads = args->threads;
ScanCtx.depth = args->depth; 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.path, args->output, sizeof(ScanCtx.index.path));
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name)); 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_GROUP("Scan options"),
OPT_INTEGER('t', "threads", &common_threads, "Number of threads. DEFAULT=1"), 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, 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", "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), 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_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 " OPT_STRING(0, "treemap-threshold", &scan_args->treemap_threshold_str, "Relative size threshold for treemap "
"(see USAGE.md). DEFAULT: 0.0005"), "(see USAGE.md). DEFAULT: 0.0005"),
OPT_INTEGER(0, "mem-buffer", &scan_args->max_memory_buffer, OPT_INTEGER(0, "mem-buffer", &scan_args->max_memory_buffer_mib,
"Maximum memory buffer size per thread in MB for files inside archives " "Maximum memory buffer size per thread in MiB for files inside archives "
"(see USAGE.md). DEFAULT: 2000"), "(see USAGE.md). DEFAULT: 2000"),
OPT_BOOLEAN(0, "read-subtitles", &scan_args->read_subtitles, "Read subtitles from media files."), OPT_BOOLEAN(0, "read-subtitles", &scan_args->read_subtitles, "Read subtitles from media files."),
OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub, OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub,

View File

@ -154,7 +154,7 @@ static void *tpool_worker(void *arg) {
int stuck_notified = 0; int stuck_notified = 0;
int throttle_ms = 0; int throttle_ms = 0;
while (1) { while (TRUE) {
pthread_mutex_lock(&pool->work_mutex); pthread_mutex_lock(&pool->work_mutex);
if (pool->stop) { if (pool->stop) {
break; break;