Improve displaying of the memory usage limit.
This commit is contained in:
parent
b3cc4d8edd
commit
96a4f840e3
@ -244,15 +244,13 @@ coder_set_compression_settings(void)
|
|||||||
if (!preset_default)
|
if (!preset_default)
|
||||||
message(V_WARNING, _("Adjusted LZMA%c dictionary size "
|
message(V_WARNING, _("Adjusted LZMA%c dictionary size "
|
||||||
"from %s MiB to %s MiB to not exceed "
|
"from %s MiB to %s MiB to not exceed "
|
||||||
"the memory usage limit of %s"),
|
"the memory usage limit of %s MiB"),
|
||||||
filters[i].id == LZMA_FILTER_LZMA2
|
filters[i].id == LZMA_FILTER_LZMA2
|
||||||
? '2' : '1',
|
? '2' : '1',
|
||||||
uint64_to_str(orig_dict_size >> 20, 0),
|
uint64_to_str(orig_dict_size >> 20, 0),
|
||||||
uint64_to_str(opt->dict_size >> 20, 1),
|
uint64_to_str(opt->dict_size >> 20, 1),
|
||||||
uint64_to_nicestr(memory_limit,
|
uint64_to_str(round_up_to_mib(
|
||||||
NICESTR_B,
|
memory_limit), 2));
|
||||||
NICESTR_MIB,
|
|
||||||
false, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -852,14 +852,35 @@ message_mem_needed(enum message_verbosity v, uint64_t memusage)
|
|||||||
if (v > verbosity)
|
if (v > verbosity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// NOTE: With bad luck, the rounded values may be the same, which
|
// Convert memusage to MiB, rounding up to the next full MiB.
|
||||||
// can be confusing to the user when this function is called to
|
// This way the user can always use the displayed usage as
|
||||||
// tell that the memory usage limit was too low.
|
// the new memory usage limit. (If we rounded to the nearest,
|
||||||
message(v, _("%s of memory is required. The limit is %s."),
|
// the user might need to +1 MiB to get high enough limit.)
|
||||||
uint64_to_nicestr(memusage,
|
memusage = round_up_to_mib(memusage);
|
||||||
NICESTR_B, NICESTR_MIB, false, 0),
|
|
||||||
uint64_to_nicestr(hardware_memlimit_get(),
|
// 2^64 with thousand separators + " MiB" suffix + '\0' = 26 + 4 + 1
|
||||||
NICESTR_B, NICESTR_MIB, false, 1));
|
char memlimitstr[32];
|
||||||
|
|
||||||
|
// Show the memory usage limit as MiB unless it is less than 1 MiB.
|
||||||
|
// This way it's easy to notice errors where one has typed
|
||||||
|
// --memory=123 instead of --memory=123MiB.
|
||||||
|
uint64_t memlimit = hardware_memlimit_get();
|
||||||
|
if (memlimit < (UINT32_C(1) << 20)) {
|
||||||
|
snprintf(memlimitstr, sizeof(memlimitstr), "%s B",
|
||||||
|
uint64_to_str(memlimit, 1));
|
||||||
|
} else {
|
||||||
|
// Round up just like with memusage. If this function is
|
||||||
|
// called for informational purporse (to just show the
|
||||||
|
// current usage and limit), we will never show that
|
||||||
|
// the usage is higher than the limit, which would give
|
||||||
|
// a false impression that the memory usage limit isn't
|
||||||
|
// properly enforced.
|
||||||
|
snprintf(memlimitstr, sizeof(memlimitstr), "%s MiB",
|
||||||
|
uint64_to_str(round_up_to_mib(memlimit), 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
message(v, _("%s MiB of memory is required. The limit is %s."),
|
||||||
|
uint64_to_str(memusage, 0), memlimitstr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,13 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern uint64_t
|
||||||
|
round_up_to_mib(uint64_t n)
|
||||||
|
{
|
||||||
|
return (n >> 20) + ((n & ((UINT32_C(1) << 20) - 1)) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern const char *
|
extern const char *
|
||||||
uint64_to_str(uint64_t value, uint32_t slot)
|
uint64_to_str(uint64_t value, uint32_t slot)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,12 @@ extern uint64_t str_to_uint64(const char *name, const char *value,
|
|||||||
uint64_t min, uint64_t max);
|
uint64_t min, uint64_t max);
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Round an integer up to the next full MiB and convert to MiB
|
||||||
|
///
|
||||||
|
/// This is used when printing memory usage and limit.
|
||||||
|
extern uint64_t round_up_to_mib(uint64_t n);
|
||||||
|
|
||||||
|
|
||||||
/// \brief Convert uint64_t to a string
|
/// \brief Convert uint64_t to a string
|
||||||
///
|
///
|
||||||
/// Convert the given value to a string with locale-specific thousand
|
/// Convert the given value to a string with locale-specific thousand
|
||||||
|
Loading…
Reference in New Issue
Block a user