base-files: tune fragment queue thresholds for available system memory
The default fragment low/high thresholds are 3 and 4 MB. On devices with only 32MB RAM, these settings may lead to OOM when many fragments that cannot be reassembled are received. Decrease fragment low/high thresholds to 384 and 512 kB on devices with less than 64 MB RAM. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
This commit is contained in:
		| @@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/kernel.mk | |||||||
| include $(INCLUDE_DIR)/version.mk | include $(INCLUDE_DIR)/version.mk | ||||||
|  |  | ||||||
| PKG_NAME:=base-files | PKG_NAME:=base-files | ||||||
| PKG_RELEASE:=173.4 | PKG_RELEASE:=173.5 | ||||||
| PKG_FLAGS:=nonshared | PKG_FLAGS:=nonshared | ||||||
|  |  | ||||||
| PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ | PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ | ||||||
|   | |||||||
| @@ -3,22 +3,33 @@ | |||||||
|  |  | ||||||
| START=11 | START=11 | ||||||
|  |  | ||||||
| set_vm_min_free() { | apply_defaults() { | ||||||
| 	mem="$(grep MemTotal /proc/meminfo  | awk '{print $2}')" | 	local mem="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)" | ||||||
|  | 	local min_free frag_low_thresh frag_high_thresh | ||||||
|  |  | ||||||
| 	if [ "$mem" -gt 65536 ]; then # 128M | 	if [ "$mem" -gt 65536 ]; then # 128M | ||||||
| 		val=16384 | 		min_free=16384 | ||||||
| 	elif [ "$mem" -gt 32768 ]; then # 64M | 	elif [ "$mem" -gt 32768 ]; then # 64M | ||||||
| 		val=8192 | 		min_free=8192 | ||||||
| 	elif [ "$mem" -gt 16384 ]; then # 32M |  | ||||||
| 		val=1024 |  | ||||||
| 	else | 	else | ||||||
| 		return | 		min_free=1024 | ||||||
|  | 		frag_low_thresh=393216 | ||||||
|  | 		frag_high_thresh=524288 | ||||||
| 	fi | 	fi | ||||||
| 	sysctl -qw vm.min_free_kbytes="$val" |  | ||||||
|  | 	sysctl -qw vm.min_free_kbytes="$min_free" | ||||||
|  |  | ||||||
|  | 	[ "$frag_low_thresh" ] && sysctl -qw \ | ||||||
|  | 		net.ipv4.ipfrag_low_thresh="$frag_low_thresh" \ | ||||||
|  | 		net.ipv4.ipfrag_high_thresh="$frag_high_thresh" \ | ||||||
|  | 		net.ipv6.ip6frag_low_thresh="$frag_low_thresh" \ | ||||||
|  | 		net.ipv6.ip6frag_high_thresh="$frag_high_thresh" \ | ||||||
|  | 		net.netfilter.nf_conntrack_frag6_low_thresh="$frag_low_thresh" \ | ||||||
|  | 		net.netfilter.nf_conntrack_frag6_high_thresh="$frag_high_thresh" | ||||||
| } | } | ||||||
|  |  | ||||||
| start() { | start() { | ||||||
| 	set_vm_min_free | 	apply_defaults | ||||||
| 	for CONF in /etc/sysctl.conf /etc/sysctl.d/*.conf; do | 	for CONF in /etc/sysctl.conf /etc/sysctl.d/*.conf; do | ||||||
| 		[ -f "$CONF" ] && sysctl -p "$CONF" -e >&- | 		[ -f "$CONF" ] && sysctl -p "$CONF" -e >&- | ||||||
| 	done | 	done | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matthias Schiffer
					Matthias Schiffer