diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-09-05T18·43+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-09-05T18·43+0200 |
commit | 0b606aad46e1d96da36d4831df63ad90f11d21c3 (patch) | |
tree | 5787f4f043f7316a8ad4625772abe9a4da3c1d57 /src/libstore/local-store.hh | |
parent | b932ea58ec610830ed3141bb14fbd812aa66b2c1 (diff) |
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 = <bytes>" specifies that Nix should run the garbage collector whenever free space in the Nix store drops below <bytes>. 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").
Diffstat (limited to 'src/libstore/local-store.hh')
-rw-r--r-- | src/libstore/local-store.hh | 21 |
1 files changed, 21 insertions, 0 deletions
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 <chrono> +#include <future> #include <string> #include <unordered_set> @@ -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<std::chrono::steady_clock> lastGCCheck; + + /* Whether auto-GC is running. If so, get gcFuture to wait for + the GC to finish. */ + bool gcRunning = false; + std::shared_future<void> 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<uint64_t>::max(); }; Sync<State, std::recursive_mutex> _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(); |