[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#862013: initramfs-tools-core: /run tmpfs size hardcoded at 10% RAM, but 16.0 MiB free required in /run/systemd



Hi,

Using 10% of RAM for /run is a good default, but not suitable for all
systems. 10% might be too small for system with less memory (e.g.
virtual machine with 160 MiB RAM) or too big (VM host with 256/512 GiB
RAM). A too small /run partition leads to not enough space on it. If
the
/run partition is huge, systemd's journald will consume lot of memory,
because it defaults to using at most 15% of the respective file system
of /run/log/journal.

Adjusting the size of /run via an entry in /etc/fstab is not sufficient
since journald calculates it limits before systemd remounts /run with
the small size. Therefore journald could occupy the full /run partition
with its logs.

Allow specifying the size of /run by adding a RUNSIZE configuration
variable and a ramsize= boot argument. Mounting /run must be done after
reading the configuration.

A tested patch is attached and I created a merge proposal:
https://salsa.debian.org/kernel-team/initramfs-tools/merge_requests/2

-- 
Benjamin Drung
System Developer
Debian & Ubuntu Developer

ProfitBricks GmbH
Greifswalder Str. 207
10405 Berlin

Email: benjamin.drung@profitbricks.com
URL: https://www.profitbricks.de

Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 125506 B
Geschäftsführer: Achim Weiss, Matthias Steinberg, Christoph Steffens
From 6569b72cad0145843b55022fa6bc9e00a75a6d79 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.drung@profitbricks.com>
Date: Tue, 15 May 2018 12:12:56 +0200
Subject: [PATCH] Make size of /run configurable

Using 10% of RAM for /run is a good default, but not suitable for all
systems. 10% might be too small for system with less memory (e.g.
virtual machine with 160 MiB RAM) or too big (VM host with 256/512 GiB
RAM). A too small /run partition leads to not enough space on it. If the
/run partition is huge, systemd's journald will consume lot of memory,
because it defaults to using at most 15% of the respective file system
of /run/log/journal.

Adjusting the size of /run via an entry in /etc/fstab is not sufficient
since journald calculates it limits before systemd remounts /run with
the small size. Therefore journald could occupy the full /run partition
with its logs.

Allow specifying the size of /run by adding a RUNSIZE configuration
variable and a ramsize= boot argument. Mounting /run must be done after
reading the configuration.

Closes: #862013
Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
---
 conf/initramfs.conf | 11 +++++++++++
 init                | 19 ++++++++++++++-----
 initramfs-tools.8   |  7 +++++++
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/conf/initramfs.conf b/conf/initramfs.conf
index f0f5071..da862bc 100644
--- a/conf/initramfs.conf
+++ b/conf/initramfs.conf
@@ -62,3 +62,14 @@ DEVICE=
 
 NFSROOT=auto
 
+#
+# RUNSIZE: ...
+#
+# The size of the /run mount point in bytes, and rounded up to entire pages.
+# This option accepts a suffix % to limit the instance to that percentage of
+# your physical RAM or a suffix k, m or g for Ki, Mi, Gi (binary kilo (kibi),
+# binary mega (mebi) and binary giga (gibi)).
+# Overridden by optional ramsize= bootarg
+#
+
+RUNSIZE=10%
diff --git a/init b/init
index 8a40b42..aa2fae6 100755
--- a/init
+++ b/init
@@ -33,8 +33,6 @@ export quiet
 mount -t devtmpfs -o nosuid,mode=0755 udev /dev
 mkdir /dev/pts
 mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
-mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
-mkdir -m 0755 /run/initramfs
 
 # Export the dpkg architecture
 export DPKG_ARCH=
@@ -101,6 +99,9 @@ for x in $(cat /proc/cmdline); do
 			;;
 		esac
 		;;
+	runsize=*)
+		RUNSIZE="${x#runsize=}"
+		;;
 	nfsroot=*)
 		NFSROOT="${x#nfsroot=}"
 		;;
@@ -147,9 +148,9 @@ for x in $(cat /proc/cmdline); do
 		debug=y
 		quiet=n
 		if [ -n "${netconsole}" ]; then
-			exec >/dev/kmsg 2>&1
+			log_output=/dev/kmsg
 		else
-			exec >/run/initramfs/initramfs.debug 2>&1
+			log_output=/run/initramfs/initramfs.debug
 		fi
 		set -x
 		;;
@@ -169,7 +170,7 @@ for x in $(cat /proc/cmdline); do
 		;;
 	netconsole=*)
 		netconsole=${x#netconsole=}
-		[ "x$debug" = "xy" ] && exec >/dev/kmsg 2>&1
+		[ "x$debug" = "xy" ] && log_output=/dev/kmsg
 		;;
 	BOOTIF=*)
 		BOOTIF=${x#BOOTIF=}
@@ -201,6 +202,14 @@ else
 	resume=${RESUME:-}
 fi
 
+mount -t tmpfs -o "noexec,nosuid,size=${RUNSIZE:-10%},mode=0755" tmpfs /run
+mkdir -m 0755 /run/initramfs
+
+if [ -n "$log_output" ]; then
+	exec >$log_output 2>&1
+	unset log_output
+fi
+
 maybe_break top
 
 # Don't do log messages here to avoid confusing graphical boots
diff --git a/initramfs-tools.8 b/initramfs-tools.8
index 0eee050..61a2fcb 100644
--- a/initramfs-tools.8
+++ b/initramfs-tools.8
@@ -88,6 +88,13 @@ mounts the rootfs read-only.
 \fB\fI rw
 mounts the rootfs read-write.
 
+.TP
+\fB\fI ramsize
+The size of the /run mount point in bytes, and rounded up to entire pages.
+This option accepts a suffix % to limit the instance to that percentage of
+your physical RAM or a suffix k, m or g for Ki, Mi, Gi (binary kilo (kibi),
+binary mega (mebi) and binary giga (gibi)). The default is 10%.
+
 .TP
 \fB\fI blacklist
 disables load of specific modules.
-- 
2.17.0


Reply to: