Nvidia never suspends

I have a Yoga 9 with discrete a RTX4050 GPU. I set it up to see both with the help of nixos-hardware. It’s nice to be able to run LLMs locally with ollama.

However, with nvtop I can see that it never goes idle, even though most of the time it’s not used.

The power setup seems to be ok? Not sure how to influence S0ix.

$ cat /proc/driver/nvidia/gpus/0000:01:00.0/power
Runtime D3 status:          Enabled (fine-grained)
Video Memory:               Active

GPU Hardware Support:
 Video Memory Self Refresh: Supported
 Video Memory Off:          Supported

S0ix Power Management:
 Platform Support:          Supported
 Status:                    Disabled

Notebook Dynamic Boost:     Supported

The users are gnome-shell, chrome, ollama and cursor. I can’t live without Chrome and I’d like to have the GPU available when needed. Ollama I could run when needed and cursor I could disable GPU use for. I tried disabling those latter two, no difference.

$ sudo fuser -v /dev/nvidia*
                     USER        PID ACCESS COMMAND
/dev/nvidia-modeset: wmertens   2599 F.... .gnome-shell-wr
                     wmertens   3527 F.... chrome
/dev/nvidia-uvm:     ollama     1556 F.... .ollama-wrapped
                     wmertens  10462 F.... nvidia-smi
/dev/nvidia0:        ollama     1556 F...m .ollama-wrapped
                     wmertens   2599 F...m .gnome-shell-wr
                     wmertens   3527 F...m chrome
                     wmertens   4566 F.... cursor
                     wmertens  10462 F.... nvidia-smi
/dev/nvidiactl:      ollama     1556 F...m .ollama-wrapped
                     wmertens   2599 F...m .gnome-shell-wr
                     wmertens   3527 F...m chrome
                     wmertens   4566 F.... cursor
                     wmertens  10462 F...m nvidia-smi

Shouldn’t all these be able to suspend the GPU when not in use?

I’m using the open drivers, but I tried the closed ones without a difference.

You need to set up finegrained powermanagement for this to work. In addition to (pointlessly for modern drivers and cards) setting the nvidia driver setting for finegrained mode, this sets up a few udev rules to configure automatic powermanagement.

That doesn’t work IME though, I suspect that NixOS starts udev too late in the boot process. The udev rules are still necessary to make hings work if the driver is unloaded for whatever reason.

I’ve written this commit to make it work for me at the moment: WIP: fix(nvidia): Make runtime powermanagement actually work · TLATER/dotfiles@600ef27 · GitHub

The udev rules shouldn’t be much different from the upstream option (though they are installed more properly), but the powerUpCommands works. You’ll need to set powerManagement.enable for it to run.

I’m slowly generalizing my nvidia module, so there are some helpful comments and explanations in there, if it helps. I also intend to fix the boot upstream when I figure out how this is supposed to work.

This issue in my dotfiles also has some hints for debugging: Nvidia powermanagement not working on sway · Issue #383 · TLATER/dotfiles · GitHub

1 Like