From edd6936903652a6f16eaa5710e3312c686e977af Mon Sep 17 00:00:00 2001 From: Xiaoyi Date: Sat, 11 Jul 2026 15:41:46 +0800 Subject: [PATCH] core: store naked core on compressed rom instead of unpacking to tmpfs On OpenWrt $TMPDIR is tmpfs (RAM) and $BINDIR sits on a transparently-compressed fs (squashfs/ubifs). Unpacking the core to $TMPDIR pins the whole ~40MB binary in unreclaimable Shmem, and a compressed copy is still kept on rom - paying twice. When $TMPDIR is tmpfs and $BINDIR is squashfs/ubifs/overlay, store the verified naked binary as $BINDIR/CrashCore.raw and symlink $TMPDIR/CrashCore to it, dropping the downloaded archive. The binary is transparently compressed on rom (~2.2:1, comparable to keeping .gz) and its text/rodata become file-backed and reclaimable at runtime (RssShmem 0). Other filesystems keep the existing behavior. The upx branch's symlink target is also corrected from $TMPDIR to $BINDIR (same dangling-symlink issue as #1295). For #1304 --- scripts/libs/core_tools.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/libs/core_tools.sh b/scripts/libs/core_tools.sh index e2ed523b..bc553f8e 100644 --- a/scripts/libs/core_tools.sh +++ b/scripts/libs/core_tools.sh @@ -14,6 +14,8 @@ core_unzip() { #$1:需要解压的文件 $2:目标文件名 rm -rf "$TMPDIR"/core_tmp elif echo "$1" |grep -q '.gz$' ;then gunzip -c "$1" > "$TMPDIR"/"$2" + elif echo "$1" |grep -q '.raw$' ;then + ln -sf "$1" "$TMPDIR"/"$2" elif echo "$1" |grep -q '.upx$' ;then ln -sf "$1" "$TMPDIR"/"$2" else @@ -45,16 +47,27 @@ core_check(){ rm -rf "$1" "$TMPDIR"/core_new return 2 else - rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx - if [ -z "$zip_type" ];then + rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx "$BINDIR"/CrashCore.raw + #$TMPDIR为内存(tmpfs)且$BINDIR为透明压缩文件系统(squashfs/ubifs)时,直接以裸二进制存于$BINDIR并软链,省内存 + store_raw=0 + tmp_fs=$(df -T "$TMPDIR" 2>/dev/null | awk 'END{print $2}') + rom_fs=$(df -T "$BINDIR" 2>/dev/null | awk 'END{print $2}') + case "$tmp_fs" in tmpfs|ramfs) + case "$rom_fs" in squashfs|ubifs|overlay|overlayfs) store_raw=1 ;; esac ;; + esac + if [ "$zip_type" = 'upx' ];then + mv -f "$1" "$BINDIR/CrashCore.upx" + rm -f "$TMPDIR"/core_new + ln -sf "$BINDIR/CrashCore.upx" "$TMPDIR/CrashCore" + elif [ "$store_raw" = 1 ];then + rm -f "$1" + mv -f "$TMPDIR/core_new" "$BINDIR/CrashCore.raw" + ln -sf "$BINDIR/CrashCore.raw" "$TMPDIR/CrashCore" + elif [ -z "$zip_type" ];then gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz" + mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore" else mv -f "$1" "$BINDIR/CrashCore.$zip_type" - fi - if [ "$zip_type" = 'upx' ];then - rm -f "$1" "$TMPDIR"/core_new - ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore" - else mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore" fi core_v="$v"