Closed Bug 1595770 Opened 5 years ago Closed 3 years ago

[Wayland] DMA-BUF leaks on certain events

Categories

(Core :: Graphics: Layers, defect, P3)

Unspecified
Linux
defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: kennylevinsen, Unassigned)

References

(Blocks 1 open bug)

Details

Testing DMA-BUF on Sway with firefox nightly, certain actions are observed to cause drastic increase in system memory consumption. A large amount of the consumed memory is not associated with a process, which suggests that it is the DMA frame buffers themselves.

In my case, after a few hours of light usage, I was spilling over to swap on a system with 64GB of memory. The firefox process was accounting for 30%, with the rest being unaccounted for.

Closing firefox caused memory usage to drop to 2.1GB in a few quick stages.

Reproduction

Note: This was done on a 4k display, which likely significantly increases the rate of leakage due to the sheer size of the frame buffers involved.

  1. Go to youtube.com
  2. Play a video
  3. Repeatedly toggle fullscreen using the video player button.

Each toggle causes an increase in memory consumption. Each toggle pair causes about 500MB increase in system memory consumption for me.

Flags: needinfo?(stransky)
OS: Unspecified → Linux
Priority: -- → P1

I did a little bit of printf debugging in the dmabuf implementation with a simple test where I wiggled the cursor over a window (cursor in, cursor out), which also seem to increase the memory consumption noticably.

  1. We're seemingly allocating a lot.
  2. Due to a lot of spam, I isolated the log output from 3 wiggle passes. Ignoring the countless buffers that were both created and destroyed in this period, the conclusion is that 2 old buffers from before this wiggle were deallocated, but 4 new were left after. Thus, we leak.

Also, to give an idea of how busy the dmabuf allocation is when just moving the cursor over the window, I give here a snippet of my debug log containing only the create/release calls for a single cursor wiggle, with a window size of 1919x755:

 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0fc0]::Create(1919, 755, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1e20]::Create(1919, 755, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::Create(1919, 3, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea17e0]::Create(1870, 54, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1f60]::Create(1870, 54, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24840]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24340]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db247a0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedf60]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd28048e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea12e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8caa240]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24700]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca93e0]::Create(1919, 755, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedf60]::Create(1919, 755, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41700]::Create(1919, 3, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41a20]::Create(1870, 54, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41e80]::Create(1870, 54, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42100]::Create(134, 54, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42380]::Create(134, 54, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1ce0]::Create(1919, 146, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42ba0]::Create(1919, 146, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0f20]::Create(445, 67, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42880]::Create(445, 67, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42ec0]::Create(54, 63, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24980]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41700]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0e80]::Create(1919, 146, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8fa4340]::Create(1919, 1, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd94aaa20]::Create(1919, 146, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd94aaca0]::Create(445, 67, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecdb0743e0]::Create(445, 67, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecdb074c00]::Create(54, 63, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25ba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecdb074f20]::Create(1919, 1, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::Create(1919, 2, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faab45aa920]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8fa4340]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecdb074f20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25ba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8fa4480]::Create(1919, 2, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9e6437e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db664c0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db65ac0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1f60]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25ce0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea17e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9e643d80]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41e80]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faaa155ce20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f41a20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42380]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42100]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca9de0]::Create(113, 45, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25b00]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db254c0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24700]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab45aa2e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1e20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab4398fc0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0fc0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab48a67a0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedf60]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca93e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab4399560]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea1ce0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0e80]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab48a6e80]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab48a6980]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42ba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd94aaa20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab458f3e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42880]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab458f200]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0f20]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecdb0743e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab4d710c0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd94aaca0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8f42ec0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab45a9660]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecdb074c00]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db242a0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca93e0]::Create(113, 45, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0e80]::Create(1919, 3, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25ba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8fa4480]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faab4d71480]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::Create(1919, 3, 3): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db242a0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db25a60]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca9de0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ca93e0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd2804fc0]::Create(1919, 137, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8caa240]::Create(1919, 137, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24840]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0e80]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7faa9db24700]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8cedba0]::ReleaseDMABufSurface()
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea0f20]::Create(1919, 137, 2): Enter
 --- KLDBG: WaylandDMABufSurface[0x7fecd8ea12e0]::Create(1919, 137, 2): Enter

I don't really see why there should be any allocation at all for that action, apart from maybe something related to the cursor surface.

I forgot to mention that this is tested using OpenGL compositing. The Basic compositor does not seem to exhibit this issue. WebRender disabled itself once dmabuf was enabled for some reason, hence why OpenGL compositing was used.

I can confirm this on Mutter (git master).

Note concerning Webrender failing: I do see the same, but from the error message (no matching function for call to `textureSize(samplerExternalOES, int)') it looks like https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2241, which did not yet get backported.

There's no reason to use dmabuf right now as it's slower than shm and also is off by default.
We should fix this when WebGL or video HW decoding uses dmabuf.

Flags: needinfo?(stransky)

I don't believe it's P1 as dmabuf off by default and should not be used right now.

Priority: P1 → P3

Kenny, can you try to enable dmabuf for WebGL (see https://bugzilla.mozilla.org/show_bug.cgi?id=1586696#c19) and test it on some WebGL scene if you still see the issue?
Thanks.

Flags: needinfo?(bugzilla)

Just testing latest nightly, setting only the webgl dmabuf setting during OpenGL compositing, I do not seem to be able to trigger the memory runaway using the same reproduction as I used in this bug. I only did limited testing, though.

During this test, I observed a ~30% boost in performance on https://webglsamples.org/aquarium/aquarium.html, however, the scene is has a yellow tint. Want me to file a bug on that?

Flags: needinfo?(bugzilla) → needinfo?(stransky)

(In reply to Kenny Levinsen :kennylevinsen from comment #7)

Just testing latest nightly, setting only the webgl dmabuf setting during OpenGL compositing, I do not seem to be able to trigger the memory runaway using the same reproduction as I used in this bug. I only did limited testing, though.

During this test, I observed a ~30% boost in performance on https://webglsamples.org/aquarium/aquarium.html, however, the scene is has a yellow tint. Want me to file a bug on that?

Yes please, can you also attach a screenshot of that?
Thanks.

Flags: needinfo?(stransky) → needinfo?(bugzilla)

Opened bug 1617553 for you with screenshots.

Again, this only tested the GL dmabuf setting, not the GL/WebRender dmabuf settings. Give me a heads up if you want those tested as well.

Flags: needinfo?(bugzilla)

Just a heads-up: I tested the full widget.wayland_dmabuf_textures.enabled in the same nightly as the WebGL test, and it still leaks uncontrollably when toggling a YouTube player between fullscreen/non-fullscreen.

(Also, the colors are of course inverted for the compositor due to color channel mix-up.)

Flags: needinfo?(stransky)

Okay, Thanks.

Flags: needinfo?(stransky)

Kenny, is this issue still reproducible for you?

Flags: needinfo?(bugzilla)

widget.wayland_dmabuf_textures.enabled is unsupported feature and it's disabled by default. We have it here just for some dmabuf measurements/performance tests. No need to fix it but we may remove the option from about:config to make sure nobody enables it.

Flags: needinfo?(bugzilla)

I see that widget.wayland_dmabuf_textures.enabled is already removed.

Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.