Re: ccache

From: Bakul Shah <bakul_at_iitbombay.org>
Date: Tue, 30 May 2023 21:48:03 UTC
On May 30, 2023, at 2:00 PM, Craig Leres <leres@freebsd.org> wrote:
> 
> On 4/3/23 18:48, Craig Leres wrote:
>> On 4/3/23 17:09, Bakul Shah wrote:
>>> Am I use ccache incorrectly or is there a bug?
>>> 
>>> # CCACHE_DIR=/usr/obj/ccache ccache -s
>>> cache directory                     /usr/obj/ccache
>>> primary config                      /usr/obj/ccache/ccache.conf
>>> secondary config      (readonly)    /usr/local/etc/ccache.conf
>>> stats updated                       Mon Apr  3 16:54:31 2023
>>> ...
>>> cleanups performed                   507
>>> files in cache                   2795230
>>> cache size                           2.9 GB <===
>>> max cache size                      15.0 GB
>>> # find /usr/obj/ccache -type f |wc
>>>   2795395 2795395 142222206
>>> # du -sh /usr/obj/ccache
>>>   83G    /usr/obj/ccache    <===
>>> 
>>> I have
>>> 
>>> WITH_CCACHE_BUILD=yes
>>> CCACHE_DIR=/usr/obj/ccache
>>> 
>>> in /etc/make.conf
>> Thank you for bringing this up; I have the same issue and have never figured it out. But I think I've found another piece or two of the puzzle.
>> Using my favorite ktrace trick we can see that by default it tries to open /usr/local/etc/ccache.conf:
>>     zinc 32 % cd /tmp && ktrace -di ccache -s > /dev/null
>>     zinc 33 % kdump | fgrep NAMI | fgrep ccache.conf
>>      17418 ccache   NAMI  "/usr/local/etc/ccache.conf"
>>   17418 ccache   NAMI  "/home/zinc/u0/leres/.ccache/ccache.conf"
>> I suspect the trick here is when ccache runs inside a poudriere jail, ccache.conf is not present and/or not in the right location.
>> On my build server I have /var/cache/ccache/ccache.conf which I believe works for some things but I still have 46 GB in /var/cache/ccache and /var/cache/ccache/ccache.conf is trying to limit use to 8 GB.
>> If I start up a poudriere jail and look around I find /root/.ccache/ccache.conf is a copy of /var/cache/ccache/ccache.conf. So I don't get why it doesn't work.
>> (Now I'll sit back and wait for something who knows more chimes in...)
> 
> Nobody stepped up and I haven't figured out how to make ccache obey max_size when run from inside the context of a poudriere jail but I do see now how to keep a lid on ccache disk usage.
> 
> I found that if I ran "ccache -c" as root, a .ccache directory would get created in /root. I could also see an attempt to open /usr/local/etc/ccache.conf so I created this with the following:
> 
>    cache_dir = /var/cache/ccache
>    max_size = 8.0G
> 
> I then added a cron job to run this command at midnight:
> 
>    /usr/local/bin/ccache -c | fgrep -v 'Cleaned cache'
> 
> As the saying goes, "crude, but effective."
> 

I have been using
	CCACHE_DIR=/usr/obj/ccache ccache -c
with /usr/obj/ccache/ccache.conf containing
	max_size = 15.0G

Not sure what is a good size.