From 0b606aad46e1d96da36d4831df63ad90f11d21c3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 5 Sep 2017 20:43:42 +0200 Subject: Add automatic garbage collection Nix can now automatically run the garbage collector during builds or while adding paths to the store. The option "min-free = " specifies that Nix should run the garbage collector whenever free space in the Nix store drops below . It will then delete garbage until "max-free" bytes are available. Garbage collection during builds is asynchronous; running builds are not paused and new builds are not blocked. However, there also is a synchronous GC run prior to the first build/substitution. Currently, no old GC roots are deleted (as in "nix-collect-garbage -d"). --- src/libstore/local-store.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libstore/local-store.hh') diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 04519bfca615..4973bd9a9849 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -7,6 +7,8 @@ #include "sync.hh" #include "util.hh" +#include +#include #include #include @@ -60,6 +62,21 @@ private: /* The file to which we write our temporary roots. */ AutoCloseFD fdTempRoots; + + /* The last time we checked whether to do an auto-GC, or an + auto-GC finished. */ + std::chrono::time_point lastGCCheck; + + /* Whether auto-GC is running. If so, get gcFuture to wait for + the GC to finish. */ + bool gcRunning = false; + std::shared_future gcFuture; + + /* How much disk space was available after the previous + auto-GC. If the current available disk space is below + minFree but not much below availAfterGC, then there is no + point in starting a new GC. */ + uint64_t availAfterGC = std::numeric_limits::max(); }; Sync _state; @@ -196,6 +213,10 @@ public: void addSignatures(const Path & storePath, const StringSet & sigs) override; + /* If free disk space in /nix/store if below minFree, delete + garbage until it exceeds maxFree. */ + void autoGC(bool sync = true); + private: int getSchema(); -- cgit 1.4.1