From: Joel Rosdahl Date: Sat, 6 Jan 2018 14:41:13 +0000 (+0100) Subject: Make ccache -c/--cleanup not take limit_multiple into account X-Git-Tag: v3.3.5~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7784c4228726a55cca043800ce45266d3301584d;p=thirdparty%2Fccache.git Make ccache -c/--cleanup not take limit_multiple into account Now "ccache -c/--cleanup" will trim the cache to the configured max limits instead of 80% (limit_multiple) of the max limits. This feels like a more intuitive behavior, and it also makes it behave like documented. --- diff --git a/NEWS.txt b/NEWS.txt index 06fbb9fb4..959a9ccf7 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -25,6 +25,12 @@ Bug fixes - Fixed a bug related to erroneously storing a dependency file with absolute paths in the cache on a preprocessed hit. +- `ccache -c/--cleanup` now works like documented: it just recalculates size + counters and trims the cache to not exceed the max size and file number + limits. Previously, the forced cleanup took ``limit_multiple'' into account, + so that `ccache -c/--cleanup` by default would trim the cache to 80% of the + max limit. + ccache 3.3.4 ------------ diff --git a/ccache.h b/ccache.h index 2bae451b2..413da7f32 100644 --- a/ccache.h +++ b/ccache.h @@ -217,7 +217,7 @@ void exitfn_call(void); // ---------------------------------------------------------------------------- // cleanup.c -void clean_up_dir(struct conf *conf, const char *dir); +void clean_up_dir(struct conf *conf, const char *dir, float limit_multiple); void clean_up_all(struct conf *conf); void wipe_all(struct conf *conf); diff --git a/cleanup.c b/cleanup.c index bbd13800b..458408264 100644 --- a/cleanup.c +++ b/cleanup.c @@ -170,15 +170,15 @@ sort_and_clean(void) // 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; @@ -221,7 +221,7 @@ void clean_up_all(struct conf *conf) { 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); } } diff --git a/stats.c b/stats.c index e07a2a9b4..0ed203d3e 100644 --- a/stats.c +++ b/stats.c @@ -395,7 +395,7 @@ stats_flush(void) } if (need_cleanup) { - clean_up_dir(conf, subdir); + clean_up_dir(conf, subdir, conf->limit_multiple); } free(subdir); diff --git a/test.sh b/test.sh index 6fbc1ca93..28dbc57e7 100755 --- a/test.sh +++ b/test.sh @@ -2621,10 +2621,22 @@ SUITE_cleanup() { 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 @@ -2655,10 +2667,8 @@ SUITE_cleanup() { 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 @@ -2678,22 +2688,45 @@ SUITE_cleanup() { 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 @@ -2705,8 +2738,7 @@ SUITE_cleanup() { 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 @@ -2735,26 +2767,29 @@ SUITE_cleanup() { 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" @@ -2780,16 +2815,6 @@ SUITE_cleanup() { $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 } # =============================================================================