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

Swapspace: dynamically manage swapspace on NixOS #88093

Closed
wants to merge 5 commits into from

Conversation

wmertens
Copy link
Contributor

Motivation for this change

Using NixOS with dynamic swap size management, the way macOS does it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@wmertens wmertens requested a review from infinisil May 18, 2020 21:47
@ofborg ofborg bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 labels May 18, 2020
###### implementation

config = mkIf cfg.enable {
systemd.services.swapspace = with pkgs; {
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
systemd.services.swapspace = with pkgs; {
systemd.services.swapspace = {

you don't refer to things inside pkgs anywhere.

@flokli
Copy link
Contributor

flokli commented Aug 7, 2020

@wmertens can you address the changes requested?

@flokli flokli added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 7, 2020
@wmertens
Copy link
Contributor Author

wmertens commented Aug 7, 2020

@flokli yes sorry, they were very helpful, but this dropped off my radar. I'll address them this weekend

@flokli
Copy link
Contributor

flokli commented Aug 15, 2020

@wmertens another poke ;-)

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 15, 2020
@wmertens
Copy link
Contributor Author

@peterhoeg thanks for the thorough review, much appreciated. I'll update this this week.

@xaverdh
Copy link
Contributor

xaverdh commented Jun 5, 2021

is this still worked on?

@wmertens wmertens force-pushed the swapspace branch 2 times, most recently from fe078cb to ef928e6 Compare June 5, 2021 10:19
@wmertens
Copy link
Contributor Author

wmertens commented Jun 5, 2021

Ok, updated and rebased. Thank you all for your comments, is this good for merging?

@stale
Copy link

stale bot commented Jan 9, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 9, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 26, 2022
@github-actions github-actions bot added 8.has: changelog 8.has: documentation This PR adds or changes documentation labels Jan 26, 2022
based on reviews from langston-barrett, flokli and peterhoeg, thanks!

nativeBuildInputs = [ autoreconfHook ];

patchPhase = ''
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
patchPhase = ''
postPatch = ''

Comment on lines +33 to +34
nativeBuildInputs = [ autoreconfHook ];

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nativeBuildInputs = [ autoreconfHook ];

duped with line 14

type = types.nullOr types.int;
default = null;
description = ''
Maximum size of a swapfile.
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be great to explain what happens when this is set to null. Same for minSwapSize.

description = ''
Cooldown period between changes.
SwapSpace will wait at least this many seconds before an action,
like removing a swapfile after adding one.
Copy link
Member

Choose a reason for hiding this comment

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

Is null then the same as 0 or how does it interact?

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 31, 2022
@ghost
Copy link

ghost commented Oct 5, 2022

Why is this staled out ? Does no one use dynamic swap on Nix?

@wmertens
Copy link
Contributor Author

wmertens commented Oct 5, 2022 via email

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 5, 2022
@SuperSandro2000 SuperSandro2000 added the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 7, 2022
@Luflosi Luflosi mentioned this pull request Oct 17, 2022
+ optionalString (cfg.cooldown != null)
" --cooldown=${toString cfg.cooldown}"
+ optionalString (cfg.minSwapSize != null)
" --min_swapsize=${toString cfg.minSwapSize}"
Copy link
Contributor

Choose a reason for hiding this comment

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

From the documentation:

Never bother to allocate any swapfiles smaller than size bytes. There should be no need to change this variable except for testing.

I suggest removing this argument and the option. For testing, one can just use extraArgs.

@Luflosi
Copy link
Contributor

Luflosi commented Oct 30, 2022

You should reuse the upstream systemd unit file by copying it to the package output and then using it in the NixOS module. Let me know if you need help with that. I'll be happy to help you on this.

@ghost
Copy link

ghost commented Dec 30, 2022

having dynamic swap on my laptop (and I bet many other systems) would be so nice... Zswap seems to work better than zram and being able to have a dynamic swap system would help with not having to sacrifice a definite storage space

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 15:40
@Luflosi Luflosi mentioned this pull request Oct 14, 2024
13 tasks
@Pandapip1
Copy link
Contributor

Superseded by #348588

@Pandapip1 Pandapip1 closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants