summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-08 19:36:09 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-14 19:50:38 +0200
commit875ae5661a011b757f0eaa468dea6ba91cbe5437 (patch)
tree0ad11ce598af13163251c727da5ce23d9e23c29d /src/core/load-fragment.c
parent9184ca48ea43e009cd6f379f319926109a30926c (diff)
core: optionally, accept a percentage value for MemoryLimit= and related settings
If a percentage is used, it is taken relative to the installed RAM size. This should make it easier to write generic unit files that adapt to the local system.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index fe60bee789..05852cc7e3 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2812,9 +2812,19 @@ int config_parse_memory_limit(
int r;
if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
- r = parse_size(rvalue, 1024, &bytes);
- if (r < 0 || bytes < 1) {
- log_syntax(unit, LOG_ERR, filename, line, r, "Memory limit '%s' invalid. Ignoring.", rvalue);
+
+ r = parse_percent(rvalue);
+ if (r < 0) {
+ r = parse_size(rvalue, 1024, &bytes);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r, "Memory limit '%s' invalid. Ignoring.", rvalue);
+ return 0;
+ }
+ } else
+ bytes = (((physical_memory() / page_size()) * (uint64_t) r) / 100) * page_size();
+
+ if (bytes < 1) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Memory limit '%s' too small. Ignoring.", rvalue);
return 0;
}
}