]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make ccache -c/--cleanup not take limit_multiple into account
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 6 Jan 2018 14:41:13 +0000 (15:41 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 10 Jan 2018 19:58:32 +0000 (20:58 +0100)
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.

NEWS.txt
ccache.h
cleanup.c
stats.c
test.sh

index 06fbb9fb44453773a62c0e49ace2fc0f894d6990..959a9ccf70e2e3ab09524681bfc7fb03f17de27e 100644 (file)
--- 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
 ------------
index 2bae451b2d181e1abd4c4e5719c2e22828864d4b..413da7f3218817bc2630e1291132ef6ff5a56f57 100644 (file)
--- 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);
 
index bbd13800b686d6e381da50dff883e9db717ef52c..458408264c19320b9be2dd9d4853efd17234ed6b 100644 (file)
--- 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 e07a2a9b4a48fcdebcad520ea43aac98f0540c66..0ed203d3e9a5ced967c8b9031b78b2e3792c1d54 100644 (file)
--- 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 6fbc1ca9316c7123470a9a7fc5d5fe057768053b..28dbc57e782fd4ed28120a09e2bf02c91b08a46a 100755 (executable)
--- 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
 }
 
 # =============================================================================