O que está usando meu espaço de troca?

3

Em uma máquina Debian Linux 3.16, eu tenho 244 MB de espaço de troca usado:

# free -h
             total       used       free     shared    buffers     cached
Mem:           94G        36G        57G       1.9G       3.8G        11G
-/+ buffers/cache:        20G        73G
Swap:         487M       244M       243M

Olhando isso, não consigo encontrar 244 MB usados.

# for file in /proc/*/status ; do grep VmSwap $file; done | sort -nk 2 | tail
VmSwap:        0 kB
VmSwap:        0 kB
VmSwap:        0 kB
VmSwap:        0 kB
VmSwap:        0 kB
VmSwap:        0 kB
VmSwap:        4 kB
VmSwap:       12 kB
VmSwap:       16 kB
VmSwap:       36 kB

E eu tenho apenas 34 MB de SwapCached :

# grep -i swap /proc/meminfo
SwapCached:        34584 kB
SwapTotal:        499708 kB
SwapFree:         249388 kB

O Kernel doc diz sobre isso:

SwapCached: Memory that once was swapped out, is swapped back in but still also is in the swapfile (if memory is needed it doesn't need to be swapped out AGAIN because it is already in the swapfile. This saves I/O)

Como posso saber qual processo está usando meu espaço de troca no meu sistema Linux? Mais precisamente: Onde são consumidos cada um desses 244 MB de swap?

    
por Totor 16.07.2018 / 16:36

2 respostas

1

How can I know which process is using my swap space on my Linux system?

O espaço de troca não é necessariamente usado por processos específicos.

More precisely: Where are consumed each of those 244 MB of swap?

Arquivos armazenados em sistemas de arquivos baseados em tmpfs podem estar usando-os ( tmpfs primeiro usa RAM como back-end mas, para não desperdiçar RAM, pode paginar para os blocos da área de swap que não são usados ativamente). / p>

Verifique a saída de:

df -ht tmpfs
    
por 23.07.2018 / 23:02
2

The /proc/PID/smaps is an extension based on maps, showing the memory consumption for each of the process's mappings. For each of mappings there is a series of lines such as the following:

08048000-080bc000 r-xp 00000000 03:02 13130      /bin/bash
Size:               1084 kB
Rss:                 892 kB
Pss:                 374 kB
Shared_Clean:        892 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:          892 kB
Anonymous:             0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB
VmFlags: rd ex mr mw me dw

Tente

$ for proc in /proc/*;   do cat $proc/smaps 2>/dev/null | awk '/Swap/{swap+=$2}END{print swap "\tKB\t''readlink $proc/exe|awk '{print $1}' ''" }'; done | sort -n | awk '{total+=$1}/[0-9]/;END{print total "\tKB\tTotal"}'


0       KB      /usr/bin/bash
0       KB      /usr/bin/bash
0       KB      /usr/bin/bash
0       KB      /usr/bin/bash
0       KB      /usr/bin/bash
0       KB      /usr/bin/docker-containerd
0       KB      /usr/bin/docker-containerd-shim
0       KB      /usr/bin/docker-containerd-shim
0       KB      /usr/bin/docker-proxy
0       KB      /usr/bin/docker-proxy
0       KB      /usr/bin/docker-proxy
0       KB      /usr/bin/gawk
0       KB      /usr/bin/readlink
0       KB      /usr/bin/sleep
0       KB      /usr/bin/sort
0       KB      /usr/bin/ssh
0       KB      /usr/bin/ssh
0       KB      /usr/bin/ssh-agent
0       KB      /usr/libexec/postfix/pickup
0       KB      /usr/libexec/postfix/qmgr
0       KB      /usr/sbin/atd
0       KB      /usr/sbin/dnsmasq
0       KB      /usr/sbin/dnsmasq
0       KB      /usr/sbin/sedispatch
0       KB      /usr/sbin/sshd
0       KB      /usr/sbin/sshd
28      KB      /usr/sbin/chronyd
32      KB      /usr/sbin/audispd
84      KB      /usr/sbin/avahi-daemon
88      KB      /usr/lib/systemd/systemd-logind
100     KB      /usr/bin/tail
104     KB      /usr/sbin/crond
156     KB      /usr/sbin/avahi-daemon
192     KB      /usr/lib/systemd/systemd-journald
196     KB      /usr/bin/bash
196     KB      /usr/bin/dbus-launch
...
14872   KB      /usr/bin/Xvnc
20048   KB      /usr/lib64/firefox/firefox
40176   KB      /usr/lib64/firefox/firefox
108848  KB      /usr/sbin/mysqld
267144  KB      Total

Isso realmente diz que o mysql está usando mais troca.

$ free -k
              total        used        free      shared  buff/cache   available
Mem:        1883740     1044212      112132       14320      727396      520304
Swap:       2097148      265784     1831364
A saída de

free não parece muito difícil no meu caso

    
por 16.07.2018 / 17:34