You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决TinyCorePure64上GCC-15.1.0编译的OOM终止错误

编译GCC-15.1.0时OOM Killer终止进程的解决方法

问题背景

在以下环境编译GCC-15.1.0时,编译3小时后进程被系统终止:

  • 宿主机:宏碁Aspire轻薄本,AMD Ryzen 5 5625U,48GB DDR4-3200MHz内存,512GB NVMe M.2 SSD,Windows 11 Home 24H2(26100.4351)
  • 虚拟机:Oracle VirtualBox 7.1.10,运行TinyCorePure64 16.12.11

编译报错信息:

-o build/genautomata.o ../../gcc/genautomata.cc
/home/tc/gcc-15.1.0/build/./prev-gcc/xg++ -B/home/tc/gcc-15.1.0/build/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs  -I/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu  -I/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include  -I/home/tc/gcc-15.1.0/libstdc++-v3/libsupc++ -L/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/home/tc/gcc-15.1.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs   -g -O2 -fchecking=1 -DIN_GCC    -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-error=narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Wconditionally-supported -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings  -DHAVE_CONFIG_H  -DGENERATOR_FILE -static-libstdc++ -static-libgcc  -o build/genautomata \
    build/genautomata.o build/rtl.o build/read-rtl.o build/ggc-none.o build/vec.o build/min-insn-modes.o build/gensupport.o build/print-rtl.o build/hash-table.o build/sort.o build/read-md.o build/errors.o .././libiberty/libiberty.a -lm
build/genautomata ../../gcc/common.md ../../gcc/config/i386/i386.md \
  insn-conditions.md > tmp-automata.cc
make[3]: *** [Makefile:2796: s-automata] Killed
make[3]: Leaving directory '/home/tc/gcc-15.1.0/build/gcc'
make[2]: *** [Makefile:4816: all-stage3-gcc] Error 2
make[2]: Leaving directory '/home/tc/gcc-15.1.0/build'
make[1]: *** [Makefile:26902: stage3-bubble] Error 2
make[1]: Leaving directory '/home/tc/gcc-15.1.0/build'
make: *** [Makefile:1103: all] Error 2

执行dmesg | grep -i kill得到的OOM日志:

tc@box:~/gcc-15.1.0/build$ dmesg | grep -i kill
[32614.157379] cc1plus invoked oom-killer: gfp_mask=0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO), order=0, oom_score_adj=0
[32614.157902] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,task=Isolated Web Co,pid=27981,uid=1001
[32614.158169] Out of memory: Killed process 27981 (Isolated Web Co) total-vm:2623812kB, anon-rss:94200kB, file-rss:116kB, shmem-rss:5876kB, UID:1001 pgtables:1268kB oom_score_adj:167
[32915.236284] genautomata invoked oom-killer: gfp_mask=0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO), order=0, oom_score_adj=0
[32915.236847] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,task=Privileged Cont,pid=27850,uid=1001
[32915.237222] Out of memory: Killed process 27850 (Privileged Cont) total-vm:2514636kB, anon-rss:44992kB, file-rss:0kB, shmem-rss:7600kB, UID:1001 pgtables:924kB oom_score_adj:167
[32918.136766] genautomata invoked oom-killer: gfp_mask=0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO), order=0, oom_score_adj=0
[32918.137165] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,task=genautomata,pid=9113,uid=1001
[32918.137177] Out of memory: Killed process 9113 (genautomata) total-vm:1479416kB, anon-rss:1476092kB, file-rss:0kB, shmem-rss:1900kB, UID:1001 pgtables:2936kB oom_score_adj:0

解决方法

1. 增加虚拟机内存分配

宿主机有48GB内存,但当前虚拟机内存不足以支撑GCC编译的峰值内存需求。操作步骤:

  • 停止TinyCore虚拟机
  • 打开VirtualBox设置,进入「系统」->「主板」选项
  • 将内存分配调高至至少8GB(建议16GB,留足系统和编译进程的空间)
  • 重启虚拟机后重新执行编译

2. 减少并行编译线程数

GCC默认使用与CPU核心数相同的线程数编译,过多线程会加剧内存占用。编译时手动指定线程数:

make -j4

(根据虚拟机分配的CPU核心数调整,比如分配6核可使用-j4或-j5,避免满负载占用内存)

3. 启用临时交换分区

如果暂时无法增加虚拟机内存,可在TinyCore中创建临时交换分区缓解内存压力:

# 创建16GB交换文件(可根据需求调整大小)
dd if=/dev/zero of=/swapfile bs=1G count=16
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

编译完成后可关闭并删除交换文件:

swapoff /swapfile
rm /swapfile

4. 调整GCC编译选项

关闭编译时的高内存开销调试选项,比如-fchecking=1:

  • 在configure阶段添加--disable-checking参数
  • 或直接修改Makefile中的编译flags,移除-fchecking=1
    该选项会增加编译时的内存占用,关闭后可有效降低内存使用峰值。

内容的提问来源于stack exchange,提问作者Chi Kun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 18:14:50