-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make 'nix store gc' use the auto-GC policy #7851
base: master
Are you sure you want to change the base?
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 <valentin.gagarin@tweag.io>
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-44/25546/1 |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-02-20-nix-team-meeting-minutes-34/25625/1 |
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: https://discourse.nixos.org/t/2023-03-20-nix-team-meeting-minutes-42/26615/1 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-05-26-nix-team-meeting-minutes-58/28572/1 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-08-28-nix-team-meeting-minutes-83/32290/1 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-09-04-nix-team-meeting-minutes-85/32608/1 |
This has a number of unaddressed comments and merge conflicts. Please undraft when comments and conflicts are resolved. |
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: https://discourse.nixos.org/t/2024-01-30-nix-team-meeting-minutes-119/39185/1 |
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: https://discourse.nixos.org/t/2024-04-10-nix-team-meeting-138/43585/1 |
Motivation
I.e.
nix store gc
will observe themin-free
andmax-free
settings, which have been renamed togc-threshold
andgc-limit
. To remove inconsistency in handlinggc-threshold
, auto-GC now must be enabled using the newauto-gc
setting.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/**.sh
src/*/tests
tests/nixos/*