1. 程式人生 > >進程的內存使用

進程的內存使用

lse total_vm rect ping writable lag stat direct ati

vm_stat_account

void vm_stat_account(struct mm_struct *mm, vm_flags_t flags, long npages)
{
mm->total_vm += npages;

if (is_exec_mapping(flags))
mm->exec_vm += npages;
else if (is_stack_mapping(flags))
mm->stack_vm += npages;
else if (is_data_mapping(flags))
mm->data_vm += npages;
}

最初這些page都是匿名頁或者是文件頁

239 /*
240 * Executable code area - executable, not writable, not stack
241 */
242 static inline bool is_exec_mapping(vm_flags_t flags) ---- 這裏使用的是文件頁
243 {
244 return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC;
245 }
246
247 /*
248 * Stack area - atomatically grows in one direction
249 *
250 * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous:
251 * do_mmap() forbids all other combinations.
252 */
253 static inline bool is_stack_mapping(vm_flags_t flags) ---- 匿名頁
254 {
255 return (flags & VM_STACK) == VM_STACK;
256 }
257
258 /*
259 * Data area - private, writable, not stack
260 */
261 static inline bool is_data_mapping(vm_flags_t flags)  ---- 匿名頁
262 {
263 return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
264 }

進程的內存使用