自己有台淘汰的笔记本,内存较小,安装了 centos 系统,在安装 grpc 的时候报错 oom,使用命令:
watch -n 2 free -m
查看发现内存耗尽了,于是参考文档配置了 swap 内存,未编译时状态:
[root ~]#free -m
total used free shared buff/cache available
Mem: 3685 426 2922 9 335 3022
Swap: 11967 0 11967
编译 grpc 后的状态
Every 2.0s: free -m Fri Jul 9 12:40:49 2021
total used free shared buff/cache available
Mem: 3685 3361 98 9 225 87
Swap: 11967 0 11967
从上面的图可以看到,内存基本上使用完了,但死活不使用 swap 里的内存,最后程序卡死,编译 grpc 一直卡在 50%,我把 vm.swappiness 值设置为 10 20 …… 100 最后结果一样。
grpc 最终卡在:
[ 49%] Building CXX object third_party/protobuf/CMakeFiles/libprotoc.dir/__/src/google/protobuf/compiler/plugin.cc.o
[ 49%] Building CXX object third_party/protobuf/CMakeFiles/libprotoc.dir/__/src/google/protobuf/compiler/plugin.pb.cc.o
[ 49%] Building CXX object third_party/protobuf/CMakeFiles/libprotoc.dir/__/src/google/protobuf/compiler/python/python_generator.cc.o
[ 50%] Built target bssl
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^Cmake[2]: *** [third_party/protobuf/CMakeFiles/libprotoc.dir/__/src/google/protobuf/compiler/code_generator.cc.o] 中断
make[2]: *** [third_party/abseil-cpp/absl/flags/CMakeFiles/absl_flags.dir/flag.cc.o] 中断
make[2]: *** [third_party/abseil-cpp/absl/status/CMakeFiles/absl_statusor.dir/statusor.cc.o] 中断
make[1]: *** [third_party/protobuf/CMakeFiles/libprotoc.dir/all] 中断
make: *** [all] 中断
^C
ctrl + c 后 swap 里反而有了使用内存:
Every 2.0s: free -m Fri Jul 9 12:44:15 2021
total used free shared buff/cache available
Mem: 3685 166 3450 1 68 3358
Swap: 11967 262 11705
gcc 和系统版本:
[root ~]#gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
[root ~]#uname -a
Linux MiWiFi-RA50-srv 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
跪求各位大佬帮忙分析下,如何才能让 swap 生效,从而可以完成编译 grpc,可以从哪些方面去分析呢?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.