Skip to content
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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Feb 16, 2023

Motivation

I.e. nix store gc will observe the min-free and max-free settings, which have been renamed to gc-threshold and gc-limit. To remove inconsistency in handling gc-threshold, auto-GC now must be enabled using the new auto-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

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

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.
@Ericson2314
Copy link
Member

Ericson2314 commented Feb 16, 2023

@edolstra I am a bit worried about the changes to GcStore because RemoteStore also implements GcStore; GcStore represents the interface of being able to trigger GCs, not the implementation. Presumably these new mechanisms would just used on the server side, not the client side.

@Ericson2314
Copy link
Member

Also, I would like to take this opportunity to chip away at #5638. The newly renamed options should be FooStoreConfig options, not global settings, on whatever FooStore subclass we end up putting this stuff on.

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 FooStoreConfig settings.

src/nix/store-gc.md Outdated Show resolved Hide resolved
src/nix/store-gc.md Outdated Show resolved Hide resolved
src/nix/store-gc.md Outdated Show resolved Hide resolved
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
@nixos-discourse
Copy link

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

src/nix/store-gc.md Outdated Show resolved Hide resolved
@fricklerhandwerk fricklerhandwerk mentioned this pull request Feb 20, 2023
4 tasks
@fricklerhandwerk
Copy link
Contributor

  • reviewed together in the Nix team meeting

  • @Ericson2314: the gc policy should be server-side, but as it is the client would be driving the server's policy

    • @edolstra: it's debatable if one really wants this. if you run nix store gc --gc-threshold 1G you wouldn't want this to be ignored on the target store
    • @Ericson2314: one may still want to override the server settings, but right now every client would tell the server to GC at random intervals, especially for auto-gc where clients will trigger timers
      • clients should not micro-manage the DB
    • @edolstra: currently the implementation mixes regular and auto GC, which is inelegant, and we should refactor this eventually
      • clients do not actually call auto-gc, this is done by workers
      • one could factor out running the timer to have a unique thread doing it, but it's a separate issue
  • @edolstra: there is still a bug: the only thing autoGC needs is waiting for getAvailableSpace(), and calling that on a remote store isn't implemented yet

  • @Ericson2314: suggestion: move all additions to a subclass of GcStore

    • GcStore and doGC() should be stateless and only worry about the policy parameters
    • state should be managed somewhere else (back to LocalStore or a new AutoGcStore)
    • @edolstra: agreed
  • @thufschmitt: does this keep an easy and intuitive way of running GC manually? this would be in order to ensure that users don't get stuck running out of space. the change subtly changes the behavior of nix store gc

    • @edolstra: the default for gc-limit is infinity anyaway
    • @thufschmitt: the problem is that someone may already have gc-max set and enable auto-gc
    • @fricklerhandwerk: nix store gc is experimental, we should be free to change it at will, that's the purpose of experimental features
    • @Ericson2314: we could add a --full/--force/--always flag to forcefully override the settings to 0-infinity
  • @roberth: auto-gc is not experimental today, so this does need a migration story.

    • have to detect min is set to something and enable auto-gc implicitly
    • issue a warning that this is a deprecated behavior with instructions to change the settings, convert to error a couple of releases later
    • @edolstra: this is such an obscure feature that didn't even work until a couple of weeks ago
    • agreement to add a warning
  • agreement: needs more work, continue async

@nixos-discourse
Copy link

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

@fricklerhandwerk fricklerhandwerk added the new-cli Relating to the "nix" command label Feb 24, 2023
@roberth
Copy link
Member

roberth commented Mar 12, 2023

I think gc-goal would be more accurate than gc-limit. A goal is also something that is allowed to be surpassed, whereas going over a limit is not ok.

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.

@nixos-discourse
Copy link

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

@Ericson2314 Ericson2314 self-assigned this May 26, 2023
@nixos-discourse
Copy link

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

@github-actions github-actions bot added documentation with-tests Issues related to testing. PRs with tests have some priority store Issues and pull requests concerning the Nix store labels Aug 28, 2023
doc/manual/src/release-notes/rl-next.md Outdated Show resolved Hide resolved
src/libstore/globals.hh Outdated Show resolved Hide resolved
src/libstore/globals.hh Outdated Show resolved Hide resolved
@nixos-discourse
Copy link

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

@tomberek tomberek mentioned this pull request Sep 1, 2023
86 tasks
@thufschmitt thufschmitt added this to the CLI Stabilisation milestone Sep 4, 2023
@nixos-discourse
Copy link

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

@roberth roberth marked this pull request as draft December 22, 2023 16:15
@roberth
Copy link
Member

roberth commented Dec 22, 2023

This has a number of unaddressed comments and merge conflicts. Please undraft when comments and conflicts are resolved.

@edolstra edolstra marked this pull request as ready for review January 8, 2024 13:42
edolstra and others added 3 commits January 8, 2024 14:46
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: John Ericson <git@JohnEricson.me>
Comment on lines +6 to +11
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +121 to +168

/**
* 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;
Copy link
Member

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

@nixos-discourse
Copy link

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

@roberth
Copy link
Member

roberth commented Apr 2, 2024

@roberth roberth marked this pull request as draft April 2, 2024 16:04
@nixos-discourse
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority
Projects
Status: 🏁 Review
Development

Successfully merging this pull request may close these issues.

Rename min-free to "threshold", rename max-free
6 participants