User Tools

Site Tools


linux:linux_memory_swap

Linux Swap and memory

List memory inuse

You can use free [-h|-k|-m|-g]

opensuse:~ # free -h
              total        used        free      shared  buff/cache   available
Mem:           15Gi        10Gi       1.2Gi       1.4Gi       3.9Gi       3.4Gi
Swap:           9Gi          0B         9Gi
opensuse:~ # free
              total        used        free      shared  buff/cache   available
Mem:       16289016    10924400     1259800     1440724     4104816     3600328
Swap:      10485756           0    10485756

Memory available

opensuse:~ # cat /proc/meminfo 
MemTotal:       16289016 kB
MemFree:         1077280 kB
MemAvailable:    3419608 kB
Buffers:          141848 kB
Cached:          3983768 kB
SwapCached:            0 kB
...

Swap available

opensuse:~ # swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       10485756        0       -1
opensuse:~ # cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       10485756        0       -1

Clear / clean swap

Clear PageCache only (more safe for ptoduction)

# sync; echo 1 > /proc/sys/vm/drop_caches

Clear dentries and inodes.

# sync; echo 2 > /proc/sys/vm/drop_caches

Clear PageCache, dentries and inodes.

# sync; echo 3 > /proc/sys/vm/drop_caches 

Another way

If you want to clear Swap space, you may like to run the below command.

# swapoff -a && swapon -a
linux/linux_memory_swap.txt · Last modified: 2021/02/11 16:35 by manu