3

I have 16G RAM, and 8G swap partition. I'm running Unity 17.04. I have a problem where my buff/cache goes to 11M, and my swap used goes to around 3500. Previously I almost never used any swap space, and I've never monitored the buff/cache.

I believe that it's an application with a memory leak, but I could be wrong.

Simple question. Is there any easy way to determine with application/process is, or has been, using swap?

enter image description here

3
  • 1
    One other possibility is that vm.swappiness might be set high, which can push things into swap if the OS thinks it won't need them for a long time, even if there's plenty of open RAM. May 28, 2017 at 1:13
  • @ChaiT.Rex hum... I wonder... pre 17.04 I had vm.swappiness=10... but after I upgraded to 17.04 I set it back to the default of 60. I wonder if that's about the time that I noticed this? I may have to set it back and see what happens. Thanks!
    – heynnema
    May 28, 2017 at 1:40
  • @ChaiT.Rex well, I played with vm.swappiness, and finally settled on =10 again, like it was before. My buff/cache usage is still 11-12G after a few days, but I guess that's normal, as long as the avail Mem stays high. If you make your comment into an answer, I can vote/accept it.
    – heynnema
    Jun 5, 2017 at 14:04

1 Answer 1

6

You can find that how much does special process uses swap partition by this command :

cat /proc/"PID"/status | grep "^VmSwap"

And you can find PID by this command:

ps -A | grep "Application_name"

But if you want to find which processes are using the swap partition, you can use this script:

#!/bin/bash
for i in /proc/*/status ; do
    vmswap=$(cat $i | grep "^VmSwap")
    echo "$vmswap" | grep -qv ' 0 kB'
    if [ $? == 0 ] && [ "$vmswap" != "" ] ; then
        echo "$i : $vmswap"
    fi
done

Then you can find the application name from its PID that's returned by the script.

Update: I changed this script to create log file every 10 second (you can change the time) and in that file you can see many processes from the moment you run this script up to now:

#!/bin/bash
counter=1
touch ~/swap_process_usage.log
while true ; do
    echo -e "************************************\nSwap's process in count $counter " >> ~/swap_process_usage.log
    for i in /proc/*/status ; do
        vmswap=$(cat $i | grep "^VmSwap")
        echo "$vmswap" | grep -qv ' 0 kB'
        if [ $? == 0 ] && [ "$vmswap" != "" ] ; then
            pid=$(echo "$i" | tr -d /proc/ | tr -d status)
            proc_name=$(ps -p $pid -o comm=)
            echo "$proc_name : $pid : $vmswap" >> ~/swap_process_usage.log
        fi
    done
    sleep 10s
    counter=$((counter+1))
done

And you can set this script to run at startup so it creates log every time.

9
  • Thanks! I'll give it a try as soon as my swap creeps up again. I'll come back and vote/accept then.
    – heynnema
    May 28, 2017 at 0:06
  • My swap crept up again, and I tried your script (and another one that I found) and both reported back nothing. It seems like they may only report if the process is currently active and currently using swap? +1 vote. I'm currently retrying vm.swappiness setting.
    – heynnema
    May 31, 2017 at 13:42
  • @heynnema Thanks for your reply. yes this script shows that which process uses your swap partition , because you said that " Is there any easy way to determine with application/process is, or has been, using swap?" But if your swap is not be used this script isn't be helpful and reported back nothing . Is your swap used ? May 31, 2017 at 14:12
  • Yes, I tried the script when it showed swap partition usage. I'm guessing that if swap usage is not currently actively used, the scripts report nothing. In other words, the scripts won't show what used swap in the past, if there's no current activity.
    – heynnema
    May 31, 2017 at 14:19
  • @heynnema Thanks for your reply. I've changed my script to shows the past swap process. Please try this script May 31, 2017 at 16:00

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.