Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

wgpu memory leak #299

Closed
cart opened this issue May 5, 2020 · 8 comments · Fixed by #300
Closed

wgpu memory leak #299

cart opened this issue May 5, 2020 · 8 comments · Fixed by #300

Comments

@cart
Copy link
Contributor

cart commented May 5, 2020

I have observed in both the "cube" example and my own personal project that wgpu programs slowly increase the amount of memory they are using over time (in what appears to be an unbounded fashion). Generally this is about 0.5 MB per second. On my machine the cube example starts at around 10 MB. I left for a bit and came back to it using over 200 MB.

I did some memory profiling by setting the allocator to jemalloc (from the jemallocator crate) with the profiling feature enabled.

I ran the example with this command and let it run for a bit:

env _RJEM_MALLOC_CONF="prof_leak:true,lg_prof_sample:0,prof_final:true" JEMALLOC_SYS_GIT_DEV_BRANCH=1 cargo run --example cube

This dumped a *.heap file (attached), which i converted to a pdf (also attached) using the following command;

jeprof --show_bytes target/debug/examples/cube jeprof.2090320.0.f.heap --pdf > out.pdf

This seems to point to wgpu_render_pass_set_pipeline generating the memory (specifically a call to RawPass.ensure_extra_size)
image

jeprof.2090320.0.f.heap.txt
out.pdf

@kvark
Copy link
Member

kvark commented May 6, 2020

Thank you for filing this!
I believe this is a regression from #281
Will fix ASAP.

@cart
Copy link
Contributor Author

cart commented May 6, 2020

Thats good news 😄. I have another (extremely nasty) memory leak that only surfaces in a multi-threaded context. I'm hoping fixing this issue also fixes that one.

@cart
Copy link
Contributor Author

cart commented May 6, 2020

Repro for the multi-threaded issue here: https://github.com/cart/wgpu-rs/tree/multi-threaded-leak
It adds crossbeam_util::thread / crossbeam_channel to the cube example.

It leaks in the hundreds of MBs within seconds.

@cart
Copy link
Contributor Author

cart commented May 6, 2020

and if it helps, here is the jemalloc prof pdf for the multithreaded example (which also has RawPass.ensure_extra_size as the hot spot)

out.pdf

@kvark
Copy link
Member

kvark commented May 6, 2020

Aren't both of these the same?

@bors bors bot closed this as completed in 89ee5bf May 6, 2020
@bors bors bot closed this as completed in #300 May 6, 2020
@cart
Copy link
Contributor Author

cart commented May 6, 2020

The pdfs are slightly different (note the crossbeam function calls).

Your changes fixed the original issue! They also vastly improved app shutdown time (which would sometimes hang for a second when quitting).

Sadly the multi-threaded issue remains. I can still repro it on the branch above (which i rebased onto the latest changes).

Should I open a new issue?

@kvark
Copy link
Member

kvark commented May 6, 2020 via email

@cart
Copy link
Contributor Author

cart commented May 6, 2020

Thanks for the quick response!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants