If configured/activated in kernel-config,
main menu ->
device drivers ->
Staging drivers ->
"Compressed RAM block device support"
we activate a small (4 megabytes) partition in RAM,
which then acts as a normal swap-partition:
http://lwn.net/Articles/388889/
Systems with 16 megabytes RAM (or lower) are then
useable again, which is really a pity at the moment,
e.g. we cannot use 'opkg list | grep foo' at time of
writing on these devices without triggering the oom-killer.
Next step will be a uci-configureable disksize.
Signed-off-by: Bastian Bittorf <bitt...@bluebottle.com>
From 13e57cab265c76aa30d56b535bdcb860f46a0dfe Mon Sep 17 00:00:00 2001
From: Bastian Bittorf <bitt...@bluebottle.com>
Date: Tue, 22 Nov 2011 16:13:04 +0100
Subject: [PATCH] activate zram-swap during early boot/preinit if possible (defaulting to 4 megabyte swap-partition)
---
.../base-files/files/lib/preinit/10_essential_fs | 22 +++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/package/base-files/files/lib/preinit/10_essential_fs b/package/base-files/files/lib/preinit/10_essential_fs
index ab317dc..629b6b9 100644
--- a/package/base-files/files/lib/preinit/10_essential_fs
+++ b/package/base-files/files/lib/preinit/10_essential_fs
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
+# Copyright (C) 2011 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
do_mount_procfs() {
@@ -19,7 +19,27 @@ do_mount_tmpfs() {
mount tmpfs /tmp -t tmpfs -o size=$pi_size,nosuid,nodev,mode=1777
}
+zram_swap_possible() {
+ local zram_device="/dev/zram0"
+
+ [ -e "$zram_device" ] || return 1
+ [ -e "/sbin/mkswap" ] || return 1
+ [ -e "/sbin/swapon" ] || return 1
+}
+
+do_activate_zram_swap() {
+ local zram_size="${1:-4}" # megabytes
+ local zram_size_in_bytes="$(( $zram_size * 1024 * 1024 ))"
+ local zram_device="/dev/zram0"
+ local zram_path="/sys/block/$( basename $zram_device )/disksize"
+
+ echo "$zram_size_in_bytes" > "$zram_path"
+ /sbin/mkswap $zram_device
+ /sbin/swapon $zram_device
+}
+
boot_hook_add preinit_essential do_mount_procfs
boot_hook_add preinit_essential do_mount_sysfs
boot_hook_add preinit_essential do_mount_tmpfs
+zram_swap_possible && boot_hook_add preinit_essential do_activate_zram_swap
--
1.7.0.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel