Linux check what is swapping

How to check the content of swap memory in Linux?

I am trying to find out what exactly uses swap memory in my system. Free reports over 5GB of used swap memory, but all processes use only 24MB of swap. I suspect that swap might be used by a tmpfs filesystem, but I don’t know how to check it. Would you be so kind to tell what else should I check to examine content of the swap memory, please?

 # free -m total used free shared buffers cached Mem: 48206 47688 518 8177 10 11789 -/+ buffers/cache: 35888 12317 Swap: 15999 5378 10621 
# grep "VmSwap:" /proc/*/status | awk ' END ' 23.8438 MB # grep "VmSwap:" /proc/*/status | grep -v " 0 kB" /proc/1/status:VmSwap: 52 kB /proc/27714/status:VmSwap: 956 kB /proc/27718/status:VmSwap: 948 kB /proc/27722/status:VmSwap: 820 kB /proc/27723/status:VmSwap: 804 kB /proc/27724/status:VmSwap: 812 kB /proc/27725/status:VmSwap: 804 kB /proc/29636/status:VmSwap: 760 kB /proc/29640/status:VmSwap: 960 kB /proc/29642/status:VmSwap: 1948 kB /proc/29643/status:VmSwap: 936 kB /proc/29647/status:VmSwap: 1624 kB /proc/29649/status:VmSwap: 872 kB /proc/3750/status:VmSwap: 116 kB /proc/3770/status:VmSwap: 228 kB /proc/3790/status:VmSwap: 260 kB /proc/3810/status:VmSwap: 444 kB /proc/3823/status:VmSwap: 164 kB /proc/4022/status:VmSwap: 2296 kB /proc/4037/status:VmSwap: 640 kB /proc/4049/status:VmSwap: 572 kB /proc/4058/status:VmSwap: 592 kB /proc/4068/status:VmSwap: 260 kB /proc/4081/status:VmSwap: 192 kB /proc/4095/status:VmSwap: 56 kB /proc/4110/status:VmSwap: 76 kB /proc/4112/status:VmSwap: 80 kB /proc/4114/status:VmSwap: 76 kB /proc/4116/status:VmSwap: 80 kB /proc/4118/status:VmSwap: 80 kB /proc/4120/status:VmSwap: 76 kB /proc/4127/status:VmSwap: 2068 kB /proc/4128/status:VmSwap: 2068 kB /proc/7655/status:VmSwap: 312 kB /proc/7661/status:VmSwap: 380 kB /proc/905/status:VmSwap: 840 kB 
# mount | grep tmpfs tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") 
# cat /proc/meminfo MemTotal: 49363344 kB MemFree: 700676 kB Buffers: 11000 kB Cached: 11822364 kB SwapCached: 522436 kB Active: 37945008 kB Inactive: 4986964 kB Active(anon): 35707220 kB Inactive(anon): 3720092 kB Active(file): 2237788 kB Inactive(file): 1266872 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 16383992 kB SwapFree: 10875936 kB Dirty: 224072 kB Writeback: 0 kB AnonPages: 30580752 kB Mapped: 12218972 kB Shmem: 8328572 kB Slab: 270104 kB SReclaimable: 181768 kB SUnreclaim: 88336 kB KernelStack: 4256 kB PageTables: 91528 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 41065664 kB Committed_AS: 49589524 kB VmallocTotal: 34359738367 kB VmallocUsed: 5203000 kB VmallocChunk: 34327589304 kB HardwareCorrupted: 0 kB AnonHugePages: 5289984 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 31952556 kB DirectMap2M: 17270784 kB DirectMap1G: 1048576 kB 

EDIT:

Problem solved, I found an information that 1372500 pages of shared memory is swapped:

 # ipcs -mu ------ Shared Memory Status -------- segments allocated 32 pages allocated 2752532 pages resident 1380020 pages swapped 1372500 Swap performance: 0 attempts 0 successes # getconf PAGESIZE 4096 # echo $((1372500*4096/1024/1024)) 5361 

Источник

Читайте также:  Using cat on linux

How to Check Swap Memory in Linux: A Comprehensive Guide

Learn how to check swap memory utilization and usage in Linux using various commands, including free, swapon, /proc/swaps, top, vmstat, and sar.

  • Using the free command
  • Using other commands to monitor swap space usage
  • Linux Crash Course — Understanding Memory and Swap Usage
  • Checking swap space on the system
  • Checking swap usage for each process
  • Clearing swap space
  • Other quick code samples for checking Linux swap memory usage
  • Conclusion
  • How to check swap memory in Linux using top?
  • Where is swap memory in Linux?
  • What is the swap memory in Linux?
  • How much memory do I have for swap?

As a Linux user, you might have heard about swap memory. Swap memory is an essential part of Linux systems that helps manage memory usage when physical memory (RAM) is full. In this article, we will discuss various ways to check swap memory in Linux.

Using the free command

The free command is a popular utility that can be used to check memory and swap utilization on the system. It is available on most Linux distributions by default. To check swap memory using the free command, open a terminal window and type the following command:

The -m option is used to display the output in megabytes, making it easier to read. The output of the free command shows the total, used, and free swap memory.

 total used free shared buff/cache available Mem: 985 324 258 36 402 422 Swap: 1023 0 1023 

In the above output, we can see that the total swap memory is 1023 megabytes, and there is no swap memory currently being used.

Читайте также:  Узнать разрядность версии linux

Using other commands to monitor swap space usage

Apart from the free command, there are several other commands that can be used to monitor swap space usage.

The swapon command

The swapon command can be used to enable or disable swap space on the system. To enable swap space, use the following command:

$ sudo swapon /path/to/swapfile 

Replace /path/to/swapfile with the path to the swap file on your system. To disable swap space, use the following command:

$ sudo swapoff /path/to/swapfile 

The /proc/swaps file

The /proc/swaps file displays information about the swap space usage. To view the contents of the /proc/swaps file, type the following command:

The output will show the path of the swap file or partition along with the size, used, and priority.

Filename Type Size Used Priority /dev/sda2 partition 2097148 0 -2 

The top command

The top command shows the current swap space usage by each process. To launch the top command, type the following command:

Once the top command is launched, press the f key to select the fields to display. Use the arrow keys to move down to the SWAP field and press the d key to enable it. The top command will now display the swap space usage by each process.

The vmstat and sar commands

The vmstat and sar commands provide detailed information about the memory and swap usage. To use the vmstat command, type the following command:

The output will show the total swap space size and the amount of swap space used.

 2097148 K total swap space 0 K used swap space 2097148 K free swap space 1048576 K total high memory 350252 K used high memory 698324 K free high memory 

To use the sar command, type the following command:

Читайте также:  Установка etcher linux mint

The output will show the swap space usage for each minute.

Linux Crash Course — Understanding Memory and Swap Usage

Checking swap space on the system

To view the swap space on the system, use the swapon —show command. This command shows the path of the swap file or partition along with the size, used, and priority.

$ swapon --show NAME TYPE SIZE USED PRIO /dev/sda2 partition 2G 0B -2 

The location of the swap space can also be checked using the cat /proc/swaps or swapon -s command.

Checking swap usage for each process

The Swap column in /proc/[PID]/smaps shows the amount of swap space used by each process. To check the size and current usage of swap space, use the following command:

$ grep SwapTotal /proc/meminfo 

The output will show the total swap space size and the amount of swap space used.

SwapTotal: 2097148 kB SwapFree: 2097148 kB SwapCached: 0 kB 

Clearing swap space

Swap space can be cleared using the swapoff command. The command disables all swap space on the system.

Other quick code samples for checking Linux swap memory usage

In Shell , for instance, how to free swap memory in linux code sample

sudo swapoff -a; sudo swapon -a

In Shell , for example, how to check swap memory in linux code sample

Conclusion

Swap memory is an important aspect of Linux systems that helps manage memory usage when RAM is full. Various commands can be used to check swap memory utilization and usage in Linux. It is essential to monitor swap space usage and ensure that it does not affect system performance. Best practices suggest setting up appropriate swap space during the operating system installation and avoiding disabling it unless necessary. With the knowledge gained from this article, you can now effectively monitor and manage swap memory on your Linux system.

Источник

Оцените статью
Adblock
detector