Skip to content

Commit

Permalink
adaptivemm: init at unstable-2023-01-16
Browse files Browse the repository at this point in the history
There are proper release tags, but the latest one is from Feb 2022
and there are buffer overflow fixes since.
  • Loading branch information
Michael Livshin committed Apr 14, 2023
1 parent 0662bd2 commit 6c3d98d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
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;

let
cfg = config.services.adaptivemm;
in {
options = {
services.adaptivemm = {
enable = mkEnableOption (lib.mdDoc "Proactively tune kernel free memory configuration");

package = mkOption {
type = types.package;
default = pkgs.adaptivemm;
defaultText = literalExpression "pkgs.adaptivemm";
description = lib.mdDoc ''
Which adaptivemm package to use.
'';
};

verbosity = mkOption {
type = types.int;
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;
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";
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}";
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 ];
};
}
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 }:

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/
'';

meta = with lib; {
description = "A userspace daemon for proactive free memory management";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [ cmm ];
};
}
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

0 comments on commit 6c3d98d

Please sign in to comment.