0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

アクセシビリティの知見を発信しよう!

スワップの発生状況を確認する方法

Last updated at Posted at 2024-05-30

free

free -h
               total        used        free      shared  buff/cache   available
Mem:           7.5Gi       2.1Gi       599Mi       159Mi       5.3Gi       5.4Gi
Swap:          8.0Gi        10Mi       8.0Gi

top

top -bn1 | grep Swap
MiB Swap:   8192.0 total,   8181.2 free,     10.7 used.   5324.7 avail Mem

/proc/swaps

cat /proc/swaps
Filename				Type		Size		Used		Priority
/dev/sda6               partition	8388604		10748		-2
swapon -s
Filename				Type		Size		Used		Priority
/dev/sda6               partition	8388604		10748		-2

cat /proc/swapsswapon -s または swapon --summary は同じ内容が出力される。

/proc/meminfo

cat /proc/meminfo | grep Swap
SwapCached:         1168 kB
SwapTotal:       8388604 kB
SwapFree:        8378112 kB

sar

sar -W
Linux 5.14.0-362.24.1.el9_3.x86_64 (hostname) 	2024年05月31日 	_x86_64_	(4 CPU)

00時00分00秒  pswpin/s pswpout/s
00時05分00秒      0.16      0.00
00時10分00秒      0.00      0.00
00時15分00秒      0.09      0.07
00時20分00秒      0.00      0.04
00時25分00秒      0.00      0.00
00時30分00秒      0.00      0.02

スワップのプロセスの一覧を表示 (/proc/[0-9]*/status)

find /proc \
 -readable \
 -path "/proc/[0-9]*/status" \
 -maxdepth 2 \
 -exec awk -v FS=":" \
  '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; \
  | awk '{print $(NF-1),$0}' \
  | sort -hr \
  | cut -d " " -f2-
   3035731 /usr/sbin/httpd                              252 kB
   2897954 /usr/sbin/httpd                              252 kB
   3035948 /usr/sbin/httpd                              248 kB
   3035736 /usr/sbin/httpd                              248 kB
   3035735 /usr/sbin/httpd                              248 kB
   3035734 /usr/sbin/httpd                              248 kB
   2903067 auditd                                        40 kB
   2903923 master                                         4 kB
       865 crond                                          4 kB

swappiness

sysctl vm.swappiness
vm.swappiness = 60
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?