内存管理-31-每进程内存统计-4-/proc/pid/smaps

基于msm-5.4

一、初探

1. 打印格式

# cat /proc/593/smaps
...
7e5a528000-7e5a626000 r--p 00000000 00:1f 5                              /dev/binderfs/hwbinder
Size:               1016 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         4 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Anonymous:             0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:        0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:            0
VmFlags: rd mr dc nr mm
...

注:打印诸多这样的单元,这里只摘抄一个。

打印成员说明:

Size: vma->vm_end - vma->vm_start

KernelPageSize: 若没有使能 CONFIG_HUGETLB_PAGE,则恒打印 PAGE_SIZE 的值。

MMUPageSize: 若没有使能 CONFIG_HUGETLB_PAGE,也恒打印 PAGE_SIZE 的值。

Rss: mss->resident

Pss: mss->pss >> PSS_SHIFT

Shared_Clean: mss->shared_clean

Shared_Dirty: mss->shared_dirty

Private_Clean: mss->private_clean

Private_Dirty: mss->private_dirty

Referenced: mss->referenced

Anonymous: mss->anonymous

LazyFree: mss->lazyfree

AnonHugePages: mss->anonymous_thp

ShmemPmdMapped: mss->shmem_thp

FilePmdMapped: mss->file_thp

Shared_Hugetlb: mss->shared_hugetlb

Private_Hugetlb: mss->private_hugetlb >> 10

Swap: mss->swap

SwapPss: mss->swap_pss >> PSS_SHIFT

Locked: mss->pss_locked >> PSS_SHIFT

THPeligible: 表示透明大页是否使能。

VmFlags: rd mr dc nr mm:打印的是 vma->vm_flags,详见 show_smap_vma_flags()


2. 实现

static const struct pid_entry tgid_base_stuff[] = {
    REG("smaps",      S_IRUGO, proc_pid_smaps_operations),
};
static const struct pid_entry tgid_base_stuff[] = {
    REG("smaps",      S_IRUGO, proc_pid_smaps_operations),
};

static int show_smap(struct seq_file *m, void *v) //proc/task_mmu.c
{
    struct vm_area_struct *vma = v;
    struct mem_size_stats mss;

    memset(&mss, 0, sizeof(mss));

    smap_gather_stats(vma, &mss);

    /* 第一行由这里打印出来的,见对 maps 文件的注释 */
    show_map_vma(m, vma);
    /* 若 vma->anon_name 存在则进行打印,如 [anon:.bss] [anon:stack_and_tls:2129] [anon:scudo:primary] 等*/
    if (vma_get_anon_name(vma)) {
        seq_puts(m, "Name:           ");
        seq_print_vma_name(m, vma);
        seq_putc(m, '\n');
    }

    SEQ_PUT_DEC("Size:           ", vma->vm_end - vma->vm_start);
    SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma));
    SEQ_PUT_DEC(" kB\nMMUPageSize:    ", vma_mmu_pagesize(vma));
    seq_puts(m, " kB\n");

    /* 主要是这个函数进行打印的 */
    __show_smap(m, &mss, false);

    seq_printf(m, "THPeligible:        %d\n", transparent_hugepage_enabled(vma));

    /* 打印 vma->vm_flags */
    show_smap_vma_flags(m, vma);

    /* 遍历下一个vma */
    m_cache_vma(m, vma);

    return 0;
}

 

posted on 2024-08-26 21:57  Hello-World3  阅读(31)  评论(0编辑  收藏  举报

导航