core: 按环境权衡 rom/RAM 取舍决定内核存储形态#1305
Merged
Merged
Conversation
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 juewuy#1295). For juewuy#1304
Adds store_on_rom() helper (tmpfs $TMPDIR + squashfs/ubifs/overlay $BINDIR). On such devices core_webget no longer downloads the upx core (its stub decompresses into a memfd = RAM at runtime); it fetches the tar.gz instead and core_check stores the naked binary as $BINDIR/CrashCore.raw, symlinked from $TMPDIR. The binary is transparently compressed on rom and file-backed/reclaimable at runtime (RssShmem 0). Other filesystems and explicit upx keep prior behavior. Also corrects the upx branch symlink target $TMPDIR -> $BINDIR (same dangling-symlink issue as juewuy#1295). For juewuy#1304
Replaces the binary compressed-rom check with store_raw_worth_it(), which decides per environment: store the naked binary on $BINDIR (0 RAM) only when $TMPDIR is tmpfs AND $BINDIR can hold it with margin (estimated ~2:1 on squashfs/ubifs, full size otherwise). Otherwise keep a compressed copy and decompress to tmp as before. core_webget skips the upx core when raw storage is viable, fetching tar.gz instead. Rationale (rough budgets for a ~40M core): raw on squashfs ~15M rom / 0 RAM; gz 10M rom / ~40M RAM; upx 9M rom / ~40M RAM (memfd). Raw wins when rom has room; compressed wins when rom is the scarce resource. Also corrects the upx branch symlink target $TMPDIR -> $BINDIR (juewuy#1295). For juewuy#1304
Contributor
Author
|
请问下个 dev 版本大概什么时候发布? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #1304
问题
内核存哪种形态、放哪里,现在只看压缩包大小,没按设备环境权衡 rom 与 RAM 的取舍。以约 40M 的核心为例,几种形态的大致成本:
OpenWrt 上
$TMPDIR是 tmpfs(RAM),rom 多为 squashfs/ubifs(透明压缩)。此时 upx 反而最费 RAM(stub 在 exec 时memfd_create把整个程序解压回内存),而 upx 却被当作小设备的首选格式(general_init.sh里非 upx 才需把/tmp撑到 45M)。512MB 的 ipq60xx 上MemAvailable因此只剩约 40M。改动
按环境计算偏好,而非写死某种格式。新增
store_raw_worth_it():当$TMPDIR在内存(tmpfs)且$BINDIR能容纳裸二进制(按 fs 估算落盘体积——压缩 fs 约 2:1,否则全量——并预留余量)时,才把裸二进制存于 rom。$BINDIR/CrashCore.raw、$TMPDIR/CrashCore软链、丢压缩包。rom 上被透明压缩,运行时 file-backed 可回收(RssShmem归零)。压缩 fs 上裸二进制约 15M,几乎总是划算;非压缩 fs 上仅当 rom 有余量才选。core_webget也据此在裸存可行时跳过 upx 核心、改取 tar.gz(拿到裸二进制)。.raw只是落盘形态不是下载格式;core_find的CrashCore.*glob 配合core_unzip新增的.raw分支在启动时重建软链。用户显式指定的 upx / 自定义链接维持原行为。顺带修正 upx 分支软链目标$TMPDIR→$BINDIR(与 #1295 同一处悬空 bug)。效果(ipq60xx, ImmortalWrt 25.12)
验证
在真实 fs(
$BINDIR于 overlay/ubifs、$TMPDIR于 tmpfs)上跑通:store_raw_worth_it成立(实测 20.1 余量 12M、10.1 余量 31M,均 > 8M)→ 存CrashCore.raw、软链、可执行。CrashCore.gz、解压到 tmp。zip_type=upx+ 裸存可行:默认核心下载被覆盖为 tar.gz → 存 raw。.upx为裸二进制:软链到 rom、运行时RssShmem=0。core_find重建软链指向$BINDIR。fs 估算比例(2:1)与余量阈值(8M)为保守默认,可调。