Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

[Linux x86_64] Massive memory leak on map load or renderer reload with typical amount of addons (for a busy server) #4085

Open Cloudwalk9 opened 5 years ago

Cloudwalk9 commented 5 years ago

Details

Massive memory leak when I change screen resolutions or enter singleplayer from a busy DarkRP server (for example). I've observed a rapid, runaway 15+ GB allocation, during the freeze time when loading a map or applying graphics settings, and this often prolongs the freeze time. Only some of this memory is freed, and it persists after disconnecting. This leak does not occur when all addons are disabled. In a severe case, the game managed to trigger the OOM killer (I have 32 GB of RAM).

Steps to reproduce

Join a DarkRP server or any busy server (or even start singleplayer) with large amounts of addons, and PAC3 for good measure, change resolution or immediately hop on singleplayer, and watch as the game gives Chrome a run for its money.

If any specific addon may be causing this, I'd be happy to help narrow it down. This is probably a regression as the same addons did not cause this problem previously, and it's presumed that Windows is probably unaffected. If there's any other way I can help debug this, I'm all ears.

Cloudwalk9 commented 5 years ago

Memory usage of Windows players on the same server (x86_64 branch) was less than 2 GB. The game spiked to 16 GB from 10, on a resolution change, then settled on 15.7

Cloudwalk9 commented 4 years ago

If this hasn't been independently reproduced already, the easiest way to do so, if I had to guess, would be addons that stream textures. In my case, it's probably PAC3, and customizable player model addons such as PPM/2 (pony player models... sorry!).

thegrb93 commented 4 years ago

This is because pac3 creates a new html panel for every texture that is loaded and html panels don't release their textures when destroyed. At least that's how it was last time I checked.

Cloudwalk9 commented 4 years ago

So when the renderer reloads, all HTML panels should release their textures, memory leak fixed, although it's probably not that simple...

thegrb93 commented 4 years ago

Or they should recycle their html panels; that's what starfall does.

robotboy655 commented 4 years ago

Potentially related or duplicate of #3792

Cloudwalk9 commented 3 years ago

Forgot about this issue.

This doesn't occur with AMD (and probably Intel).

This is an educated guess as to what's going wrong, but I've been told (not sure how true this is) Windows likes to ditch texture memory without warning on OpenGL, which is worked around by mapping textures to application memory. The Nvidia OpenGL driver is a shared codebase between Windows, Linux, and Nvidia's other supported platforms, and this behavior likely carried over.

This would imply Garry's Mod indeed has a really bad VRAM leak, perhaps with HTML panels. This also makes the 32-bit build unplayable on Nvidia (except in singleplayer or servers with not a lot going on) as this mapping quickly exhausts the limited address space.

thegrb93 commented 3 years ago

I haven't noticed any serious memory leaks on windows so I'm guessing this is Linux only.

Cloudwalk9 commented 3 years ago

I haven't noticed any serious memory leaks on windows so I'm guessing this is Linux only.

Garry's Mod uses DX9 on Windows.