How to prevent the system (X windows, Gnome, etc) from slowly taking all GPU memory?

I have a 1080Ti card installed into Ubuntu 16.04 system. GPU memory usage is about 400Mb right after system start, this is normal. But during normal activity (browsing, programming in IDE, etc) system memory usage constantly grows. This is an usage 3 hours after the start:
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
| 0 1391 G /usr/lib/xorg/Xorg 516MiB |
| 0 1594 G /usr/bin/gnome-shell 412MiB |
| 0 3374 G …el-token=E6E19324253A13762449DC51FB5042A9 454MiB |
| 0 4883 G …s-passed-by-fd --v8-snapshot-passed-by-fd 70MiB |

‘el-token=E6E19324253A13762449DC51FB5042A9’ is a Chrome browser.

It looks like X-Windows never returns memory back to GPU, if GPU still has free memory. This is a problem for Tensorflow, because it can’t use all GPU memory, and available memory is constantly shrinking.
How can I prevent the system (X-Windows, Gnome, browser, etc) from taking all GPU memory? X-Windows/Gnome don’t really needs 500Mb, same system works perfectly using only 200-400Mb on smaller cards (1060, 1050)

Did you ever figure out what to do for this? I’m in the same boat.

allen, if you are using gnome-shell, pressing alt-f2 to bring up the command window, typing r and pressing ‘enter’ reexecutes gnome-shell and frees some gpu memory used by gnome-shell.
However memory used by Xorg doesn’t decrease much till you exit the programs it allocated memory for. Do that once or twice a day.

Thanks, Hussam. That did reduce gnome-shell’s memory usage.

I’m thinking that the best solution may be “systemctl isolate multi-user” :-)