gcc 或 javac 在第一次启动时很慢 [英] gcc or javac slow at first startup

查看:36
本文介绍了gcc 或 javac 在第一次启动时很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释为什么在 linux 中,当我在一段时间不活动后启动 gcc 或 javac 时,它们需要一段时间才能启动.后续调用要快得多.有没有办法确保始终快速启动?(这个要求可能看起来很奇怪,但在我的情况下是必要的).顺便说一下,Ubuntu.

Can anyone explain why in linux when I start gcc or javac after some time of inactivity it takes a while for them to start. Subsequent invocations are way faster. Is there a way to ensure quick startup always? (This requirement may seem strange, but is necessary in my case). Ubuntu by the way.

推荐答案

最有可能的是代码页出错所需的时间.如果确实需要,有几种方法可以避免这种延迟.最简单的方法是定期运行 gcc.另一种方法是将 gcc 安装到 RAM 磁盘.

Most likely, it's the time it takes for code pages to fault in. There are a few ways to avoid this delay if you really have to. The simplest would be to run gcc periodically. Another would be to install gcc to a RAM disk.

另一种方法是列出所涉及的文件,然后编写一个简单的程序将所有这些文件锁定到内存中.您可以使用以下内容:
strace -f gcc *rest of gcc command* 2>&1 |grep 打开 |grep -v -- -1
使用 GCC 命令行,这是您使用 GCC 的典型方式.

Another approach would be to make a list of which files are involved and then write a simple program to lock all those files into memory. You can use something like:
strace -f gcc *rest of gcc command* 2>&1 | grep open | grep -v -- -1
Use a GCC command line that's typical of how you are using GCC.

您会在其中找到正在打开的库和二进制文件.在文件中制作完整列表.然后编写一个调用 mlockall(MCL_FUTURE) 的程序,然后从文件中读取文件名.对于每个文件,mmap 将其放入内存并读取每个字节.然后让程序永远休眠(或直到被杀死).

You'll find libraries and binaries being opened in there. Make a full list in a file. Then write a program that calls mlockall(MCL_FUTURE) then reads in filenames from the file. For each file, mmap it into memory and read each byte. Then have the program just sleep forever (or until killed).

这将具有强制内存中每个文件的每个页面的效果.您应该检查所有这些文件的总大小,并确保它不是您实际拥有的内存量的重要部分!

This will have the effect of forcing every page of every file in memory. You should check the total size of all these files and make sure it's not a significant fraction of the amount of memory you actually have!

顺便说一下,曾经有一种叫做 sticky bit 的东西会做这样的事情.如果您的平台碰巧支持它,只需在所有使用的文件上设置它.(虽然传统上它会导致文件被保存以交换,但在现代系统上这不会使事情变得更快.)

By the way, there used to be something called a sticky bit that did something like this. If by some chance your platform supports it, just set it on all the files used. (Although it traditionally caused the files to be saved to swap, which on a modern system won't make things any faster.)

这篇关于gcc 或 javac 在第一次启动时很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆