// Clean up one cache subdirectory.
void
-clean_up_dir(struct conf *conf, const char *dir)
+clean_up_dir(struct conf *conf, const char *dir, float limit_multiple)
{
cc_log("Cleaning up cache directory %s", dir);
// When "max files" or "max cache size" is reached, one of the 16 cache
// subdirectories is cleaned up. When doing so, files are deleted (in LRU
// order) until the levels are below limit_multiple.
- cache_size_threshold = conf->max_size * conf->limit_multiple / 16;
- files_in_cache_threshold = conf->max_files * conf->limit_multiple / 16;
+ cache_size_threshold = conf->max_size * limit_multiple / 16;
+ files_in_cache_threshold = conf->max_files * limit_multiple / 16;
num_files = 0;
cache_size = 0;
{
for (int i = 0; i <= 0xF; i++) {
char *dname = format("%s/%1x", conf->cache_dir, i);
- clean_up_dir(conf, dname);
+ clean_up_dir(conf, dname, 1.0);
free(dname);
}
}
prepare_cleanup_test_dir $CCACHE_DIR/a
- # (9/10) * 30 * 16 = 432
- $CCACHE -F 432 -M 0 >/dev/null
+ # No cleanup needed.
+ #
+ # 30 * 16 = 480
+ $CCACHE -F 480 -M 0 >/dev/null
+ $CCACHE -c >/dev/null
+ expect_file_count 10 '*.o' $CCACHE_DIR
+ expect_file_count 10 '*.d' $CCACHE_DIR
+ expect_file_count 10 '*.stderr' $CCACHE_DIR
+ expect_stat 'files in cache' 30
+ expect_stat 'cleanups performed' 0
+
+ # Reduce file limit
+ #
+ # 21 * 16 = 336
+ $CCACHE -F 336 -M 0 >/dev/null
$CCACHE -c >/dev/null
- # floor(0.8 * 9) = 7
expect_file_count 7 '*.o' $CCACHE_DIR
expect_file_count 7 '*.d' $CCACHE_DIR
expect_file_count 7 '*.stderr' $CCACHE_DIR
prepare_cleanup_test_dir $CCACHE_DIR/a
- # (4/10) * 10 * 4 * 16 = 256
$CCACHE -F 0 -M 256K >/dev/null
- $CCACHE -c >/dev/null
- # floor(0.8 * 4) = 3
+ CCACHE_LOGFILE=/tmp/foo $CCACHE -c >/dev/null
expect_file_count 3 '*.o' $CCACHE_DIR
expect_file_count 3 '*.d' $CCACHE_DIR
expect_file_count 3 '*.stderr' $CCACHE_DIR
done
# -------------------------------------------------------------------------
- TEST "Automatic cache cleanup"
+ TEST "Automatic cache cleanup, limit_multiple 0.9"
for x in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
prepare_cleanup_test_dir $CCACHE_DIR/$x
done
- # (9/10) * 30 * 16 = 432
- $CCACHE -F 432 -M 0 >/dev/null
+ $CCACHE -F 480 -M 0 >/dev/null
+
expect_file_count 160 '*.o' $CCACHE_DIR
expect_file_count 160 '*.d' $CCACHE_DIR
expect_file_count 160 '*.stderr' $CCACHE_DIR
expect_stat 'files in cache' 480
+ expect_stat 'cleanups performed' 0
touch empty.c
- $CCACHE_COMPILE -c empty.c -o empty.o
- # floor(0.8 * 9) = 7
+ CCACHE_LIMIT_MULTIPLE=0.9 $CCACHE_COMPILE -c empty.c -o empty.o
+ expect_file_count 159 '*.o' $CCACHE_DIR
+ expect_file_count 158 '*.d' $CCACHE_DIR
+ expect_file_count 158 '*.stderr' $CCACHE_DIR
+ expect_stat 'files in cache' 475
+ expect_stat 'cleanups performed' 1
+
+ # -------------------------------------------------------------------------
+ TEST "Automatic cache cleanup, limit_multiple 0.7"
+
+ for x in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
+ prepare_cleanup_test_dir $CCACHE_DIR/$x
+ done
+
+ $CCACHE -F 480 -M 0 >/dev/null
+
+ expect_file_count 160 '*.o' $CCACHE_DIR
+ expect_file_count 160 '*.d' $CCACHE_DIR
+ expect_file_count 160 '*.stderr' $CCACHE_DIR
+ expect_stat 'files in cache' 480
+ expect_stat 'cleanups performed' 0
+
+ touch empty.c
+ CCACHE_LIMIT_MULTIPLE=0.7 $CCACHE_COMPILE -c empty.c -o empty.o
expect_file_count 157 '*.o' $CCACHE_DIR
expect_file_count 156 '*.d' $CCACHE_DIR
expect_file_count 156 '*.stderr' $CCACHE_DIR
prepare_cleanup_test_dir $CCACHE_DIR/a
- # (9/10) * 30 * 16 = 432
- $CCACHE -F 432 -M 0 >/dev/null
+ $CCACHE -F 336 -M 0 >/dev/null
backdate $CCACHE_DIR/a/result2-4017.stderr
$CCACHE -c >/dev/null
# floor(0.8 * 9) = 7
touch $CCACHE_DIR/a/abcd.unknown
$CCACHE -F 0 -M 0 -c >/dev/null # update counters
expect_stat 'files in cache' 31
- # (9/10) * 30 * 16 = 432
- $CCACHE -F 432 -M 0 >/dev/null
+
+ $CCACHE -F 480 -M 0 >/dev/null
$CCACHE -c >/dev/null
if [ ! -f $CCACHE_DIR/a/abcd.unknown ]; then
test_failed "$CCACHE_DIR/a/abcd.unknown removed"
fi
- expect_stat 'files in cache' 19
+ expect_stat 'files in cache' 28
# -------------------------------------------------------------------------
TEST "Cleanup of old unknown file"
prepare_cleanup_test_dir $CCACHE_DIR/a
- # (9/10) * 30 * 16 = 432
- $CCACHE -F 432 -M 0 >/dev/null
+ $CCACHE -F 480 -M 0 >/dev/null
touch $CCACHE_DIR/a/abcd.unknown
backdate $CCACHE_DIR/a/abcd.unknown
- $CCACHE -c >/dev/null
+ $CCACHE -F 0 -M 0 -c >/dev/null # update counters
+ expect_stat 'files in cache' 31
+
+ $CCACHE -F 480 -M 0 -c >/dev/null
if [ -f $CCACHE_DIR/a/abcd.unknown ]; then
test_failed "$CCACHE_DIR/a/abcd.unknown not removed"
fi
+ expect_stat 'files in cache' 30
# -------------------------------------------------------------------------
TEST "Cleanup of tmp file"
$CCACHE -c >/dev/null
expect_file_count 1 '.nfs*' $CCACHE_DIR
expect_stat 'files in cache' 30
-
- # -------------------------------------------------------------------------
- TEST "CCACHE_LIMIT_MULTIPLE"
-
- prepare_cleanup_test_dir $CCACHE_DIR/a
-
- # (1/1) * 30 * 16 = 480
- $CCACHE -F 480 >/dev/null
- CCACHE_LIMIT_MULTIPLE=0.5 $CCACHE -c >/dev/null
- expect_stat 'files in cache' 15
}
# =============================================================================