danyspin97 / wpaperd

Modern wallpaper daemon for Wayland
GNU General Public License v3.0
329 stars 25 forks source link

Waperd slowly uses up Swap space #81

Closed DhruvaSambrani closed 2 months ago

DhruvaSambrani commented 4 months ago

I am not entirely sure if this is the case, but my swap reaches 99% after using wpaperd -d for a while. Killing the daemon and starting it again drops the swap usage back to ~0, until it eventually (over many hours) comes back up.

danyspin97 commented 4 months ago

Hello @DhruvaSambrani and thank you for the report!

I am using ps_mem to see the memory usage and can confirm that it always gets bigger (up to 250Mb in my case). I don't see the RAM filling right away, but I can't exclude that either.

Which version of wpaperd are you running?

DhruvaSambrani commented 4 months ago

It does not fill up right away, only after some time (I'm not really sure how long, I only realize it when apps start to stutter and i have to kill wpaperd). Also, I am not sure why, but the ram doesn't actually fill up for me, only the swap.

❯ wpaperd -V
wpaperd 1.0.1

But it was installed using the wpaperd-git package, whose version is

❯ yay -Q wpaperd-git
wpaperd-git r274.097c911-1
rolflobker commented 3 months ago

Not "slowy" if I run wpaperctl next every second to see how quickly it fills up

There seems to be a big memory issue

Between the first and second times free was run I ran wpaperctl next 30 times

➜  /data free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       6.8Gi       6.1Gi        75Mi       3.0Gi       8.7Gi
Swap:          8.0Gi          0B       8.0Gi
➜  /data free -h

               total        used        free      shared  buff/cache   available
Mem:            15Gi       7.3Gi       5.6Gi        75Mi       3.0Gi       8.2Gi
Swap:          8.0Gi          0B       8.0Gi
➜  /data killall wpaperd

➜  /data free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       4.2Gi       8.7Gi        75Mi       3.0Gi        11Gi
Swap:          8.0Gi          0B       8.0Gi
danyspin97 commented 3 months ago

Hi @rolflobker and @DhruvaSambrani ! That's actually a lot of memory used...

I investigated a bit, there is some memory leaked by the driver (I have an AMD card) which I am not able to pinpoint the source and a fix. Some fellow rust developers suggested to use jemalloc allocator in place of malloc, to reduce memory fragmentation. I have pushed a small commit with it, can you please try again?

rolflobker commented 3 months ago

Just pulled the new commit, uninstalled previous build, created new build and installed that.

Effect of 60 times wpaperctl next :

root@desktop:/proc/668724# free -h --mega
               total        used        free      shared  buff/cache   available
Mem:             16G        3.9G        9.5G        933M        4.6G         12G
Swap:           8.6G        473M        8.1G

root@desktop:/proc/668724# free -h --mega
               total        used        free      shared  buff/cache   available
Mem:             16G        5.0G        8.4G        933M        4.6G         11G
Swap:           8.6G        473M        8.1G

Actual RSS mem used, when running wpaperctl next 300 times (killed previous wpaperd, spawned a new process)

root@desktop:/proc/677289# awk 'BEGIN {i=0} /^Rss/ {i = i + $2} END {print i}' smaps
95868
for run in {1..300}; do wpaperctl next; sleep 1; done
root@desktop:/proc/677289# awk 'BEGIN {i=0} /^Rss/ {i = i + $2} END {print i}' smaps
8465760
root@desktop:/proc/677289# free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi        11Gi       525Mi       897Mi       4.5Gi       3.9Gi
Swap:          8.0Gi       451Mi       7.6Gi

This is on a 1 monitor system by the way, so probably 3 times worse on triple monitor system.

Setting a new wallpaper 300 times is probably a bit much. But I have assigned a keyboard shortcut to wpaperctl next and sometimes swap a few before finding the one I want for a short time. But also with 1 hour delayed slideshow and an uptime of 10 days this will start to really slow down a system.

Makes more sense currently to bind killall wpaperd; wpaperd -d to a key-combo or cron-job :smile:

By the way: I have an NVIDIA card.

danyspin97 commented 3 months ago

That is still a LOT of memory. Can I ask what GPU is currently running? I suspect it to be related to the driver and my implementation not playing along fine.

rolflobker commented 3 months ago
product: GP107 [GeForce GTX 1050 Ti]

$ modinfo $(modprobe --resolve-alias nvidia)

filename:       /lib/modules/6.9.10-200.fc40.x86_64/extra/nvidia.ko
version:        550.100
firmware:       nvidia/550.100/gsp_tu10x.bin
firmware:       nvidia/550.100/gsp_ga10x.bin
➜  /tmp nvidia-smi
Tue Jul 30 12:15:14 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.100                Driver Version: 550.100        CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce GTX 1050 Ti     Off |   00000000:01:00.0  On |                  N/A |
| 38%   43C    P8             N/A /   75W |    1301MiB /   4096MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      1514      G   Hyprland                                      121MiB |
|    0   N/A  N/A      1542      G   Xwayland                                       11MiB |
|    0   N/A  N/A     26785      G   transmission-gtk                               44MiB |
|    0   N/A  N/A    674396      G   /usr/lib64/firefox/firefox                    522MiB |
|    0   N/A  N/A    678771      G   /usr/lib64/firefox/firefox                      3MiB |
|    0   N/A  N/A    678945      G   wpaperd                                       298MiB |
|    0   N/A  N/A    679000      G   alacritty                                      39MiB |
|    0   N/A  N/A    680525      G   ...eoEncoder --variations-seed-version        186MiB |
+-----------------------------------------------------------------------------------------+
AtlasC0R3 commented 3 months ago

Intel HD Graphics user on Fedora and Hyprland. Seems to be the same issue. It takes up large amounts of RAM (being that I'm only running on a 4GB laptop) and clears up when the process is killed. Interestingly, the RAM gets taken up, but no process manager indicates that. I would have suggested to set the wallpaper queue history thing to 1, but that makes no difference. I'm wondering, does wpaperd unload the wallpaper from memory once it's done?

wpaperd_memory_leak.png

rolflobker commented 3 months ago

wpaperd unload the wallpaper from memory once it's done?

That's what I was thinking as well.

Btw: love your wallpaper!

Hellzbellz123 commented 3 months ago

Version: v1.01

paru -Q wpaperd-git 
  wpaperd-git r278.430244a-1 

the most recent git release seems too have the same issue with 4gb mem usage after 72.13 minutes

i have a 3 monitor system wpaperd is set too pick a random wallpaper from a 1gb folder every minute. if i let it sit overnight the ram usage can balloon too 16gb+

ram usage after 171.31 minutes 2024-Aug18-Sun@02-45

danyspin97 commented 2 months ago

This issue has been finally fixed by #86 .