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

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

问题描述

任何人都可以解释为什么在linux启动gcc或javac一段时间后处于非活动状态,他们需要一段时间才能启动。随后的调用速度更快。有没有办法确保始终快速启动? (这个要求可能看起来很奇怪,但在我的情况下是必要的)。 Ubuntu顺便说一句。

解决方案

最有可能的情况是代码页出错的时间。避免这种延迟,如果你真的必须。最简单的方法是定期运行 gcc 。另一种方法是将 gcc 安装到RAM磁盘中。

另外一种方法是制作一个文件列表参与其中,然后编写一个简单的程序将所有这些文件锁定到内存中。你可以使用类似于:
strace -f gcc * gcc命令的其余部分* 2>& 1 | grep打开| grep -v - -1

使用GCC命令行,这是您使用GCC的典型代码。



你会发现在那里打开库和二进制文件。在文件中制作完整列表。然后编写一个程序调用 mlockall(MCL_FUTURE)然后从文件读入文件名。对于每个文件, mmap 它到内存中并读取每个字节。然后让程序永久睡眠(或直到死亡)。



这会影响内存中每个文件的每个页面。你应该检查所有这些文件的总大小,并确保它不是你实际拥有的内存量的重要部分!



顺便说一下,曾经有过这就是所谓的 sticky bit 。如果您的平台支持它,只需在所有使用的文件上进行设置即可。 (虽然它传统上会导致文件被保存为交换,但在现代系统上这不会让事情变得更快)。


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.

解决方案

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.

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.

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!

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天全站免登陆