Make 'nix store gc' use the auto-GC policy #7851
Make 'nix store gc' use the auto-GC policy #7851edolstra wants to merge 15 commits intoNixOS:masterfrom
Conversation
This makes 'nix store gc' observe the same policy as auto-GC (which of course can be overriden from the command line via --max-free and --min-free).
This is no longer determined by 'min-free', which now defaults to infinity. The reason is to make 'min-free' behave consistently for auto-GC and explicit 'nix store gc' invocations.
|
@edolstra I am a bit worried about the changes to |
|
Also, I would like to take this opportunity to chip away at #5638. The newly renamed options should be If we want to be able to set the settings from the Nix config, @roberth and I discussed making a private global settings singleton (which is registered) whose sole purpose is to initialize those |
Co-authored-by: Valentin Gagarin <[email protected]>
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
I think Also I think a goal reflects something in absolute space, whereas limit could refer to anything including the gc process; a relative amount, which this is not. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This has a number of unaddressed comments and merge conflicts. Please undraft when comments and conflicts are resolved. |
Co-authored-by: Robert Hensing <[email protected]>
Co-authored-by: John Ericson <[email protected]>
| Automatic garbage collection is now only enabled if you set [`auto-gc | ||
| = true`](@docroot@/command-ref/conf-file.md#conf-auto-gc). You will | ||
| probably also want to set | ||
| [`gc-threshold`](@docroot@/command-ref/conf-file.md#conf-gc-threshold) | ||
| to configure when the garbage collector kicks in, e.g. `1G` to make it | ||
| run when free space drops below 1 gigabyte. |
There was a problem hiding this comment.
| Automatic garbage collection is now only enabled if you set [`auto-gc | |
| = true`](@docroot@/command-ref/conf-file.md#conf-auto-gc). You will | |
| probably also want to set | |
| [`gc-threshold`](@docroot@/command-ref/conf-file.md#conf-gc-threshold) | |
| to configure when the garbage collector kicks in, e.g. `1G` to make it | |
| run when free space drops below 1 gigabyte. | |
| Automatic garbage collection is now only enabled if you set [`auto-gc = true`](@docroot@/command-ref/conf-file.md#conf-auto-gc). | |
| You will probably also want to set [`gc-threshold`](@docroot@/command-ref/conf-file.md#conf-gc-threshold) to configure when the garbage collector kicks in, e.g. `1G` to make it run when free space drops below 1 gigabyte. |
|
|
||
| /** | ||
| * Do a garbage collection that observes the policy configured by | ||
| * `gc-threshold`, `gc-limit`, etc. | ||
| */ | ||
| void doGC(bool sync = true); | ||
|
|
||
| /** | ||
| * Perform an automatic garbage collection, if enabled. | ||
| */ | ||
| void autoGC(bool sync = true); | ||
|
|
||
| /** | ||
| * Return the amount of available disk space in this store. Used | ||
| * by `autoGC()`. | ||
| */ | ||
| virtual uint64_t getAvailableSpace() | ||
| { | ||
| return std::numeric_limits<uint64_t>::max(); | ||
| } | ||
|
|
||
| private: | ||
|
|
||
| struct State | ||
| { | ||
| /** | ||
| * 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> _state; |
There was a problem hiding this comment.
remember this stuff cannot go here, because this mixin is also used by the remote stores. It should go in local store or a new mixin class
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
Please mark as ready for review when the following are addressed: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation
I.e.
nix store gcwill observe themin-freeandmax-freesettings, which have been renamed togc-thresholdandgc-limit. To remove inconsistency in handlinggc-threshold, auto-GC now must be enabled using the newauto-gcsetting.This PR also allows unit prefix in configuration settings, e.g.
min-free = 5G.Fixes #7822, #7608.
Context
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.shsrc/*/teststests/nixos/*