[LINUX] The story of misreading the swap line of the top command


I sometimes check the memory usage of VPS with the top command etc. (Bottom is from Ubuntu 18.04 LTS)

top - 13:40:39 up  1:44,  0 users,  load average: 0.52, 0.58, 0.59
Tasks:   5 total,   1 running,   3 sleeping,   1 stopped,   0 zombie
%Cpu(s):  3.6 us,  5.6 sy,  0.0 ni, 88.6 id,  0.0 wa,  2.2 hi,  0.0 si,  0.0 st
KiB Mem :  8290600 total,  2456796 free,  5604452 used,   229352 buff/cache
KiB Swap: 25165824 total, 25094400 free,    71424 used.  2552416 avail Mem

    1 root      20   0    8304    136    108 S   0.0  0.0   0:00.10 init
    4 kitakou   20   0   17620   2020   1492 T   0.0  0.0   0:04.10 top
    5 root      20   0    8308    100     60 S   0.0  0.0   0:00.00 init
    6 kitakou   20   0   16788   3396   3312 S   0.0  0.0   0:00.09 bash
   10 kitakou   20   0   17620   2032   1500 R   0.0  0.0   0:00.03 top

I mainly check the real memory and swap area on the 4th and 5th lines, but the rightmost value of the line related to swap, which is displayed as cached or avail Mem depending on the environment. here ** "What is the cache in the swap area ...? Why is it called avail Mem ...?" ** The question arose. Since the cache area is released according to the request of other applications, if there is a certain amount of cache area in the swap area as well, the lack of main memory can be compensated, so ** it is not a preferable state, but ** it works for the time being. (Because the processing speed has dropped when moving to the swap area in the first place)

However, this time, the question "Why is the cache area for speeding up in the slow swap area ...?" ** appears. Even if I looked at multiple articles, it was described as "cached swap area" etc. and it became Rin Nyapi ..., but since it has finally been resolved, I would like to summarize the results of various investigations.


** It was not a value on the swap area in the first place ** The values in memory of the top command are divided as shown in the figure below. image.png The blue part is the value on the physical memory, and the yellow part is the value related to the virtual memory (that is, the swap area). If you check with the man top command,

 2c. MEMORY Usage
       This portion consists of two lines which may express values in kibibytes (KiB) through exbibytes (EiB) depend‐
       ing on the scaling factor enforced with the 'E' interactive command.

       As a default, Line 1 reflects physical memory, classified as:
           total, free, used and buff/cache

       Line 2 reflects mostly virtual memory, classified as:
           total, free, used and avail (which is physical memory)

       The avail number on line 2 is an estimation of physical memory available for starting new applications,  with‐
       out  swapping.   Unlike  the  free field, it attempts to account for readily reclaimable page cache and memory
       slabs.  It is available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free.

It is certainly supplemented with (which is physical memory). But that's hard to understand! !! !! !! !! !! !! !! !! !! If it's written on the swap line, you'd think it's about the swao area! !! !! !! !!

Sites that were taken care of

https://piro.sakura.ne.jp/latest/blosxom/topics/2018-11-13_top-cached.htm It fits the case at the end of the above site insanely ... I want to keep in mind that I can check multiple articles and not be afraid of English ...

Recommended Posts

The story of misreading the swap line of the top command
The story of sys.path.append ()
The story of stopping the production service with the hostname command
The story of building Zabbix 4.4
[Apache] The story of prefork
Check the operating status of the server with the Linux top command
The story of Python and the story of NaN
The story of participating in AtCoder
The story of the "hole" in the file
Hit the top command with htop
The story of remounting the application server
The story of writing a program
Keep getting RSS on the command line
The story of trying to reconnect the client
The story of making a university 100 yen breakfast LINE bot with Python
The story of verifying the open data of COVID-19
The story of adding MeCab to ubuntu 16.04
The story of making Python an exe
The story of making an immutable mold
The story of manipulating python global variables
Migemo version of the: find command,: mfind
The story of trying deep3d and losing
top command
The story of deciphering Keras' LSTM model.predict
The story of blackjack A processing (python)
The story of pep8 changing to pycodestyle
You search commandlinefu on the command line
Notice the completion of a time-consuming command
Introduction of SoftLayer Command Line Interface environment
Get only the source code of the PyPI package with pip from the command line
The story of making a Line Bot that tells us the schedule of competitive programming
The story of doing deep learning with TPU
Summary of tools used in Command Line vol.8
Arduino development on the command line: vim + platformio
Image processing? The story of starting Python for
Summary of tools used in Command Line vol.5
The story of making a lie news generator
The story of finding the optimal n in N fist
Syntax highlighting on the command line using Pygments
Linux: Understand the information displayed by the top command
The story of reading HSPICE data in Python
The story of trying Sourcetrail × macOS × VS Code
The story of viewing media files in Django
Convert XLSX to CSV on the command line
The story of making a mel icon generator
Operate Route53 on the command line using AWS-CLI.
[Small story] Download the image of Ghibli immediately
The story of moving from Pipenv to Poetry
Think about the selective interface on the command line
See here for the amount of free memory of the free command
How to create an article from the command line
The story of launching a Minecraft server from Discord
A story that reduces the effort of operation / maintenance
Gradually display the output of the command executed by subprocess.Popen
The story of Python without increment and decrement operators.
The story of replacing Nvidia GTX 1650 with Linux Mint 20.1.
The story of building the fastest Linux environment in the world
The story of Hash Sum mismatch caused by gcrypto20
Let's clear the ambiguity of the hyphen (-) of the su command now! !!
The story of sharing the pyenv environment with multiple users
Python --Explanation and usage summary of the top 24 packages