Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #3561

Closed
SalsaGal opened this issue Mar 6, 2023 · 11 comments
Closed

Memory leak #3561

SalsaGal opened this issue Mar 6, 2023 · 11 comments
Labels
type: bug Something isn't working

Comments

@SalsaGal
Copy link

SalsaGal commented Mar 6, 2023

Description
Program uses more and more memory as it runs, probably a memory leak. Anywhere from a few times a second
to once every few seconds another allocation is made. Upon trying to find problems through strace and lldb it seems to
be related to TextureTrackers. I have attempted this on a Windows machine and it doesn't happen, so I
believe this may be a Wayland specific bug.

Repro steps
Running any WGPU examples causes this to happen.

Expected vs observed behavior
The memory usage should be stable since there is nothing being loaded, and this behavior is observed on Windows,
but missing on Wayland.

Extra materials
Stack trace of the brk system call that was repeatedly allocating memory:

* thread #1, name = 'juice', stop reason = breakpoint 1.1
    frame #0: 0x00007ffff7c84410 libc.so.6`brk
    frame #1: 0x00007ffff7c844e5 libc.so.6`__sbrk + 149
    frame #2: 0x00007ffff7c1af06 libc.so.6`__default_morecore + 22
    frame #3: 0x00007ffff7c1be9a libc.so.6`___lldb_unnamed_symbol3628 + 1178
    frame #4: 0x00007ffff7c1d0af libc.so.6`___lldb_unnamed_symbol3629 + 3679
    frame #5: 0x00007ffff7c1d8ed libc.so.6`malloc + 157
    frame #6: 0x0000555556bb0e3c juice`alloc::alloc::Global::alloc_impl::hcbffc166a09f30b2 [inlined] alloc::alloc::alloc::h3b2850c9340fb196 at alloc.rs:95:14
    frame #7: 0x0000555556bb0dfa juice`alloc::alloc::Global::alloc_impl::hcbffc166a09f30b2(self=0x00005555589fc6b8, layout=Layout @ 0x00007ffffffed390, zeroed=false) at alloc.rs:177:73
    frame #8: 0x0000555556bb1729 juice`_$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Allocator$GT$::allocate::h1889aa39275a2d66(self=0x00005555589fc6b8, layout=Layout @ 0x00007ffffffed5c8) at alloc.rs:237:9
    frame #9: 0x0000555556bb007c juice`alloc::raw_vec::finish_grow::h49becb591faa655a(new_layout=Result<core::alloc::layout::Layout, core::alloc::layout::LayoutError> @ 0x00007ffffffed6d8, current_memory=Option<(core::ptr::non_null::NonNull<u8>, core::alloc::layout::Layout)> @ 0x00007ffffffed890, alloc=0x00005555589fc6b8) at raw_vec.rs:469:9
    frame #10: 0x0000555556bb0954 juice`alloc::raw_vec::RawVec$LT$T$C$A$GT$::grow_amortized::h6b756de6aae66c41(self=0x00005555589fc6b8, len=0, additional=25774) at raw_vec.rs:400:19
    frame #11: 0x0000555556a36b48 juice`alloc::raw_vec::RawVec$LT$T$C$A$GT$::reserve::do_reserve_and_handle::h8f428ed23f5e9961(slf=0x00005555589fc6b8, len=0, additional=25774) at raw_vec.rs:285:28
    frame #12: 0x0000555556a367e6 juice`alloc::raw_vec::RawVec$LT$T$C$A$GT$::reserve::hbc0f1aa3da488ff3(self=0x00005555589fc6b8, len=0, additional=25774) at raw_vec.rs:289:13
    frame #13: 0x0000555556ac6ecb juice`alloc::vec::Vec$LT$T$C$A$GT$::reserve::h9d5c62f1545392b2(self=0x00005555589fc6b8, additional=25774) at mod.rs:907:9
    frame #14: 0x0000555556abd9b6 juice`alloc::vec::Vec$LT$T$C$A$GT$::extend_with::hccb6bfa3ac419ee5(self=0x00005555589fc6b8, n=25774, value=(__0 = 4294967295)) at mod.rs:2499:9
    frame #15: 0x0000555556ac6bee juice`alloc::vec::Vec$LT$T$C$A$GT$::resize::h49a5eb94c8c277b2(self=0x00005555589fc6b8, new_len=25774, value=4294967295) at mod.rs:2365:13
  * frame #16: 0x0000555556756f37 juice`wgpu_core::track::metadata::ResourceMetadata$LT$A$GT$::set_size::h2622e711ba26ab0b(self=0x00005555589fc680, size=25774) at metadata.rs:52:9
    frame #17: 0x00005555566afd99 juice`wgpu_core::track::texture::TextureTracker$LT$A$GT$::set_size::h8cc5c8440725c4f9(self=0x00005555589fc680, size=25774) at texture.rs:439:9
    frame #18: 0x00005555565489e0 juice`wgpu_core::track::Tracker$LT$A$GT$::set_size::he57fcbe0d0878c9b(self=0x00005555589fc3b8, buffers=Option<&wgpu_core::hub::Storage<wgpu_core::resource::Buffer<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::resource::Buffer<wgpu_hal::empty::Api>>>> @ 0x00007ffffffedd30, textures=Option<&wgpu_core::hub::Storage<wgpu_core::resource::Texture<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::resource::Texture<wgpu_hal::empty::Api>>>> @ 0x00007ffffffedd38, views=Option<&wgpu_core::hub::Storage<wgpu_core::resource::TextureView<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::resource::TextureView<wgpu_hal::empty::Api>>>> @ 0x00007ffffffedd40, samplers=Option<&wgpu_core::hub::Storage<wgpu_core::resource::Sampler<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::resource::Sampler<wgpu_hal::empty::Api>>>> @ 0x00007ffffffedd48, bind_groups=Option<&wgpu_core::hub::Storage<wgpu_core::binding_model::BindGroup<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::binding_model::BindGroup<wgpu_hal::empty::Api>>>> @ 0x00007ffffffedd50, compute_pipelines=Option<&wgpu_core::hub::Storage<wgpu_core::pipeline::ComputePipeline<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::pipeline::ComputePipeline<wgpu_hal::empty::Api>>>> @ 0x00007ffffffeddb0, render_pipelines=Option<&wgpu_core::hub::Storage<wgpu_core::pipeline::RenderPipeline<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::pipeline::RenderPipeline<wgpu_hal::empty::Api>>>> @ 0x00007ffffffeddb8, bundles=Option<&wgpu_core::hub::Storage<wgpu_core::command::bundle::RenderBundle<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::command::bundle::RenderBundle<wgpu_hal::empty::Api>>>> @ 0x00007ffffffeddc0, query_sets=Option<&wgpu_core::hub::Storage<wgpu_core::resource::QuerySet<wgpu_hal::vulkan::Api>, wgpu_core::id::Id<wgpu_core::resource::QuerySet<wgpu_hal::empty::Api>>>> @ 0x00007ffffffeddc8) at mod.rs:523:13
    frame #19: 0x00005555565de668 juice`wgpu_core::command::render::_$LT$impl$u20$wgpu_core..hub..Global$LT$G$GT$$GT$::command_encoder_run_render_pass_impl::hcff155d931700938(self=0x0000555558089060, encoder_id=Id<wgpu_core::command::CommandBuffer<wgpu_hal::empty::Api>> @ 0x00007ffffffee910, base=BasePassRef<wgpu_core::command::draw::RenderCommand> @ 0x00007fffffff7720, color_attachments=(data_ptr = 0x0000555558f11db0, length = 1), depth_stencil_attachment=Option<&wgpu_core::command::render::RenderPassDepthStencilAttachment> @ 0x00007fffffff76e0) at render.rs:1197:13
    frame #20: 0x00005555565d2b55 juice`wgpu_core::command::render::_$LT$impl$u20$wgpu_core..hub..Global$LT$G$GT$$GT$::command_encoder_run_render_pass::ha09973659494ff9d(self=0x0000555558089060, encoder_id=Id<wgpu_core::command::CommandBuffer<wgpu_hal::empty::Api>> @ 0x00007fffffff7778, pass=0x0000555558f11d70) at render.rs:1123:9
    frame #21: 0x0000555556461999 juice`_$LT$wgpu..backend..direct..Context$u20$as$u20$wgpu..context..Context$GT$::command_encoder_end_render_pass::h2f88a576984e0b16(self=0x0000555558089060, encoder=0x00007fffffff7c40, encoder_data=0x0000555559020570, _pass=0x00007fffffff7c48, pass_data=0x0000555558f11d70) at direct.rs:1915:13
    frame #22: 0x000055555646d58d juice`_$LT$T$u20$as$u20$wgpu..context..DynContext$GT$::command_encoder_end_render_pass::hd6333d9db637a052(self=0x0000555558089060, encoder=0x00007fffffff84e0, encoder_data=&(dyn core::any::Any + core::marker::Send + core::marker::Sync) @ 0x00007fffffff7c60, pass=0x00007fffffff7f08, pass_data=&mut (dyn core::any::Any + core::marker::Send + core::marker::Sync) @ 0x00007fffffff7c78) at context.rs:2660:9
    frame #23: 0x000055555648b88c juice`_$LT$wgpu..RenderPass$u20$as$u20$core..ops..drop..Drop$GT$::drop::haa16b0a7f23078da(self=0x00007fffffff7ef8) at lib.rs:3449:13
    frame #24: 0x00005555557adaa7 juice`core::ptr::drop_in_place$LT$wgpu..RenderPass$GT$::h00f33fa3ab6af23b((null)=0x00007fffffff7ef8) at mod.rs:490:1
    frame #25: 0x00005555557d7818 juice`_$LT$rhachis..renderers..SimpleRenderer$u20$as$u20$rhachis..graphics..Renderer$GT$::render::hcde6ccbcd7335c49(self=0x00007fffffffa078, view=0x0000555558705788, encoder=0x00007fffffff84b8) at renderers.rs:613:5
    frame #26: 0x000055555577b4f6 juice`_$LT$rhachis..postprocess..PostProcess$LT$T$GT$$u20$as$u20$rhachis..graphics..Renderer$GT$::render::h8da0643acc64e9af(self=0x00007fffffff9d40, view=0x00007fffffff8458, encoder=0x00007fffffff84b8) at postprocess.rs:189:9
    frame #27: 0x000055555579bf08 juice`rhachis::graphics::Graphics::render::h498aafd511d2fdb0(self=0x00005555571f7090, renderer=&mut dyn rhachis::graphics::Renderer @ 0x00007fffffff8630) at graphics.rs:94:13
    frame #28: 0x0000555555719d65 juice`_$LT$T$u20$as$u20$rhachis..GameExt$GT$::run::_$u7b$$u7b$closure$u7d$$u7d$::h2f8af88bd50ccaa6(event=Event<()> @ 0x00007fffffff8b88, (null)=0x00007fffffffb0a0, control_flow=0x00007fffffff8e48) at lib.rs:266:27
    frame #29: 0x0000555555725045 juice`winit::platform_impl::platform::sticky_exit_callback::h410655806c331cb7(evt=Event<()> @ 0x00007fffffff9b08, target=0x00007fffffffb0a0, control_flow=0x00007fffffff8e48, callback=0x00007fffffff9d30) at mod.rs:849:9
    frame #30: 0x000055555570b81a juice`winit::platform_impl::platform::wayland::event_loop::EventLoop$LT$T$GT$::run_return::h3feb819efd081a63(self=0x00007fffffffb0a0, callback={closure_env#1}<juice::Main> @ 0x00007fffffff9d30) at mod.rs:529:21
    frame #31: 0x000055555570c7f3 juice`winit::platform_impl::platform::wayland::event_loop::EventLoop$LT$T$GT$::run::h531d1be4083550c2(self=EventLoop<()> @ 0x00007fffffffb0a0, callback=<unavailable>) at mod.rs:222:25
    frame #32: 0x0000555555724e32 juice`winit::platform_impl::platform::EventLoop$LT$T$GT$::run::he808bd3cc96905c1(self=EventLoop<()> @ 0x00007fffffffb9f0, callback={closure_env#1}<juice::Main> @ 0x00007fffffffbc18) at mod.rs:755:56
    frame #33: 0x000055555577f3ca juice`winit::event_loop::EventLoop$LT$T$GT$::run::h0b1bd2aa0bf6511a(self=<unavailable>, event_handler={closure_env#1}<juice::Main> @ 0x00007fffffffdcc0) at event_loop.rs:278:9
    frame #34: 0x00005555557191d1 juice`_$LT$T$u20$as$u20$rhachis..GameExt$GT$::run::h0922c2b40d0e150e(init=GameInit @ 0x00007fffffffe418) at lib.rs:249:9
    frame #35: 0x0000555555733eaf juice`juice::main::h88b0fa44a437f46c at main.rs:12:1
    frame #36: 0x0000555555746ceb juice`core::ops::function::FnOnce::call_once::h11e04a2493bb4ded((null)=(juice`juice::main::h88b0fa44a437f46c at main.rs:12), (null)=<unavailable>) at function.rs:507:5
    frame #37: 0x00005555556fcdee juice`std::sys_common::backtrace::__rust_begin_short_backtrace::h83928945c265779d(f=(juice`juice::main::h88b0fa44a437f46c at main.rs:12)) at backtrace.rs:121:18
    frame #38: 0x00005555557761a1 juice`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h7585c390212421a2 at rt.rs:166:18
    frame #39: 0x0000555556c5255c juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] core::ops::function::impls::_$LT$impl$u20$core..ops..function..FnOnce$LT$A$GT$$u20$for$u20$$RF$F$GT$::call_once::h9ab31282e87f134a at function.rs:606:13
    frame #40: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panicking::try::do_call::h42ddf5b01d0b4bc7 at panicking.rs:483:40
    frame #41: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panicking::try::hfb70320d7386c61a at panicking.rs:447:19
    frame #42: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panic::catch_unwind::h978c9edbad2bb4d4 at panic.rs:137:14
    frame #43: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::h04ede5bd2f26b553 at rt.rs:148:48
    frame #44: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panicking::try::do_call::ha6b9da35a0885c93 at panicking.rs:483:40
    frame #45: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panicking::try::h3325520cab3a642e at panicking.rs:447:19
    frame #46: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d [inlined] std::panic::catch_unwind::h160beec6f047175b at panic.rs:137:14
    frame #47: 0x0000555556c52559 juice`std::rt::lang_start_internal::h79190e3a877a769d at rt.rs:148:20
    frame #48: 0x000055555577617a juice`std::rt::lang_start::h677725c577524831(main=(juice`juice::main::h88b0fa44a437f46c at main.rs:12), argc=1, argv=0x00007fffffffe788, sigpipe='\0') at rt.rs:165:17
    frame #49: 0x0000555555733ede juice`main + 30
    frame #50: 0x00007ffff7bab790 libc.so.6`___lldb_unnamed_symbol3140 + 128
    frame #51: 0x00007ffff7bab84a libc.so.6`__libc_start_main + 138
    frame #52: 0x00005555556f8db5 juice`_start + 37

Platform
I'm on Arch Linux on Wayland and WGPU version 0.15. I'm on the sway window manager.

@SalsaGal
Copy link
Author

SalsaGal commented Mar 7, 2023

It also seems to use memory even faster when it's not currently visible, this might be some weirdness with the sway handles programs that aren't visible?

@teoxoy
Copy link
Member

teoxoy commented Mar 7, 2023

Did you have a chance to try to reproduce it on x11 on the same system?

@SalsaGal
Copy link
Author

SalsaGal commented Mar 7, 2023

I've tried it on another X system without the same result, however I'll try setting it up on my system tonight and let you know.

@SalsaGal
Copy link
Author

Alright, it seems to not be Wayland, just tried it on someone else's computer who has Wayland and it has no problem, so I'm not sure what else it could be. Maybe it's related to my AMD integrated GPU? This issue comes to mind, as it is a problem I also have but haven't tried working out.

@SalsaGal SalsaGal changed the title Memory leak on Wayland Memory leak Mar 10, 2023
@i509VCB
Copy link
Contributor

i509VCB commented Mar 10, 2023

On Intel UHD Graphics (ICL GT1) this leak occurs on Linux as well. This also occurs on my system with a 6700 xt on x11 and wayland. Furthermore forcing gles with WGPU_BACKEND still results in the leak. So this isn't Vulkan either.

The best way I've found to replicate this is to resize the window continuously so that more memory is allocated.

Running ASAN reported this, but it can't seem to figure out where the allocations are coming from: https://gist.github.com/i509VCB/e5d8cb5cf4d84bb8f4f1b93dd975fd55

The Xlib and xcb leaks are probably fine to ignore, although I'd be interested in seeing if those can be cleaned up to

I suspect this may be a memory leak in wgpu.

@SalsaGal
Copy link
Author

It makes sense to be connected to the resizing continuously if it's related to the other bug because it would be recreating the surface constantly when it's timed out right?

@SalsaGal
Copy link
Author

Using PresentMode::Mailbox instead of PresentMode::Fifo seems to slow down the leak and also get rid of the error about the surface timeout, that could be helpful.

@SalsaGal
Copy link
Author

Running with WINIT_UNIX_BACKEND=x11 seems to slow it down but not halt it altogether.

@xXLINK1123Xx
Copy link

I've got the same problem on Windows 10 using vulkan backend with RX 6800. And whats interesting, leaking temporary stops after I resize window and then starts again after like 20-30 secs. DX12 backend works fine but for some reason it uses ~x2 time more memory.

@crabdancing
Copy link

crabdancing commented Jul 16, 2023

I'm seeing very similar symptoms on NixOS on Wayland. GPU is a Radeon RX 6600 XT, with CPU being a AMD Ryzen 9 7900X (with integrated graphics).

EDIT: Unlike @xXLINK1123Xx, the leak is not affected by resizing the window

@jimblandy jimblandy added the type: bug Something isn't working label Jul 3, 2024
@teoxoy
Copy link
Member

teoxoy commented Aug 1, 2024

I think this is the same issue as #5394 (which has been fixed).

If you are still seeing leaks like this on the latest release (v22) please reopen the issue or create a new one.

@teoxoy teoxoy closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants