Joel Rosdahl [Wed, 8 Mar 2023 07:10:27 +0000 (08:10 +0100)]
feat: Support overriding MSVC /Z* options
MSVC options /Zi and /ZI are too hard since they produce separate PDB
files. /Z7 is OK, but if the command line contains /Zi or /ZI followed
by /Z7, MSVC will use the latter (with a warning) but ccache will still
consider the command line too hard.
This commit makes ccache understand that only the last /Z* option will
be used and thus accepts the command line if the last /Z* option is /Z7.
Joel Rosdahl [Thu, 2 Mar 2023 17:14:49 +0000 (18:14 +0100)]
feat: Improve cache size presentation and specification
Aligned how cache size is presented (in "ccache --show-stats", "ccache
--show-compression", "ccache --recompress", debug logs, etc.) and
specified (in configuration files, "ccache --max-size" and "ccache
--trim-max-size"). The size units are now formatted according to the
type of size unit prefix used for the max_size/CCACHE_MAXSIZE setting: a
decimal size unit prefix (k/M/G/T with or without B for bytes) in
max_size means using decimal size unit prefix for presented sizes, and
similar for binary size unit prefixes (Ki/Mi/Gi/Ti with or without B for
bytes). If no unit is specified, GiB is assumed, . For example, "ccache -M
10" means 10 GiB.
Also aligned how cache sizes are calculated. Now all sizes are computed
as "apparent size", i.e., rounded up to the disk block size. This means
that the cache size in "--show-stats" and the sizes presented in
"--show-compression" and "--recompress" now match.
Joel Rosdahl [Wed, 8 Feb 2023 21:24:01 +0000 (22:24 +0100)]
fix: Log config and command line before finding compiler
If the compiler can't be found then ccache exits early and doesn't print
the config and command line to the log. This makes it harder to debug
problems with finding the compiler, like issue #1249.
Improve this by logging "safe things" before searching for the compiler.
Joel Rosdahl [Fri, 3 Feb 2023 12:11:57 +0000 (13:11 +0100)]
fix: Handle Unix-style paths as non-options to MSVC
For MSVC, ccache treats all arguments starting with a slash as an
option, which makes it fail to detect the source code file if it's
passed as a Unix-style absolute path.
Fix this by not treating an argument as an option if it's (a) an unknown
option, and (b) the argument exists as a file in the file system.
Joel Rosdahl [Mon, 30 Jan 2023 20:23:43 +0000 (21:23 +0100)]
build: Fix Zstd and Hiredis downloads for unstable GitHub archives
The content of the Zstd and Hiredis GitHub source achive URLs like
<https://github.com/$X/$Y/archive/$tag.tar.gz> apparently change from
time to time. Color me surprised. [1] says that this is intentional
(although, at the time of writing, reverted temporarily). Let's use
another URL for Zstd and not verify the checksum for Hiredis (since
there is no release source archive).
Joel Rosdahl [Sun, 29 Jan 2023 12:12:30 +0000 (13:12 +0100)]
fix: Cache path relativization in preprocessed output
After PR #1033 and [1], a stat call is made each time a note about an
include file is found in the preprocessed output. Such calls are very
performant on Linux (and therefore unnoticed until now), but apparently
costly on Windows.
Fix this by caching the calculation of relative paths in
process_preprocessed_file.
Joel Rosdahl [Mon, 23 Jan 2023 21:14:54 +0000 (22:14 +0100)]
fix: Disable inode cache if filesystem risks getting full soon
Some filesystems, for instance btrfs with compression enabled,
apparently make a posix_fallocate call succeed without actually
allocating the requested space for the file. This means that if the file
is mapped into memory, like done by the inode cache, the process can
crash when accessing the memory if the filesystem is full.
This commit implements a workaround: the inode cache is disabled if the
filesystem reports that it has less than 100 MiB free space. The free
space check is valid for one second before it is done again. This should
hopefully make crashes very rare in practice.
Joel Rosdahl [Fri, 27 Jan 2023 12:09:25 +0000 (13:09 +0100)]
feat: Allow forcing download of zstd and hiredis again
Before it was possible to force downloading of the Zstandard library
using "-D ZSTD_FROM_INTERNET=ON" and similar for Hiredis. That ability
was lost in 2c742c2c7ca9, so if you for some reason want to not use a
locally installed library you're out of luck.
Improve this by letting ZSTD_FROM_INTERNET and HIREDIS_FROM_INTERNET be
tristate variables:
ON: Always download
AUTO (default): Download if local installation not found
OFF: Never download
Joel Rosdahl [Thu, 5 Jan 2023 18:14:27 +0000 (19:14 +0100)]
feat: Improve automatic cache cleanup mechanism
The cache cleanup mechanism has worked essentially the same ever since
ccache was initially created in 2002:
- The total number and size of all files in one of the 16 subdirectories
(AKA level 1) are kept in the stats file in said subdirectory.
- On a cache miss, the new compilation result file is written (based on
the first digits of the hash) to a subdirectory of one of those 16
subdirectories, and the stats file is updated accordingly.
- Automatic cleanup is triggered if the size of the level 1 subdirectory
becomes larger than max_size / 16.
- ccache then lists all files in the subdirectory recursively, stats
them to check their size and mtime, sorts the file list on mtime and
deletes the 20% oldest files.
Some problems with the approach described above:
- (A) If several concurrent ccache invocations result in a cache miss
and write their results to the same subdirectory then all of them will
start cleaning up the same subdirectory simultaneously, doing
unnecessary work.
- (B) The ccache invocation that resulted in a cache miss will perform
cleanup and then exit, which means that an arbitrary ccache process
that happens to trigger cleanup will take a long time to finish.
- (C) Listing all files in a subdirectory of a large cache can be quite
slow.
- (D) stat-ing all files in a subdirectory of a large cache can be quite
slow.
- (E) Deleting many files can be quite slow.
- (F) Since a cleanup by default removes 20% of the files in a
subdirectory, the actual cache size will (once the cache limit is
reached) on average hover around 90% of the configured maximum size,
which can be confusing.
This commit solves or improves on all of the listed problems:
- Before starting automatic cleanup, a global "auto cleanup" lock is
acquired (non-blocking) so that at most one process is performing
cleanup at a time. This solves the potential "cache cleanup stampede"
described in (A).
- Automatic cleanup is now performed in just one of the 256 level 2
directories. This means that a single cleanup on average will be 16
times faster than before. This improves on (B), (C), (D) and (E) since
the cleanup made by a single compilation will not have to access a
large part of the cache. On the other hand, cleanups will be triggered
16 times more often, but the cleanup duty will be more evenly spread
out during a build.
- The total cache size is calculated and compared with the configured
maximum size before starting automatic cleanup. This, in combination
with performing cleanup on level 2, means that the actual cache size
will stay very close to the maximum size instead of about 90%. This
solves (F).
The limit_multiple configuration option has been removed since it is no
longer used.
Joel Rosdahl [Thu, 5 Jan 2023 10:07:06 +0000 (11:07 +0100)]
enhance: Make it possible for LockFile::try_acquire to break the lock
If a long-lived lock is stale and has no alive file,
LockFile::try_acquire will never succeed to acquire the lock. Fix this
by creating the alive file for all lock types and making
LockFile::try_acquire exit when lock activity is seen instead of
immediately after failing to acquire the lock.
Another advantage is that a stale lock can now always be broken right
away if the alive file exists.
Joel Rosdahl [Fri, 30 Dec 2022 20:49:23 +0000 (21:49 +0100)]
fix: Avoid sometimes too wide percent figure in --show-stats
If the nominator is 99999 and the denominator is 100000, the percent
function in Statistics.cpp would return "(100.00%)" instead of the
wanted "(100.0%)". Fix this by using the alternate format string if the
result string overflows its target size.
Joel Rosdahl [Tue, 29 Nov 2022 20:54:08 +0000 (21:54 +0100)]
feat: Do clean/clear/evict-style operations per level 2 directory
Progress bars will now be smoother since the operations are now divided
into 256 instead of 16 "read files + act on files" steps. This is also
in preparation for future improvements related to cache cleanup.
Oleg Sidorkin [Wed, 4 Jan 2023 13:53:21 +0000 (16:53 +0300)]
fix: Use spinlocks for inode cache memory synchronization (#1229)
Changed the inode cache implementation to use spinlocks instead of pthread
mutexes. This makes the inode cache work on FreeBSD and other systems where the
pthread mutexes are destroyed when the last memory mapping containing the
mutexes is unmapped.
Also added tmpfs, ufs and zfs to the list of supported filesystems on macOS and
BSDs.
Joel Rosdahl [Wed, 21 Dec 2022 12:16:12 +0000 (13:16 +0100)]
fix: Fix matching of base directory for MSVC
The base directory will now match case-insensitively with absolute paths
in preprocessed output, or from /showIncludes in the depend mode case,
when compiling with MSVC.
Joel Rosdahl [Mon, 5 Dec 2022 19:50:58 +0000 (20:50 +0100)]
enhance: Extract lock keep-alive thread to a manager class
Instead of running one keep-alive thread per lock, a long-lived LockFile
now lets a separate LongLivedLockFileManager object handle keep-alive
for several locks in a single thread.
Joel Rosdahl [Wed, 23 Nov 2022 19:11:12 +0000 (20:11 +0100)]
fix: Don't use copy of mutex/condition in long-lived lock thread
This was kind of due to a typo in 0babd33e84147e923a729ee07a3b85097ec8baa8. Since the LongLivedLockFile
class is not used yet, the bug does not affect any released code.
Joel Rosdahl [Thu, 10 Nov 2022 09:15:12 +0000 (10:15 +0100)]
enhance: Only keep atime if needed
- For the --recompress case, only reset timestamps if mtime has changed
since local cache LRU cleanup always uses mtime.
- For the --trim-dir/--trim-recompress case, always reset timestamps
since atime may be used for LRU cleanup.
Erik Flodin [Sun, 27 Nov 2022 20:32:36 +0000 (21:32 +0100)]
fix: Fix edge case where a non-temporal identifier is misidentified (#1227)
If a non-temporal identifier, that ends with a temporal macro, happens
to be at the end of the buffer with the temporal suffix starting on the
avx boundary, then it would be incorrectly classified as a temporal
macro. This since the helper function lacks the context to see that the
data before the match is something that invalidates the match.