Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Learn to read the source code of vmstat     - Java exception handling mechanism (Programming)

- Hibernate Performance Optimization of EHCache cache (Programming)

- How do you access Dropbox Linux command line (Linux)

- The hash function under OpenSSL (Linux)

- CentOS Linux firewall configuration and Close (Linux)

- Oracle 11g 10g induced into error (Database)

- Emacs install clojure development environment (Linux)

- Linux Regular expressions grep and egrep (Linux)

- Linux system performance analysis and top command ps.pstree Comments (Linux)

- RHEL 5.7 Yum configure local source [Errno 2] No such file or directory (Linux)

- Perl said method B if A judge (Programming)

- Ubuntu comes with gedit editor to add Markdown preview widget (Linux)

- Linux Security Setup Guide (Linux)

- Oracle 12c detailing the new features (Database)

- CentOS 7 Test Marathon start Docker container (Server)

- CentOS 6.5_x64 install Oracle 11g R2 (Database)

- Python kills corresponding process according to pid (Programming)

- Varnish achieve page jump (Server)

- The virtual memory (Linux)

- Django url () function Detailed (Programming)

 
         
  Learn to read the source code of vmstat
     
  Add Date : 2018-11-21      
         
         
         
  vmstat -a command to see the active memory and inactive memory, but what do they mean it?

$ Vmstat-a
procs ----------- memory ------------- swap ------- io ----- system -------- cpu -----
r b swpd free inact active si so bi bo in cs us sy id wa st
1013809631956013724081757848002323109900
Their meaning in manpage only gave a simple explanation, did not explain in detail:

inact: the amount of inactive memory (-a option).
active: the amount of active memory (-a option).

Here we try to understand exactly what it means. Vmstat by reading the source code (vmstat.c and proc / sysinfo.c) that, vmstat command is taken directly from the / proc / meminfo data:

$ Grep-i act / proc / meminfo
Active: 1767928 kB
Inactive: 1373760 kB
The / proc / meminfo data is generated in the following core functions:

fs / proc / meminfo.c:
==================
0023staticint meminfo_proc_show (struct seq_file * m, void * v)
0024 {
...
0032unsignedlong pages [NR_LRU_LISTS];
...
0051for (lru = LRU_BASE; lru 0052 pages [lru] = global_page_state (NR_LRU_BASE + lru);
...
0095 "Active:% 8lu kB \ n"
0096 "Inactive:% 8lu kB \ n"
0097 "Active (anon):% 8lu kB \ n"
0098 "Inactive (anon):% 8lu kB \ n"
0099 "Active (file):% 8lu kB \ n"
0100 "Inactive (file):% 8lu kB \ n"
...
0148 K (pages [LRU_ACTIVE_ANON] + pages [LRU_ACTIVE_FILE]),
0149 K (pages [LRU_INACTIVE_ANON] + pages [LRU_INACTIVE_FILE]),
0150 K (pages [LRU_ACTIVE_ANON]),
0151 K (pages [LRU_INACTIVE_ANON]),
0152 K (pages [LRU_ACTIVE_FILE]),
0153 K (pages [LRU_INACTIVE_FILE]),
This code means that all statistical LRU list, which is equal to ACTIVE_ANON Active Memory and ACTIVE_FILE sum, Inactive Memory and INACTIVE_FILE INACTIVE_ANON equal sum.

LRU list is the Linux kernel memory pages to retrieve data structure algorithms (Page Frame Reclaiming Algorithm) used, LRU is an acronym for the Least Recently Used. The core idea of ​​this algorithm is: Recycling page should be the least recently used.

To achieve this goal, the ideal situation is that each page has an age term for recording the last time the page is accessed, but x86 CPU hardware does not support this feature, x86 CPU can do when you visit the page settings a flag Access bit, time can not be recorded.

So Linux kernel uses a compromise approach: It uses the LRU list list to just visited pages on the column header, the closer the end of the column is the longer unvisited pages, so although it can not access the recording time , but the use of the page in the relative positions of the LRU list can easily find the oldest page.

Linux kernel designed two LRU list: active list and inactive list, just visited pages into the active list, not a long time visited pages into the inactive list, this page recovered from the inactive list becomes simple. Kswapd kernel thread periodically the active list in qualifying moved to inactive list in the page, the transfer is done by refill_inactive_zone () completed. This code means that all statistical LRU list, which is equal to ACTIVE_ANON Active Memory and ACTIVE_FILE sum, Inactive Memory and INACTIVE_FILE INACTIVE_ANON equal sum.

LRU_list

vmstat see active / inactive memory on the active list are inactive list and the memory size. If the inactive list is large, indicating that the page can be recovered if necessary a lot; and if the inactive list is small, indicating that the page can be recovered much.

Active / inactive memory for user processes in terms of memory occupied by the kernel memory occupied (including slab) is not among them.

As seen in the source code ACTIVE_ANON and ACTIVE_FILE, respectively anonymous pages and mapped pages. User process is divided into two pages of memory: memory file associated with (such as program files, data files corresponding to the memory pages) and has nothing to do with the file memory (such as process stack, the application memory using malloc), the former is called file pages or mapped pages, the latter known as anonymous pages. In the event of paging file pages (page-in or page-out) when a read or write from its corresponding file; anonymous pages when paging occurs, the exchange zone is read / write operations.
     
         
         
         
  More:      
 
- Installation and operation GAMIT software under Linux operating system (Linux)
- Batch kill processes using awk command (Linux)
- CentOS6.5 install SVN & visual management tools iF.SVNAdmin (Server)
- openSUSE 13.1 / 13.2 installation SoundConverter 2.1.2 (Linux)
- Oracle 11g tracking and monitoring system-level triggers to drop misuse (Database)
- Linux Creating a new user error Creating mailbox file: File exists (Linux)
- Archive log file size and redo log file size relationship (Database)
- Use Observium to monitor your network and servers (Server)
- CentOS iptables firewall enabled (Linux)
- Linux operation and maintenance of the actual file system, file links (Linux)
- cat command uses the Linux redirection merge files (Linux)
- Oracle bug Ora-04043 (Database)
- CentOS 6.x and CentOS7 install MPlayer (Linux)
- After installing Ubuntu 15.04, to do a few things (Linux)
- MySQL 5.6.12 binary log path switching binlog (Database)
- 5 tips to improve your Linux desktop security (Linux)
- Linux use chattr and lsattr commands to manage file and directory attributes (Linux)
- OpenGL ES 3.0 vertex buffer (Programming)
- Hadoop virtualization performance comparison and tuning experience (Server)
- 10 Best Swift Tutorial examples (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.