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

adaptivemm: init at unstable-20230116 #225782

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@
./services/matrix/pantalaimon.nix
./services/matrix/synapse.nix
./services/misc/airsonic.nix
./services/misc/adaptivemm.nix
./services/misc/ananicy.nix
./services/misc/ankisyncd.nix
./services/misc/apache-kafka.nix
Expand Down
86 changes: 86 additions & 0 deletions nixos/modules/services/misc/adaptivemm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{ config, lib, pkgs, ... }:

with lib;
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
with lib;

to address #208242 for this module, uses of with such as this should be avoided.
consider inherits where you find yourself using lib.foo excessively.
this nix.dev page on best practices with with may be helpful


let
cfg = config.services.adaptivemm;
in {
options = {
services.adaptivemm = {
enable = mkEnableOption (lib.mdDoc "Proactively tune kernel free memory configuration");
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
enable = mkEnableOption (lib.mdDoc "Proactively tune kernel free memory configuration");
enable = mkEnableOption "Proactively tune kernel free memory configuration";

lib.mdDoc is now just an alias and can be safely removed everywhere.
see d36f950 and #237557


package = mkOption {
type = types.package;
default = pkgs.adaptivemm;
defaultText = literalExpression "pkgs.adaptivemm";
description = lib.mdDoc ''
Which adaptivemm package to use.
'';
};
Comment on lines +12 to +19
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
package = mkOption {
type = types.package;
default = pkgs.adaptivemm;
defaultText = literalExpression "pkgs.adaptivemm";
description = lib.mdDoc ''
Which adaptivemm package to use.
'';
};
package = mkPackageOptionMD pkgs "adaptivemm" { };


verbosity = mkOption {
type = types.int;
Copy link
Member

Choose a reason for hiding this comment

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

There's some magic stuff in lib that let's us avoid the nasty asserts.

Suggested change
type = types.int;
type = types.int.between 0 5;

default = 0;
defaultText = literalExpression "0";
description = lib.mdDoc ''
Verbosity, from 0 to 5.
'';
};

maxWatermarkGap = mkOption {
type = types.int;
default = 5;
defaultText = literalExpression "5";
description = lib.mdDoc ''
Maximum allowed gap between high and low watermarks in GB.
'';
};

aggressiveness = mkOption {
type = types.int;
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
type = types.int;
type = types.int.between 1 3;

default = 2;
defaultText = literalExpression "2";
description = lib.mdDoc ''
Aggressiveness level (1=high, 2=normal, 3=low).
'';
};
};
};

config = mkIf cfg.enable {
environment = {
systemPackages = [ cfg.package ];
etc."sysconfig/adaptivemmd".source = "${cfg.package}/etc/sysconfig/adaptivemmd";
};

systemd.services.adaptivemmd = {
serviceConfig = {
Type = "forking";
EnvironmentFile = "/etc/sysconfig/adaptivemmd";
Comment on lines +51 to +59
Copy link
Member

Choose a reason for hiding this comment

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

unless you have a strong suspicion that it would be beneficial to the average user to run this manually, I think I would just hide this file and keep the package away from the environment.

Suggested change
environment = {
systemPackages = [ cfg.package ];
etc."sysconfig/adaptivemmd".source = "${cfg.package}/etc/sysconfig/adaptivemmd";
};
systemd.services.adaptivemmd = {
serviceConfig = {
Type = "forking";
EnvironmentFile = "/etc/sysconfig/adaptivemmd";
systemd.services.adaptivemmd = {
serviceConfig = {
Type = "forking";
EnvironmentFile = "${cfg.package}/etc/sysconfig/adaptivemmd";

ExecStart = let
verboseFlag = assert (cfg.verbosity >= 0 && cfg.verbosity <= 5);
if cfg.verbosity == 0 then ""
else lib.concatStrings (["-"] ++ (lib.replicate cfg.verbosity "v"));
aggressivenessFlag = assert (cfg.aggressiveness >= 1 && cfg.aggressiveness <= 3);
"-a ${builtins.toString cfg.aggressiveness}";
gapFlag = "-m ${builtins.toString cfg.maxWatermarkGap}";
Comment on lines +61 to +66
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
verboseFlag = assert (cfg.verbosity >= 0 && cfg.verbosity <= 5);
if cfg.verbosity == 0 then ""
else lib.concatStrings (["-"] ++ (lib.replicate cfg.verbosity "v"));
aggressivenessFlag = assert (cfg.aggressiveness >= 1 && cfg.aggressiveness <= 3);
"-a ${builtins.toString cfg.aggressiveness}";
gapFlag = "-m ${builtins.toString cfg.maxWatermarkGap}";
verboseFlag = if cfg.verbosity == 0 then ""
else "-${lib.concatStrings (lib.replicate cfg.verbosity "v")}";
aggressivenessFlag = "-a ${toString cfg.aggressiveness}";
gapFlag = "-m ${toString cfg.maxWatermarkGap}";

in "${cfg.package}/bin/adaptivemmd ${verboseFlag} ${aggressivenessFlag} ${gapFlag}";
KillMode = "control-group";
Restart = "on-failure";
RestartSec = "10s";
};

unitConfig = {
Description = "Adaptive free memory optimizer daemon";
Documentation = "man:adaptivemmd(8)";
After = [ "systemd-sysctl.service" "local-fs.target" ];
};

wantedBy = [ "multi-user.target" ];
};
};

meta = {
maintainers = with maintainers; [ cmm ];
};
Comment on lines +83 to +85
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
meta = {
maintainers = with maintainers; [ cmm ];
};
meta.maintainers = with maintainers; [ cmm ];

}
31 changes: 31 additions & 0 deletions pkgs/os-specific/linux/adaptivemm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ lib, stdenv, fetchFromGitHub }:
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
{ lib, stdenv, fetchFromGitHub }:
{ lib, stdenv, fetchFromGitHub, installShellFiles }:


let
pname = "adaptivemm";
in stdenv.mkDerivation {
inherit pname;
version = "unstable-2023-01-16";

src = fetchFromGitHub {
owner = "oracle";
repo = pname;
rev = "92f7d6e9155e153db884ebb7da25c0a9cbcb29fe";
hash = "sha256-3aRfHn0HV9CfcLulDimHsMJPs8/VAWRVDxPijKVhtDM=";
};

CFLAGS = "-I. -Wall -O2";

installPhase = ''
mkdir -p $out/bin $out/etc/sysconfig $out/share/man/man8
cp adaptivemmd $out/bin/
cp $src/adaptivemmd.cfg $out/etc/sysconfig/adaptivemmd
cp $src/adaptivemmd.8 $out/share/man/man8/
'';
Comment on lines +17 to +23
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
installPhase = ''
mkdir -p $out/bin $out/etc/sysconfig $out/share/man/man8
cp adaptivemmd $out/bin/
cp $src/adaptivemmd.cfg $out/etc/sysconfig/adaptivemmd
cp $src/adaptivemmd.8 $out/share/man/man8/
'';
nativeBuildInputs = [ installShellFiles ];
installPhase = ''
runHook preInstall
install -Dm555 adaptivemmd $out/bin/adaptivemmd
install -Dm444 adaptivemmd.cfg $out/etc/sysconfig/adaptivemmd
installManPage adaptivemmd.8
runHook postInstall
'';


meta = with lib; {
description = "A userspace daemon for proactive free memory management";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [ cmm ];
};
Comment on lines +25 to +30
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
meta = with lib; {
description = "A userspace daemon for proactive free memory management";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [ cmm ];
};
meta = with lib; {
description = "A userspace daemon for proactive free memory management";
homepage = "https://github.com/oracle/adaptivemm";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [ cmm ];
mainProgram = "adaptivemmd";
};

}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26125,6 +26125,8 @@ with pkgs;

acpitool = callPackage ../os-specific/linux/acpitool { };

adaptivemm = callPackage ../os-specific/linux/adaptivemm { };

alfred = callPackage ../os-specific/linux/batman-adv/alfred.nix { };

alertmanager-bot = callPackage ../servers/monitoring/alertmanager-bot { };
Expand Down