Task_statm reflects virtual memory and physical memory

Source: Internet
Author: User

In Linux, a function called task_statm is used to return the memory usage of a process.

Int task_statm (struct mm_struct * Mm, int * shared, int * text,

Int * data, int * resident)

{

* Shared = get_mm_counter (mm, file_rss );

* Text = (page_align (Mm-> end_code)-(Mm-> start_code & page_mask ))

> Page_shift;

* Data = mm-> total_vm-mm-> shared_vm;

* Resident = * shared + get_mm_counter (mm, anon_rss );

Return mm-> total_vm;

}

The aboveCodeShared is the number of pages in the physical memory actually used in the page cache. Text is the number of pages occupied by the code, and data is the total number of pages in the virtual memory minus the number of pages in the shared virtual memory, resident is the number of pages of all physical memory in use. The returned mm-> total_vm is the addressing space of the virtual memory of the process.

The get_mm_counter function does not perform any calculations. It is used to ensure the atomicity of Data Reading.

The preceding value is finally output to/proc/$ PID/statm through procfs. The relationship between them and the value displayed on top is as follows.

SHR: shared

Res: Resident

Virt: Mm-> total_vm

Code: Code

Data: Data

Original article:

Http://wenku.baidu.com/view/1cb3338683d049649b6658a3.html ### 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.