aboutsummaryrefslogtreecommitdiff
path: root/src/xzdec
diff options
context:
space:
mode:
Diffstat (limited to 'src/xzdec')
-rw-r--r--src/xzdec/xzdec.18
-rw-r--r--src/xzdec/xzdec.c42
2 files changed, 34 insertions, 16 deletions
diff --git a/src/xzdec/xzdec.1 b/src/xzdec/xzdec.1
index 442a19ec..3057c586 100644
--- a/src/xzdec/xzdec.1
+++ b/src/xzdec/xzdec.1
@@ -4,7 +4,7 @@
.\" This file has been put into the public domain.
.\" You can do whatever you want with this file.
.\"
-.TH XZDEC 1 "2009-06-04" "Tukaani" "XZ Utils"
+.TH XZDEC 1 "2010-03-07" "Tukaani" "XZ Utils"
.SH NAME
xzdec, lzmadec \- Small .xz and .lzma decompressors
.SH SYNOPSIS
@@ -99,8 +99,7 @@ can be specified as a percentage of physical RAM. Example:
.IP \(bu 3
The
.I limit
-can be reset back to its default value (currently 40 % of physical RAM)
-by setting it to
+can be reset back to its default value by setting it to
.BR 0 .
.IP \(bu 3
The memory usage limiting can be effectively disabled by setting
@@ -163,6 +162,7 @@ for executables distributed in typical non-embedded operating system
distributions. If you need a truly small
.B .xz
decompressor, consider using XZ Embedded.
-.\" TODO: Provide URL to XZ Embedded.
.SH "SEE ALSO"
.BR xz (1)
+.PP
+XZ Embedded: <http://tukaani.org/xz/embedded.html>
diff --git a/src/xzdec/xzdec.c b/src/xzdec/xzdec.c
index 2b166861..6ddf7d28 100644
--- a/src/xzdec/xzdec.c
+++ b/src/xzdec/xzdec.c
@@ -38,6 +38,9 @@
/// Number of bytes to use memory at maximum
static uint64_t memlimit;
+/// Total amount of physical RAM
+static uint64_t total_ram;
+
/// Error messages are suppressed if this is zero, which is the case when
/// --quiet has been given at least twice.
static unsigned int display_errors = 2;
@@ -103,14 +106,7 @@ version(void)
static void
memlimit_set_percentage(uint32_t percentage)
{
- uint64_t mem = lzma_physmem();
-
- // If we cannot determine the amount of RAM, use the assumption
- // set by the configure script.
- if (mem == 0)
- mem = (uint64_t)(ASSUME_RAM) * 1024 * 1024;
-
- memlimit = percentage * mem / 100;
+ memlimit = percentage * total_ram / 100;
return;
}
@@ -120,15 +116,37 @@ memlimit_set_percentage(uint32_t percentage)
static void
memlimit_set(uint64_t new_memlimit)
{
- if (new_memlimit == 0)
- memlimit_set_percentage(40);
- else
+ if (new_memlimit != 0) {
memlimit = new_memlimit;
+ } else {
+ memlimit = 40 * total_ram / 100;
+ if (memlimit < UINT64_C(80) * 1024 * 1024) {
+ memlimit = 80 * total_ram / 100;
+ if (memlimit > UINT64_C(80) * 1024 * 1024)
+ memlimit = UINT64_C(80) * 1024 * 1024;
+ }
+ }
return;
}
+/// Get the total amount of physical RAM and set the memory usage limit
+/// to the default value.
+static void
+memlimit_init(void)
+{
+ // If we cannot determine the amount of RAM, use the assumption
+ // defined by the configure script.
+ total_ram = lzma_physmem();
+ if (total_ram == 0)
+ total_ram = (uint64_t)(ASSUME_RAM) * 1024 * 1024;
+
+ memlimit_set(0);
+ return;
+}
+
+
/// \brief Convert a string to uint64_t
///
/// This is rudely copied from src/xz/util.c and modified a little. :-(
@@ -422,7 +440,7 @@ main(int argc, char **argv)
// Set the default memory usage limit. This is needed before parsing
// the command line arguments.
- memlimit_set(0);
+ memlimit_init();
// Parse the command line options.
parse_options(argc, argv);