Swap Space

I have a CentOS 6.7 64 bit machine having 64GB RAM. When running free command it shows that it is using about 1420 MB of Swap space. My question is how to know which process is using Swap?

# free -m
             total       used       free     shared    buffers     cached
Mem:         64410      60119       4291      14534        426      56235
-/+ buffers/cache:       3456      60953 
Swap:        32271       1420      30851 

Open in new window


Since the machine has good enough RAM I don't think it should need to use Swap.
sysautomationAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andreasSystem AdminCommented:
yum install smem

then

smem

will show you the processes and how much swap they are using.
Shiju JacobInfo Security ManagerCommented:
Hi

try using this script

#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
        PID=`echo $DIR | cut -d / -f 3`
        PROGNAME=`ps -p $PID -o comm --no-headers`
        for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
        do
                let SUM=$SUM+$SWAP
        done
        echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
        let OVERALL=$OVERALL+$SUM
        SUM=0

done
echo "Overall swap used: $OVERALL"



sh new.sh | sort -n -k 5
sysautomationAuthor Commented:
Thanks to both of you. Both the solutions show 0 MB swap usage:

# smem
  PID User     Command                         Swap      USS      PSS      RSS 
# 

Open in new window

But free is still showing 1420 MB.

Any idea why?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

andreasSystem AdminCommented:
Any tmpfs filesystems on your machine? They will also eat up swap.

you can check with
mount
if there are any tmpfs.

With df -k you can check how big they are and how much of it is used.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sysautomationAuthor Commented:
Yes it has tmpfs:

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ce-lv_root
                       50G  3.6G   44G   8% /
tmpfs                  32G   16G   16G  50% /dev/shm
/dev/sda1             477M   64M  388M  15% /boot
/dev/mapper/vg_ce-lv_home
                      689G  107G  548G  17% /home
/dev/mapper/vg_ce-lv_opt
                      886G  236G  606G  29% /opt

Open in new window


But it is saying 16GB used whereas free saying 1420MB use. Why are they different?
andreasSystem AdminCommented:
Maybe only parts of /dev/shm are kept in swap and the rest in memory cache?

But this is just a guess I'm not sure.

But you shouldnt be worfried about your system uses some swap even it has enough memory.

Ressources in swap on systems with a lot of memory are things that were not accessed in a long time. You may adjust the swappiness parameter of the kernel to adjust the swap behaviour of your machine.

more about how to do this here: https://www.howtoforge.com/tutorial/linux-swappiness/
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.