JeffyCN / xorg-xserver

X server with glamor hacks for gles2 and rga based exa
Other
15 stars 23 forks source link

Memory leak #8

Closed avafinger closed 2 years ago

avafinger commented 2 years ago

Hi @JeffyCN

There is a memory leak in xorg that i am trying to hunt down. I have noticed there is a leak of about 1M every ~10 min in idle mode. If you run an intensive opengles2 application you can have a significant amount of memory not released. I have all memory leak fix patches applied.

You can reproduce the leak by running glmark2-es2 and checking with xrestop.

  1. before running glmark2-es2
    
    xrestop - Display: localhost
          Monitoring 20 clients. XErrors: 14
          Pixmaps:   58868K total, Other:      49K total, All:   58917K total

res-base Wins GCs Fnts Pxms Misc Pxm mem Other Total PID Identifier
0c00000 204 30 1 232 728 37982K 23K 38005K 799 xfwm4 0600000 0 0 0 1 0 8100K 0B 8100K ? 1800000 5 22 0 4 39 5784K 1K 5785K 812 Desktop 0000000 2 0 2 0 119 2700K 4K 2704K ? 0e00000 11 3 0 6 171 2304K 4K 2308K 803 debian - File 2200000 19 3 1 10 99 1355K 3K 1359K 851 Terminal - 1000000 10 33 0 2 40 384K 1K 385K 808 xfce4-panel 2600000 7 4 0 2 59 256K 1K 257K 357 *Untitled 1 - 1c00000 7 36 0 2 14 1K 1K 3K 819 wrapper-1.0 1200000 4 1 0 0 99 0B 2K 2K 810 xfsettingsd 1a00000 5 26 0 1 12 4B 1K 1K 821 wrapper-1.0 0400000 10 3 0 0 27 8B 960B 968B 778 Fcitx Tray Win 0800000 2 1 0 0 25 0B 672B 672B 786 xfce4-session 1600000 3 2 0 0 22 4B 648B 652B 824 light-locker 2400000 1 1 0 0 9 0B 264B 264B 803 Thunar 0a00000 1 1 0 0 9 0B 264B 264B 795 xfce4-notifyd 2000000 1 1 0 0 1 0B 72B 72B ? xrestop 1e00000 0 1 0 0 0 0B 24B 24B ? 1400000 0 1 0 0 0 0B 24B 24B ? 0200000 0 0 0 0 0 0B 0B 0B ?


2.  After running glmark2-es2

xrestop - Display: localhost Monitoring 20 clients. XErrors: 14 Pixmaps: 60788K total, Other: 51K total, All: 60840K total

res-base Wins GCs Fnts Pxms Misc Pxm mem Other Total PID Identifier
0c00000 204 30 1 232 736 38175K 23K 38199K 799 xfwm4 0600000 0 0 0 1 0 8100K 0B 8100K ? 1800000 6 22 0 4 40 5784K 1K 5785K 812 Desktop 0e00000 11 3 0 7 173 4031K 4K 4035K 803 debian - File 0000000 2 0 2 0 120 2700K 4K 2704K ? 2200000 21 3 1 10 104 1355K 4K 1359K 851 Terminal - 1000000 10 33 0 2 40 384K 1K 385K 808 xfce4-panel 2600000 7 4 0 2 136 256K 3K 259K 357 *Untitled 1 - 1c00000 7 36 0 2 14 1K 1K 3K 819 wrapper-1.0 1200000 4 1 0 0 99 0B 2K 2K 810 xfsettingsd 1a00000 5 26 0 1 12 4B 1K 1K 821 wrapper-1.0 0400000 10 3 0 0 27 8B 960B 968B 778 Fcitx Tray Win 0800000 2 1 0 0 25 0B 672B 672B 786 xfce4-session 1600000 3 2 0 0 22 4B 648B 652B 824 light-locker 2400000 1 1 0 0 9 0B 264B 264B 803 Thunar 0a00000 1 1 0 0 9 0B 264B 264B 795 xfce4-notifyd 2000000 1 1 0 0 1 0B 72B 72B ? xrestop 1e00000 0 1 0 0 0 0B 24B 24B ? 1400000 0 1 0 0 0 0B 24B 24B ? 0200000 0 0 0 0 0 0B 0B 0B ?



How can this be mitigated? Can you check with your setup?
JeffyCN commented 2 years ago

from your log, it's 'debian - File'?

maybe you can try to test it without desktop manager(stop your dm and run X alone manually)

avafinger commented 2 years ago

Yes, debian.

(stop your dm and run X alone manually)

How to do that?, and can i run any opengles2 client?

avafinger commented 2 years ago

Do you mean run only with window manager? At first glance, i read DRM and not DM...

avafinger commented 2 years ago

@JeffyCN

I did the following experiment:

  1. killed X
  2. open tty1
  3. open ssh session 1
  4. open ssh session 2
  5. from ssh session 1, run htop
  6. from ssh session 2, run sudo xinit glmark2-es2 $* -- :1

Monitored memory consumption, no leaks.

What can we infer from this experiments? xserver is leaking???

JeffyCN commented 2 years ago

11 3 0 7 173 4031K 4K 4035K 803 debian - File

your log shows this app is leaking, not gles clients. so you can try to run the test without that 'debian-File' to confirm

avafinger commented 2 years ago

Ok. That was my mousepad after i pasted the content.

Now i ran glmark2-es2 and left it idle for some time. ~19min and a bit more. /usr/lib/xorg :0 -seat seat0 -auth /var/runt/lightdm/root/:0 -nolisten TCP vt7 -novtswitch is eating some memory (2 MB) but xfce4-terminal seems to be the one who leaks the most (12 MB).

xrestop does not show any leaks, it just takes some time to release the memory. Can you suggest a few steps on how to run only the window manager without removing xcfe4 package, so i can repeat this test?

here is the print screen to show the leaks:

  1. idle 1_xserver_idle

  2. ~20 min later 2_xserver_after_19min_idle

  3. some time later (still idle) 3_some_time_later

Update:

xrestop was/is running in the console, and this is making xfce4-terminal leak or eat memory. i thought there was some kind of circular buffer. Apparently printing info like xrestop does in the console or using printf in a console app is not a good idea. It all started with an app that printed FPS info that sparked this hunting.

Anyway, if you feel the leaks have nothing to do with xserver please close the issue. But i would appreciate if you can give some instructions to run only with window manager so i can repeat this experiments.

JeffyCN commented 2 years ago

stop your dm, for example:/etc/init.d/lightdm stop run X: X&

avafinger commented 2 years ago

killed dm, logged into tty1, and ran X& but got an error: cannot open /dev/tty0 (permission denied)

update: with root, i get a blank screen.

avafinger commented 2 years ago

I couldn't make X work as you advised. Instead, i am running (my way) a camera app that grabs the image and draws it as a texture (opengles2) , though i don't know if xserver is involved since only the client is drawn. i will let it run overnight and see the results tomorrow but seems fine with a few minutes running.

x11_app

JeffyCN commented 2 years ago

killed dm, logged into tty1, and ran X& but got an error: cannot open /dev/tty0 (permission denied)

update: with root, i get a blank screen.

the pure xserver is blank, you can run openbox& to get a window manager and xterm to get a terminal window

JeffyCN commented 2 years ago

and if you confirm there's a memleak in X, you can use valgrind to trace it

avafinger commented 2 years ago

In my way to run the X app described above, xserver is involved?

JeffyCN commented 2 years ago

when drawing a client with gles, it actually calls xserver dri2 api to swap the client window's dri2 buffer, which would let xserver to compose it to the screen pixmap with glamor(gpu) in current setup.

avafinger commented 2 years ago

286M - 278M = 8M memleak somewhere. I could not find the leak with htop, maybe i missed something. If the leak happens to be in mail blob, would that be visible? what you think? next_day_X11_p2

next_day_X11

avafinger commented 2 years ago

Just an update.

I added a memory leak column to watch for possible memory leaks. I found that running an x11 app from xfce4-terminal leaks memory. The memory leak occurs by using any printf function or using ncurses lib.

If you run the x11 app using the x11 launcher there will not be a memory leak. As an experiment, if you open a terminal (xcfe4-terminal) and move the cursor around inside the client area xorg consumes 1K to 2K but later releases this memory.

So, xcfe4-terminal and xcfe4-session are to blame. Don't know if is a bug with debian (i am not really a debian advanced user). I will test xserver with ubuntu and see if leaks. Closing here for failing to determine why it leaks. Possible not Xorg or xserver issue.

Using valgrind on the x11 app finds a 8K memory leak. No matter if run for 10 min or 10 hrs.

Here is a picture of a 12 hrs running htop within xcfe4-terminal and an X11 app also within xcfe4-terminal. ~ 100MB is wasted. mleak2