[lxc-devel] [lxd/master] Tweak squashfs for low-memory systems

stgraber on Github lxc-bot at linuxcontainers.org
Thu Sep 15 20:03:01 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 494 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160915/584e5059/attachment.bin>
-------------- next part --------------
From 5306765c7fe2a4f46ab0019b05a16892fc7e25cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 15 Sep 2016 16:01:57 -0400
Subject: [PATCH] Tweak squashfs for low-memory systems
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On low-memory systems (below 2GB of RAM), limit unsquashfs to a single
CPU and to 10% of the RAM for its fragment size.

Closes #2382

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/images.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lxd/images.go b/lxd/images.go
index 842a923..70b33e6 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -99,6 +99,13 @@ func unpack(file string, path string) error {
 	} else if strings.HasPrefix(extension, ".squashfs") {
 		command = "unsquashfs"
 		args = append(args, "-f", "-d", path, "-n")
+
+		mem, err := deviceTotalMemory()
+		mem = mem / 1024 / 1024 / 10
+		if err == nil && mem < 256 {
+			args = append(args, "-da", fmt.Sprintf("%d", mem), "-fr", fmt.Sprintf("%d", mem), "-p", "1")
+		}
+
 		args = append(args, file)
 	} else {
 		return fmt.Errorf("Unsupported image format: %s", extension)


More information about the lxc-devel mailing list