[llvm-branch-commits] [llvm] ec87710 - [ThinLTO] Also prune Thin-* files from the ThinLTO cache

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 19 06:16:20 PST 2021


Author: Hans Wennborg
Date: 2021-01-19T14:43:49+01:00
New Revision: ec877106a38b760229a2d676b7d2278b2bade8ab

URL: https://github.com/llvm/llvm-project/commit/ec877106a38b760229a2d676b7d2278b2bade8ab
DIFF: https://github.com/llvm/llvm-project/commit/ec877106a38b760229a2d676b7d2278b2bade8ab.diff

LOG: [ThinLTO] Also prune Thin-* files from the ThinLTO cache

Such files (Thin-%%%%%%.tmp.o) are supposed to be deleted immediately
after they're used (either by renaming or deletion). However, we've seen
instances on Windows where this doesn't happen, probably due to the
filesystem being flaky. This is effectively a resource leak which has
prevented us from using the ThinLTO cache on Windows.

Since those temporary files are in the thinlto cache directory which we
prune periodically anyway, allowing them to be pruned too seems like a
tidy way to solve the problem.

Differential revision: https://reviews.llvm.org/D94962

Added: 
    

Modified: 
    lld/test/COFF/lto-cache.ll
    llvm/lib/Support/CachePruning.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/COFF/lto-cache.ll b/lld/test/COFF/lto-cache.ll
index ced0c5251d13..559f7a9db91e 100644
--- a/lld/test/COFF/lto-cache.ll
+++ b/lld/test/COFF/lto-cache.ll
@@ -7,8 +7,8 @@
 
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; Create two files that would be removed by cache pruning due to age.
-; We should only remove files matching the pattern "llvmcache-*".
-; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
+; We should only remove files matching "llvmcache-*" or "Thin-*".
+; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/Thin-123.tmp.o %t.cache/foo
 ; RUN: lld-link /lldltocache:%t.cache /lldltocachepolicy:prune_after=1h /out:%t3 /entry:main %t2.o %t.o
 
 ; Two cached objects, plus a timestamp file and "foo", minus the file we removed.

diff  --git a/llvm/lib/Support/CachePruning.cpp b/llvm/lib/Support/CachePruning.cpp
index 7663644db558..5c5759ffbaca 100644
--- a/llvm/lib/Support/CachePruning.cpp
+++ b/llvm/lib/Support/CachePruning.cpp
@@ -211,11 +211,12 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
   // Walk all of the files within this directory.
   for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd;
        File != FileEnd && !EC; File.increment(EC)) {
-    // Ignore any files not beginning with the string "llvmcache-". This
+    // Ignore filenames not beginning with "llvmcache-" or "Thin-". This
     // includes the timestamp file as well as any files created by the user.
     // This acts as a safeguard against data loss if the user specifies the
     // wrong directory as their cache directory.
-    if (!sys::path::filename(File->path()).startswith("llvmcache-"))
+    StringRef filename = sys::path::filename(File->path());
+    if (!filename.startswith("llvmcache-") && !filename.startswith("Thin-"))
       continue;
 
     // Look at this file. If we can't stat it, there's nothing interesting


        


More information about the llvm-branch-commits mailing list