llvm.org GIT mirror llvm / 463ba76
[ThinLTO][CachePruning] explicitly disable pruning In https://reviews.llvm.org/rL321077 and https://reviews.llvm.org/D41231 I fixed a regression in the c-api which prevented the pruning from being *effectively* disabled. However this approach, helpfully recommended by @labath, is cleaner. It is also nice to remove the weasel words about effectively disabling from the api comments. Differential Revision: https://reviews.llvm.org/D41497 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321376 91177308-0d34-0410-b5e6-96231b3b80d8 Ben Dunbobbin 1 year, 8 months ago
4 changed file(s) with 20 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
147147 /// incremental build.
148148 void setCacheDir(std::string Path) { CacheOptions.Path = std::move(Path); }
149149
150 /// Cache policy: interval (seconds) between two prunes of the cache. A
151 /// negative value sets the maximum possible pruning interval. A value
152 /// of 0 will be ignored.
150 /// Cache policy: interval (seconds) between two prunes of the cache. Set to a
151 /// negative value to disable pruning. A value of 0 will be ignored.
153152 void setCachePruningInterval(int Interval) {
154 static_assert(std::is_same
155 std::chrono::seconds>::value,
156 "ensure same types to avoid risk of overflow");
157 if (Interval)
158 CacheOptions.Policy.Interval = Interval > 0 ? std::chrono::seconds(Interval)
159 : std::chrono::seconds::max();
153 if (Interval == 0)
154 return;
155 if(Interval < 0)
156 CacheOptions.Policy.Interval.reset();
157 else
158 CacheOptions.Policy.Interval = std::chrono::seconds(Interval);
160159 }
161160
162161 /// Cache policy: expiration (in seconds) for an entry.
2626 struct CachePruningPolicy {
2727 /// The pruning interval. This is intended to be used to avoid scanning the
2828 /// directory too often. It does not impact the decision of which file to
29 /// prune. A value of 0 forces the scan to occur.
30 std::chrono::seconds Interval = std::chrono::seconds(1200);
29 /// prune. A value of 0 forces the scan to occur. A value of None disables
30 /// pruning.
31 llvm::Optional Interval = std::chrono::seconds(1200);
3132
3233 /// The expiration for a file. When a file hasn't been accessed for Expiration
3334 /// seconds, it is removed from the cache. A value of 0 disables the
763763 * To avoid filling the disk space, a few knobs are provided:
764764 * - The pruning interval limits the frequency at which the garbage collector
765765 * will try to scan the cache directory to prune expired entries.
766 * Setting to a negative number applies the maximum interval.
766 * Setting to a negative number disables the pruning.
767767 * - The pruning expiration time indicates to the garbage collector how old an
768768 * entry needs to be to be removed.
769769 * - Finally, the garbage collector can be instructed to prune the cache until
781781 const char *cache_dir);
782782
783783 /**
784 * Sets the cache pruning interval (in seconds). A negative value sets the
785 * maximum possible pruning interval. An unspecified default value will be
786 * applied, and a value of 0 will be ignored.
784 * Sets the cache pruning interval (in seconds). A negative value disables the
785 * pruning. An unspecified default value will be applied, and a value of 0 will
786 * be ignored.
787787 *
788788 * \since LTO_API_VERSION=18
789789 */
154154 SmallString<128> TimestampFile(Path);
155155 sys::path::append(TimestampFile, "llvmcache.timestamp");
156156 sys::fs::file_status FileStatus;
157 const auto CurrentTime =
158 time_point_cast(system_clock::now());
157 const auto CurrentTime = system_clock::now();
159158 if (auto EC = sys::fs::status(TimestampFile, FileStatus)) {
160159 if (EC == errc::no_such_file_or_directory) {
161160 // If the timestamp file wasn't there, create one now.
165164 return false;
166165 }
167166 } else {
167 if (!Policy.Interval)
168 return false;
168169 if (Policy.Interval != seconds(0)) {
169170 // Check whether the time stamp is older than our pruning interval.
170171 // If not, do nothing.
171 const auto TimeStampModTime = time_point_cast(
172 FileStatus.getLastModificationTime());
172 const auto TimeStampModTime = FileStatus.getLastModificationTime();
173173 auto TimeStampAge = CurrentTime - TimeStampModTime;
174 if (TimeStampAge <= Policy.Interval) {
174 if (TimeStampAge <= *Policy.Interval) {
175175 DEBUG(dbgs() << "Timestamp file too recent ("
176176 << duration_cast(TimeStampAge).count()
177177 << "s old), do not prune.\n");