From: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>

If threads are automatically selected then it is possible that their
number needs to get reduced in order not to exceed the current memory
limit. This "reducing" forces a warning which is printed on stderr to
inform the user.
The information is probably not something the user would be interested
in since he did not explicitly ask for the additional threads and so any
number of threads would probably do it without raising an eyebrow.
The downside of this warning is that a few testsuites capture the output
of stderr and complain now that something went wrong.

Print the warning about reduced threads only if number is selected
- automatically and asked to be verbose (-v)
- explicit by the user

Signed-off-by: Sebastian Andrzej Siewior <sebast...@breakpoint.cc>
---
 src/xz/coder.c    | 13 +++++++++++--
 src/xz/hardware.c |  7 +++++++
 src/xz/hardware.h |  2 ++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/xz/coder.c b/src/xz/coder.c
index 4efaa802b9bbc..e5e30558aedf6 100644
--- a/src/xz/coder.c
+++ b/src/xz/coder.c
@@ -580,8 +580,13 @@ coder_set_compression_settings(void)
                                message_bug();
 
                        if (memory_usage <= memory_limit) {
+                               enum message_verbosity v = V_WARNING;
+
+                               if (hardware_threads_are_automatic())
+                                       v = V_VERBOSE;
+
                                // The memory usage is now low enough.
-                               message(V_WARNING, _("Reduced the number of "
+                               message(v, _("Reduced the number of "
                                        "threads from %s to %s to not exceed "
                                        "the memory usage limit of %s MiB"),
                                        uint64_to_str(
@@ -601,7 +606,11 @@ coder_set_compression_settings(void)
                // time the soft limit will never make xz fail and never make
                // xz change settings that would affect the compressed output.
                if (hardware_memlimit_mtenc_is_default()) {
-                       message(V_WARNING, _("Reduced the number of threads "
+                       enum message_verbosity v = V_WARNING;
+
+                       if (hardware_threads_are_automatic())
+                               v = V_VERBOSE;
+                       message(v, _("Reduced the number of threads "
                                "from %s to one. The automatic memory usage "
                                "limit of %s MiB is still being exceeded. "
                                "%s MiB of memory is required. "
diff --git a/src/xz/hardware.c b/src/xz/hardware.c
index 952652fecb8d9..c1d54a5910b7a 100644
--- a/src/xz/hardware.c
+++ b/src/xz/hardware.c
@@ -195,6 +195,13 @@ hardware_memlimit_mtenc_get(void)
 }
 
 
+extern bool
+hardware_threads_are_automatic(void)
+{
+       return threads_are_automatic;
+}
+
+
 extern bool
 hardware_memlimit_mtenc_is_default(void)
 {
diff --git a/src/xz/hardware.h b/src/xz/hardware.h
index 25b351e32b195..e4cfe299d2b2d 100644
--- a/src/xz/hardware.h
+++ b/src/xz/hardware.h
@@ -25,6 +25,8 @@ extern uint32_t hardware_threads_get(void);
 /// This can be true even if the number of threads is one.
 extern bool hardware_threads_is_mt(void);
 
+/// Returns true if the number of threads has set automaticaly.
+extern bool hardware_threads_are_automatic(void);
 
 /// Set the memory usage limit. There are separate limits for compression,
 /// decompression (also includes --list), and multithreaded decompression.
-- 
2.43.0


Reply via email to