1

A couple of times recently I've noticed my laptop running a bit slow and the disk light flickering a lot. It's an i7 with SSD and 12GB RAM, so I'm not really expecting much slowness when just browsing.

This last time, it bugged me, so I had a quick peek in System Monitor (KSysGuard) and it was showing my 2GB swap partition to be 100% utilised, but physical memory only at 4.8GB out of 11.6 (which is where the graph goes to). So I thought I'd try to empty the swap by turning it off & on again (swapoff -a, swapon -a) but swapoff failed due to insufficient RAM.

This confused me, as I should have about 7GB spare, according to KSysGuard, so I thought I'd see what top had to say. Top showed about 150MB free RAM and 2048/2048MB swap in use. No wonder it was running a bit slow!

Why would KSysGuard under-report memory usage so much and how can I make it top telling porkies?

9
  • 1
    What version of Kubuntu? The next time it happens, please run top -n 1 -o %MEM | head -20 and post the output here by editing your question. – DK Bose Oct 5 '19 at 15:45
  • I would increase your swap to at least 6G, and modify your vm.swappiness from 60 to 80. Also check for firmware updates for your SSD. – heynnema Oct 5 '19 at 17:22
  • @DKBose, it's Kubuntu 1810. I'll be sure to try your suggestion next time it happens. – flim Oct 5 '19 at 18:55
  • @heynnema, I did think 2GB was a bit small for the swap partition, but that's what the installer set it to, so I figured I'd leave it. I've actually just turned my swappiness down to try to restrict swap usage. Why do you suggest setting it so high? – flim Oct 5 '19 at 18:57
  • With "only" 12G RAM, you DO want it to swap... but to an appropriately sized swap partition or /swapfile. Increasing vm.swappiness does that. – heynnema Oct 5 '19 at 19:00
1

From the comments...

Note: remember that unused RAM is used for file and disk buffers.

The real problem is that your 2G swap space is too small, and your disk is thrashing.

I would increase your swap to at least 6G, and modify your vm.swappiness from the default of 60, to 80.

To test various settings of vm.swappiness, use sudo sysctl vm.swappiness=80. vm.swappiness values greater than the default of 60 make more use of swap. Values less than 60 make more use of RAM.

To make it permanent, edit /etc/sysctl.conf and add vm.swappiness=80 at the end, then reboot.

0

Per the comments, I increased my swap file from 2GiB to 6GiB using the following:

sudo swapoff -a
sudo rm /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1M count=6144
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Respectively, the above commands turn swapping off by moving pages back to physical memory, remove the swap file, create a new 6GiB file called swapfile, set the permissions to root only, configure the file for swap use and finally turn swapping back on with the new file.

I then added vm.swappiness=70 to the end of the penultimate section in /etc/sysctl.conf to make swapping to the page file slightly more aggressive (saving some physical memory).

However, to actually answer the question of why KSysGuard seemed to be lying about the amount of RAM in use, it's because the default "Memory and Swap History" chart actually only shows data from the "Application Memory" sensor. To resolve this, I added a tab called Memory in KSysGuard and included 2 graphs - one for physical memory and one for swap. The physical memory graph has the following sensors configured: Used Memory, Free Memory, Buffer Memory, Cache Memory. Only Used and Cache are really required, but it's the Used metric which tells you how much memory has actually been used.

3
  • Please note that my answer was posted about an hour before your answer, and the comments to which we both refer to came from me about 4 hours before that. I didn't specifically address the KSysGuard bug, but did address the real reason/problem in your question... slow system... and disk thrashing. – heynnema Oct 6 '19 at 3:17
  • Agreed @heynnema. I wasn't sure whether it was appropriate etiquette to mention you in my answer. The only reason I added mine was to answer the "Why do KSysGuard and Top show different numbers" question, which will likely be the reason other users come here. I very much appreciate your input and no offence was intended with my answer. – flim Oct 7 '19 at 18:45
  • It would normally be fine to mention another user in your comments or answer. Since you discuss the KSysGuard work around in your comments above, then your and my answers are virtually the same. Can I respectfully ask you to accept my answer, as it really addresses the problem behind your original question? – heynnema Oct 7 '19 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.