Thursday 4 January 2018

Kubuntu 17.10 and Plasma 5 memory problems - solution?

For a couple of years now I have been trying to find a way to move to a version of KDE using the latest Plasma desktop.  I have had to revert to earlier releases using Plasma 4.x because every time I used a release with Plasma 5.x I would end up with a crashed system after a few hours, with plasmashell and some indexing processes eating up all available RAM and even most of my swap space.

At last, after tracking down and disabling most of the indexing, I thought I had the problem sorted, but all it did was slowed the gradual increase of RAM use.  Even with a clean boot and NO programs running today, my RAM use went from around 1.2GB to 7.2GB, whole I was out shopping for a couple of hours.

This was the amount of RAM used by 'plasmashell' (basically the main part of the KDE desktop) when I rebooted the computer.  Then I went out to get some medication and food.


I left the computer with NO user programs loaded other than the system monitor.
Plasmashell was using about 70KB of RAM and my entire system was using about 900MB of RAM and about 8.5MB out of 16GB of swap file.

 I came back an hour or two later and looked at the system monitor.  What I found on my return is shown below.


Still only a tiny bit (7.3MB) of swap used, but a whopping 4.5GB of my RAM was being used by plasmashell (the KDE desktop).

Now, bear in mind that I had not opened any other windows or programs.  I had simply left the computer turned on when I went out.

I killed plasma, and restarted it, and my RAM in use when back to about 1.2GB.  I opened Chromium web browser and Dolphin and a few other things and got my RAM use up to a bit over 2GB, then closed each program, and RAM stayed at about 2GB.  And it crept up, while I waited.

So I killed and restarted Plasma again.  There is a handy little script for any time you need to restart Plasma without rebooting Linux.  Simply type this into a terminal and press ENTER:

kquitapp5 plasmashell && kstart plasmashell

By this time I was bloody annoyed and started searching Google yet again.  I had already found the indexing problem and confirmed it was an issue.  But this was something else.  Eventually I came across some discussions among the developers and maintainers of Plasma5 regarding memory leaks.

It seems that some 'plasmoids', little applications that do small jobs within the Plasma shell, can leave bits of themselves in RAM when they refresh.  Effectively I suppose they sort of shut down, leaving a bit of themselves in memorym then when they restart, they load a full version of themselves, then leave a little bit of themselves again, thus building up a stash of useless 'dead' code in RAM each time.

And one of the worst offenders seemed to be the plasmoid that draws a little picture slideshow on the desktop so you can see slides from your pictures folder or elsewhere.  But I don't use that, so I kept digging and found...

Slideshow Wallpaper!!

Yep, this is built in to KDE and allows you to set a folder of images as wallpaper and have it change at an interval you choose.  Anything from seconds to hours between changes.  I had the slideshow set to change images each 30 seconds on one of my 'Activities'.  Now, Activities are what Plasma 5 wants us to use instead of the 'Virtual Desktops' we had in Plasma 4.

The problem is, that in KDE with Plasma 4, Virtual Desktops worked perfectly and Activities worked perfectly.  Then some dickhead decided to 'fix' them.  And neither has worked properly since!

Anyway, I found the Activity that was set for a Slideshow Wallpaper and changed it to a single image.  I've been running the system continuously for some hours since then and my system monitor shows the result below, even with Chromium open so I can type this post..


Chromium Browser however is another program that doesn't play nicely with Plasma 5, and if I keep it open, opening and closing new tabs will gradually add more and more to the amount of RAM being used.  It is now around 1.7GB, but in an hour or two it will be up around 2.5GB.

Fortunately I used that little terminal script to create a shell script to kill and restart plasma, made it executable, and dragged it to my Panel.  I can now restart Plasma desktop with a single click.

!#/bin/bash
# Restart Plasma 5.x to free up memory. 
# Copy this script to the Panel. 
#Change the icon once it is there,
#for convenience.
kquitapp5 plasmashell && kstart plasmashell



No comments:

Post a Comment