LD_BIND_NOW可以使可执行的运行速度变慢吗? [英] LD_BIND_NOW Can Make the Executable run Slower?

查看:648
本文介绍了LD_BIND_NOW可以使可执行的运行速度变慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇一个可执行文件写得不好,它有很多死代码,在外部引用了数千个函数(即.so文件),但是在运行时实际上只调用了其中的100个函数,LD_BIND_NOW = 1会比LD_BIND_NOW未设置?因为过程链接表将包含900个无用的函数地址?在内存占用和性能方面更糟糕(因为我不知道查找是否为O(n))。

I am curious if an executable is poorly written that it has much dead code, referring to 1000s of functions externally (i.e. .so files) but only 100s of those functions are actually called during runtime, will LD_BIND_NOW=1 be worse than LD_BIND_NOW not set? Because the Procedure Linkage Table will contain 900 useless function addresses? Worse in a sense of memory footprint and performance (as I don't know whether the lookup is O(n)).

我试图查看是否将LD_BIND_NOW设置为1会有所帮助(通过与未设置LD_BIND_NOW进行比较):

1.就延迟而言运行24 x 5的程序

2.节省1微秒被认为是我的情况是,在程序生存期内执行的代码路径主要是处理来自TCP / UDP /共享内存的传入消息,然后对它们进行一些计算。
所有这些代码路径都需要很短的时间(例如<10 micro),并且这些代码路径将像数百万次一样运行

I am trying to see whether setting LD_BIND_NOW to 1 will help (by comparing to LD_BIND_NOW not set):
1. a program that runs 24 x 5 in terms of latency
2. saving 1 microsecond is considered big in my case as the code paths being executed during the life time of the program are mainly processing incoming messages from TCP/UDP/shared memory and then doing some computations on them; all these code paths take very short time (e.g. < 10 micro) and these code paths will be run like millions of times

是否LD_BIND_NOW = 1帮助启动时间对我来说无关紧要。

Whether LD_BIND_NOW=1 helps the startup time doesn't matter to me.

推荐答案


节省1微秒是在我看来,由于程序的执行时间都很短(例如< 10 micro)

saving 1 microsecond is considered big in my case as the executions by the program are all short (e.g. <10 micro)

意思是别的)。对 execve(2)的典型调用-系统调用用于启动程序-通常持续几毫秒。因此,程序执行的情况很少(几乎是不可能的)(从 execve _exit(2) ),以微秒为单位。

This is unlikely (or you mean something else). A typical call to execve(2) -the system call used to start programs- is usually lasting several milliseconds. So it is rare (and practically impossible) that a program executes (from execve to _exit(2)) in microseconds.

我建议您的程序每秒启动的次数不应超过几次。如果确实整个程序寿命很短(那么它的进程仅持续一小部分)一秒钟),您可以考虑采用其他方法(也许使服务器运行这些功能)。

I suggest that your program should not be started more than a few times per second. If indeed the entire program is very short lived (so its process lasts only a fraction of a second), you could consider some other approach (perhaps making a server running those functions).

LD_BIND_NOW 将影响(并减慢)启动时间(例如,在动态链接器 ld-linux(8))。 (除高速缓存影响外)某些事件循环的稳态执行时间并不重要。

LD_BIND_NOW will affect (and slow down) the start-up time (e.g. in the dynamic linker ld-linux(8)). It should not matter (except for cache effects) the steady state execution time of some event loop.

另请参见此相关答案(对于不同的问题),其中包含与您的问题相关的详细说明。

See also references in this related answer (to a different question), they contain detailed explanations relevant to your question.

简而言之, LD_BIND_NOW 不会严重影响处理紧密事件循环中每个传入消息所需的时间。

In short, the setting of LD_BIND_NOW will not affect significantly the time needed to handle each incoming message in a tight event loop.

共享库中的调用函数(包含在某些情况下,与位置无关的代码)可能会稍慢一些(最多可降低几个百分点,而在x86-64上可能会更低)。您可以尝试静态链接,甚至可以考虑链接时间优化(即,使用 -flto -O2 并链接所有代码-主程序和静态库- c $ c>(如果使用 GCC )。

Calling functions in shared libraries (containing position-independent code) might be slightly slower (by a few percents at most, and probably less on x86-64) in some cases. You could try static linking, and you might consider even link time optimization (i.e. compiling and linking all your code -main programs and static libraries- with -flto -O2 if using GCC).

您可能已经积累了技术债务,并且您可能需要大量的代码重构(这需要花费很多时间和精力,因此您应该预算一下)。

You might have accumulated technical debt, and you could need major code refactoring (which takes a lot of time and effort, that you should budget).

这篇关于LD_BIND_NOW可以使可执行的运行速度变慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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