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 when viewing mpv fullscreen #4662

Closed
pedrocr opened this issue Oct 21, 2019 · 7 comments · Fixed by swaywm/wlroots#1872
Closed

Memory leak when viewing mpv fullscreen #4662

pedrocr opened this issue Oct 21, 2019 · 7 comments · Fixed by swaywm/wlroots#1872
Labels
bug Not working as intended

Comments

@pedrocr
Copy link
Contributor

pedrocr commented Oct 21, 2019

Either sway or mpv are doing something wrong when fullscreen that results in memory being unreclaimed in the kernel. Only killing sway returns the memory to use. Here's how to reproduce:

  • Open a terminal running top and a video file with mpv next to it
  • Notice the "avail Mem" section of top that shows the available memory discounting the buffers that can be easily reclaimed
  • As the video plays that value will remain relatively constant if there's nothing else consuming memory in the system
  • Now make mpv fullscreen for a few seconds and come back. Now the available memory will go down significantly. In my system that was 2GB/hour of video but I'm sure that will vary depending on the video or screen resolution.

Killing mpv does not reclaim the memory but killing sway does. Running mpv with gpu-context=waylandvk seems to fix it or at least reduce it very significantly. I get video tearing with that option though.

At least on my system I can reproduce this at will right now so I can gather more info if wanted.

@pedrocr
Copy link
Contributor Author

pedrocr commented Oct 21, 2019

Instead of top looking up /proc/meminfo seems to work too. When fullscreen MemAvailable goes down because Unevictable grows.

@pedrocr
Copy link
Contributor Author

pedrocr commented Oct 21, 2019

Another evidence of a leak is that when the video is fullscreen something like this:

sudo cat /sys/kernel/debug/dri/0/framebuffer | grep sway | wc -l

shows the number of allocated framebuffers climbing rapidly (100 more in a few seconds).

@emersion emersion added the bug Not working as intended label Oct 21, 2019
@heghe
Copy link
Contributor

heghe commented Oct 22, 2019

I think this bug is related to this line

bo = import_gbm_bo(&drm->renderer, &conn->pending_dmabuf);

After importing the buffer we never destroy it. The import_gbm_bo documentation say that should be freed with destroy_gbm_bo, but we never do this.

@pedrocr
Copy link
Contributor Author

pedrocr commented Oct 22, 2019

There seems to be something specific to how mpv is handling fullscreen that triggers the bug. Fullscreen youtube videos in Firefox don't seem to cause the same issue. I'm using the latest mpv release (0.29.1) as packaged by Ubuntu 19.04.

@ascent12
Copy link
Member

@pedrocr It's definitely a bug on our side; not particularly related to mpv. mpv just happens to be a client that is capable of hitting the direct-scanout optimisation for you.

@heghe Yeah, that'd be it.

emersion added a commit to emersion/wlroots that referenced this issue Oct 22, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
@emersion
Copy link
Member

emersion commented Oct 22, 2019

Can you try swaywm/wlroots#1872?

@pedrocr
Copy link
Contributor Author

pedrocr commented Oct 22, 2019

@emersion from 5 minutes of testing that seems to fix it, thanks. I'm now running that patched version and will keep monitoring to see if there's anything else.

ascent12 pushed a commit to swaywm/wlroots that referenced this issue Oct 22, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
aiqs4 pushed a commit to aiqs4/wlroots that referenced this issue Dec 19, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
aiqs4 pushed a commit to aiqs4/wlroots that referenced this issue Dec 19, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
aiqs4 pushed a commit to aiqs4/wlroots that referenced this issue Dec 19, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
aiqs4 pushed a commit to aiqs4/wlroots that referenced this issue Dec 19, 2019
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
filips pushed a commit to filips/wlroots that referenced this issue Mar 15, 2020
We need to destroy the gbm_bo we imported and drmModeRmFb.

Closes: swaywm/sway#4662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Development

Successfully merging a pull request may close this issue.

4 participants