I’m having trouble running several OpenGL processes at the same time on Linux. What I want is for one of them to be active and fullscreen, and the other ones to stay in background and not affect the performance of the foreground process.
Right know I am unmapping them in X and even suspending them by killing them with SIGSTOP to enure that they do not get any cpu time. The problem is that they still seem to reside in video memory, as far as i can see when running nvidia-smi tool.
This causes problems for the OpenGL processes starting later, that can not get the vram that they need. The driver does not seem to free any of the video memory used by the suspended processes, which was my impression that it would, to allow several processes to use the gpu.
Is there any way to free gpu memory without terminating the processes?
No, suspending a process or unmapping its window does not cause that process to release its memory allocations. You can force that by doing a mode switch or a VT switch.
I tried the following:
Suspended a few OpenGL apps in one x-session, noted vram usage from nvidia-smi, and then tried each of these:
Tried to change resolution back and forth, but no drop in vram usage.
Switch vt to console, login and look at nvidia-smi. Vram usage was the same.
Switch back from console to x and try to run another OpenGL app. Performance of the new app was bad, because it was not able to allocate sufficient vram. Nvidia-smi values still hadn’t dropped.
Created additional x-session, switched to it, and tried running opengl apps there while the others were suspended in the first x-session. Still bad performance and high vram usage.
I experienced multiple crashes of the xserver during the above tests. The crashes do not occur when switching resolution, vt or x-sessions without any opengl apps open.
Can you please provide the application or a representative sample, and an nvidia-bug-report.log.gz file generated after the X server crash has occurred?
The problem can be recreated using the Unity3D game: angrybots, which is a demo project incluced with unity. I have created a linux build, that i have attached.
To make x crash, i just start enough instances of the game up, to fill my vram, which i monitor using nvidia-smi. Then do a vt-switch, and try to switch back which causes the crash.
I have attached nvidia-bug-report.log.gz from before and after the crash, and also Xorg.0.log.old, because im not sure that the script included it. It contains the crash in the last part of the file: