📜 ⬆️ ⬇️

Prelink and Preload to speed up the launch of programs in Linux

In this post I will describe two utilities that will help speed up the work of the Linux system, specifically, the launch of applications: prelink and preload . Prelink optimizes executable files for quick linking to libraries. Preload caches frequently used libraries and programs.
Details under the cut.

Prelink


Most Linux applications use dynamically loaded libraries that contain various functions necessary for their work. Each time the application starts, these libraries should also be loaded. In the case of heavy applications with a large number of links, this process may take some time. At the same time, the actions performed for linking libraries are the same if the libraries themselves do not change. The prelink utility allows you to register links to libraries directly into the executable file, which will speed up the launch of the application. This is done without recompiling the application.
Install the prelink application using your distribution. The file /etc/prelink.conf contains a list of paths the files by which prelink will process. You probably don’t have to modify this list, the authors of your distribution did it for you. Run prelink -amfR (--all --conserve-memory --force --random) to prelink all applications. Description of options:
-a - All, apply prebinding to all executable files.
-m - Saves virtual memory space. This is required if you have many libraries that need to be linked.
-f - Forces the prelinking to repeat for files that have already been subjected to it. This is necessary because The prelink program stops processing existing old linked files whose dependent libraries may have changed.
-R - Random, selects a random address order, this increases security against buffer overflow attacks.
Note that it is necessary to run prelink after each update of libraries and / or applications. You can assign it to run on cron.

Preload


Preload is a daemon that collects information about frequently used programs and libraries and caches them in memory for quick launch. Accordingly, it is irrational to use it if you have little RAM. Settings are in the /etc/preload.conf file. Standard values ​​are likely to suit you, but I will give a description of the main options:
model.cycle - how often preload will receive information about the programs and libraries used from the system.
model.halflife - how often the preload will reset the old information.
model.minsize - the limit on the size of the program or library that preload will process.
In the /var/lib/preload/preload.state file /var/lib/preload/preload.state can see information about the preload operation.

Testing


With the help of the time utility, five measurements of the execution of the “php -v” command were made at intervals of a couple of seconds. First, five measurements without optimizations, then the prelink utility was launched, five measurements were carried out. Finally, the preload daemon was started, after the appearance of php in the preload cache, five measurements were performed again. The results are displayed on the graph (figures - milliseconds):
')


It should be noted that the performance gain on the desktop will be significantly greater, due to the "heavy" DE, which has a large number of related libraries.

Materials were used:
* www.gentoo.org/doc/en/prelink-howto.xml
* sourceforge.net/projects/preload

UPD: In this comment snakeye gives a more correct graph, where the Y axis starts at 0.
UPD2: In this comment wRAR corrects about the description of the option -f prelink.

Source: https://habr.com/ru/post/108454/


All Articles