简体   繁体   English

减少gcc内存使用量

[英]Reduce gcc memory usage

Currently I have to build a quite large project on a very limited hardware (a core i5 which have only 2gb RAM). 目前,我必须在非常有限的硬件上构建一个相当大的项目(核心i5只有2GB RAM)。 When run make with 4 thread gcc crashed due to each thread eats up to 40% RAM. 当运行make 4线程gcc崩溃时,由于每个线程占用高达40%的RAM。 I googled a bit and found this link . 我google了一下,找到了这个链接 A few people feedback it works.However, not me. 一些人反馈它有效。但是,不是我。

Here is how I did. 我就是这样做的。

/usr/bin/qmake-qt4 -r -spec linux-g++ $DEBUG_FLAGS -o Makefile "QMAKE_CXXFLAGS +=  --param ggc-min-expand=10 --param ggc-min-heapsize=8192"  /home/build-srv/LargeProject/largeProject.pro

make output does have the flag: make输出确实有标志:

g++ -c -pipe --param ggc-min-expand=10 --param ggc-min-heapsize=8192 -std=c++11 -std=c++11 -g -Wall -W -D_REENTRANT -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -DBASE_LIBRARY -DQT_DECLARATIVE_DEBUG -DQT_DECLARATIVE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++  -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtDeclarative...

But the ram usage still the same. 但是ram的使用情况仍然相同。 The only way is reduce to single thread build, which is awfully slow. 唯一的方法是减少单线程构建,这非常慢。

What did I do wrong? 我做错了什么? Are there any better solution for this. 有没有更好的解决方案。

Update : 更新

  • Yes, the hardware department "upgrade" the RAM capacity to 4GB and now it's responsive when building the project.(Actually a stick broke so they need to wait the replacement). 是的,硬件部门将RAM容量“升级”到4GB,现在它在构建项目时响应。(实际上一根棍子坏了,所以他们需要等待更换)。 But I'm curious that in a limited resource system like a VPS how can we handle that? 但我很好奇,在像VPS这样的有限资源系统中我们如何处理? (Except reduce the build threads?) (除了减少构建线程?)
  • I will search for the file that eat up a alot of RAM when compiling/linking. 我会在编译/链接时搜索占用大量RAM的文件。 I dont remember the name due to that ain't my modules. 我不记得名字,因为那不是我的模块。
  • The build server had 2GB of swap space. 构建服务器有2GB的交换空间。

Tell your employer that the tools they provide for your job are inadequate. 告诉您的雇主他们为您的工作提供的工具是不充分的。 That's a bit of a joke of a system for what you're doing, and I assume it's provided by the employer. 对于你正在做的事情,这是一个系统的笑话,我认为它是由雇主提供的。 You need more RAM, no doubt about it. 你需要更多的RAM,毫无疑问。 It should be simple enough to extend the RAM, there are no i5 motherboards that only take 2G as a maximum. 它应该足够简单,以扩展RAM,没有i5主板只有2G作为最大。

Otherwise - yes, you will need to limit the number of threads, eg use make -j2 or even make -j1. 否则 - 是的,你需要限制线程数,例如使用make -j2甚至make -j1. Modern compilers need lots of RAM not because they are wasteful, but because they hold the entire translation unit's worth of information in memory at once to provide global optimizations. 现代编译器需要大量RAM而不是因为它们浪费,而是因为它们一次性将整个翻译单元的信息保存在内存中以提供全局优化。 Link-time code generation will need even more memory as it holds the information about the entire application. 链接时代码生成需要更多内存,因为它包含有关整个应用程序的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM