base-files: increase vm.min_free_kbytes
authorFelix Fietkau <nbd@nbd.name>
Mon, 1 Aug 2016 12:52:13 +0000 (14:52 +0200)
committerFelix Fietkau <nbd@nbd.name>
Mon, 1 Aug 2016 12:53:27 +0000 (14:53 +0200)
Network drivers typically allocate memory in atomic context. For that to
be reliable, there needs to be enough free memory. Set the value
heuristically based on the total amount of system RAM.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/base-files/files/etc/init.d/sysctl

index 2dfbaf7a6e473d81575c2692fc0f8e0e3d3d9952..a0daec071e3afe77919120d74f1c8490e3569289 100755 (executable)
@@ -2,7 +2,23 @@
 # Copyright (C) 2006 OpenWrt.org
 
 START=11
+
+set_vm_min_free() {
+       mem="$(grep MemTotal /proc/meminfo  | awk '{print $2}')"
+       if [ "$mem" -gt 65536 ]; then # 128M
+               val=16384
+       elif [ "$mem" -gt 32768 ]; then # 64M
+               val=8192
+       elif [ "$mem" -gt 16384 ]; then # 32M
+               val=4096
+       else
+               return
+       fi
+       sysctl -qw vm.min_free_kbytes="$val"
+}
+
 start() {
+       set_vm_min_free
        for CONF in /etc/sysctl.conf /etc/sysctl.d/*.conf; do
                [ -f "$CONF" ] && sysctl -p "$CONF" -e >&-
        done