Поиск:  
Администрирование Linux

Ccache в Gentoo Linux

Статья добавлена: 2006-07-12

Что такое ccache? ccache - это быстрый кэш компилятора. Временные файлы, которые будут созданы во время компиляции программы будут закэшированы, в результате чего во время обновления установленного программного обеспечения, время , затраченное на компиляцию программного значительно cокращается. Компиляция программ из исходных текстов часто занимает очень много времени, особенно на слабых машинах. Если Вы имеете несколько компьютеров объединенных в сеть, то тогда этот процесc можно ускорить. В этой статье представлен способ значительного ускорения компиляции программ, средствами ccache и distcc.

ccache использует опцию GCC -E  и хэш для определения можно ли взять результат компиляции из кэша. Эффект от использования заключается в ускорении компиляции часто компилируемого кода в 5-10 раз.

Установка

  1. Убедитесь что используемая версия portage больше чем 2.0.46-r11: emerge --version
  2. Установите ccache: emerge -av dev-util/ccache

Расположение файлов

При установке ccache как root, создаются такие файлы и папки:

  • /usr/lib/ccache - дом для файлов откуда portage будет запускаться вместо обычных компиляторов
  • /usr/bin/ccache - запускаемые файлы ccache
  • /root/.ccache - харнилище cache

Когда ccache устанавливается для пользователей, дополнительно создаётся ещё одна папка:

  • /var/tmp/ccache - хранилище cache

Solid information on this structure has proven difficult to come by and anyone who can provide an authorative answer should edit this page to do so.

However it seems that /var/tmp/ccache is unique to Gentoo, and should be chosen over /root/.ccache to store the cache.


Configuration

Note: The instructions in ccache's man page to create symlinks in the ccache directory are not applicable to gentoo users. This might be a unique feature of portage, or it may well be the case that the instruction is obsolete. Whichever is the case, you will find these links already created in: /usr/lib/ccache/bin


Code: /bin/bash
$ ls -l /usr/lib/ccache/bin
...
lrwxrwxrwx 1 root portage 15 Mar 6 i686-pc-linux-gnu-c++ -> /usr/bin/ccache
lrwxrwxrwx 1 root portage 15 Mar 6 i686-pc-linux-gnu-g++ -> /usr/bin/ccache
lrwxrwxrwx 1 root portage 15 Mar 6 i686-pc-linux-gnu-gcc -> /usr/bin/ccache
...

The 3 files are links, all of them pointing to: /usr/bin/ccache

When portage seeks to compile a package, it of course looks for the relevant compiler. However we don't want portage to go direct to the compiler, rather we want the compiler accessed through ccache. Thus we have a number of symlinks in the ccache directory which bear names that correspond to the various c and c++ compilers that portage looks for. With ccache enabled, Portage follows the path to /usr/lib/ccache/bin, and thus one of these files is invoked instead of one of the actual compilers. As you will see from the box above, all of these files are merely links to the ccache executable, (/usr/bin/ccache), which itself will call the genuine compilers.


Configuration takes place within /etc/make.conf

File: /etc/make.conf
...
FEATURES="ccache"
CCACHE_DIR="/var/tmp/ccache/"
CCACHE_SIZE="2G"
...
  1. Most importantly we need /etc/make.conf to inform portage to look for and use ccache. This is achieved by the first of the three lines above. If you already have some features set, naturally just add "ccache" to the list.
    • If you also use DistCC, be sure you add the "ccache" option first and "distcc" second in your features list to take full advantage of both.
  2. The CCACHE_DIR environment variable specifies where ccache will keep its cached compiler output.
  3. The 3rd line sets the maximum space that is allocated to caching compilations. At the time of writing the default maximum size is 976.6M. If you can afford the space you may well want to allow for more as in the example.
    • The ccache stats won't update to show your chosen CACHE_SIZE until after the emerge that follows your change in specification.
    • You can also set the cache size by employing the -M option described on ccache's man page. However, if you have a CCACHE_SIZE value set in /etc/make.conf, it will overwite previously set values from as soon as you next emerge.

Execution

Now, for the purpose of testing, emerge something small...

To ensure that ccache was running, pull up the ccache stats afterwards with: ccache -s

If you're using the CCACHE_DIR in /var/tmp/ccache you need to add that variable to the command string as shown below.


Code: /bin/bash
CCACHE_DIR="/var/tmp/ccache" ccache -s
/* The output will look something like this if it's working */
cache hit 189
cache miss 1983
called for link 159
multiple source files 4
compile failed 52
preprocessor error 4
bad compiler arguments 3
not a C/C++ file 141
autoconf compile/link 357
unsupported compiler option 30
no input file 145
files in cache 3966
cache size 30.1 Mbytes
max cache size 2.0 Gbytes

If no space shows as used, your cache directory is still empty and it might be the case that ccache (when run direct rather than by Portage) is looking for the cache store in the wrong place. You can overcome this by declaring the location of the cache store system-wide. Update your profile to include the second line that we added to /etc/make.conf as follows:

Code: /bin/bash
 echo "CCACHE_DIR=\"/var/tmp/ccache\"" >> /etc/env.d/99local 
env-update && source /etc/profile

Troubleshooting


ccache and Genkernel

Genkernel doesn't use ccache by default, even when you've enabled it for root. You can easily fix this by appending the --kernel_cc option to your genkernel call:


Code: /bin/bash
$ genkernel --kernel-cc=/usr/lib/ccache/bin/gcc --menuconfig all

A better way then this is to add a file to /etc/env.d called 02ccache with the following contents: PATH="/usr/lib/ccache/bin"

then run env-update, that way everything (including genkernel) will use the local ccache. If you want root to see the settings too, add ROOTPATH="/usr/lib/ccache/bin" to 02ccache as well.


ccache adjusts directory permissions

Apparently ccache will sometimes try to set the permissions of the ccache_dir after and before each emerge. Type this to fix that:


Code: /bin/bash
# chmod g+X -R /usr/lib/ccache



 Дополнительную информацию по ccache Вы можете найти на http://ccache.samba.org

Источник: http://gentoo-wiki.com/TIP_Use_ccache




[tags]

Связи:



Комментарии пользователей

Перейти в форум ...


Логин: Anonymous [Авторизоваться]
Текст сообщения
 
Интернет-магазин Альбомчик.Ру - Свадебные, детские, VIP Фотоальбомы







Интернет-магазин: Фильтры для воды Аквафор – Кристалл, Фаворит, WaterBoss, WaterMax, Модули

        HOTSUPPORT
        Техническая поддержка
Разработка и поддержка сайта - HotSupport.Ru
Контакты | О проекте        
        RSS лента
Rambler's Top100 Системы прослушивания. Многоканальная запись. Прослушивание телефонов.