Avoid Linux locking up in low memory situations using earlyoom

I really needed it, my laptop with 8 GB of memory canโ€™t handle nix-env on nixpkgs-unstable anymore :scream_cat: :scream_cat: :scream_cat:

4 Likes

I use this in my build wrapper script which obviously only addresses the nix part, but is helpful nonetheless:

MEM=$(free --giga | grep Mem | gawk '{print $2}')
if [ "$MEM" -lt 12 ]; then
  echo "Detected memory: ${MEM}GB. Lowering GC heap size"
  export GC_INITIAL_HEAP_SIZE=1m
fi

3 Likes

Thank you! This seems useful, the default garbage collector size is 384M per Common Environment Variables

I understand your command saves up to 383 MB of memory for a nix process? :thinking: Seems useful for my systems with 1 or 2 GB!

1 Like

I understand your command saves up to 383 MB of memory for a nix process?

I donโ€™t know enough about the specific garbage collector or how the various nix commands do allocations to give you anything tangible in terms of quantifiable memory savings.

My only data point - on an 8GB laptop, it would go into swap hell when running other things and doing nixos-rebuild without this. With this, the laptop would remain usable.

1 Like