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 ###