Display additional information /proc/pid/smaps This patch includes some additional information to smaps: Anonymous pages, mapped pages, highest mapping count (to see how many processes may be using a vma). For NUMA show a map of the nodes on which the memory was allocated. This patch can safely display the policy information of a vma because the mmap_sem readlock is held which prevents the policy layer from modifying policy under us. Signed-off-by: Christoph Lameter Index: linux-2.6.13-rc4-mm1/fs/proc/task_mmu.c =================================================================== --- linux-2.6.13-rc4-mm1.orig/fs/proc/task_mmu.c 2005-08-05 08:47:31.000000000 -0700 +++ linux-2.6.13-rc4-mm1/fs/proc/task_mmu.c 2005-08-05 08:52:34.000000000 -0700 @@ -158,6 +158,10 @@ unsigned long shared_dirty; unsigned long private_clean; unsigned long private_dirty; + unsigned long anon; + unsigned long mapped; + unsigned long mapcount_max; + unsigned long node[MAX_NUMNODES]; }; static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd, @@ -167,6 +171,7 @@ pte_t *pte, ptent; unsigned long pfn; struct page *page; + int count; pte = pte_offset_map(pmd, addr); do { @@ -191,6 +196,15 @@ else mss->private_clean += PAGE_SIZE; } + + count = page_mapcount(page); + if (count) + mss->mapped += PAGE_SIZE; + if (count > mss->mapcount_max) + mss->mapcount_max = count; + if (PageAnon(page)) + mss->anon += PAGE_SIZE; + mss->node[page_to_nid(page)] += PAGE_SIZE; } while (pte++, addr += PAGE_SIZE, addr != end); pte_unmap(pte - 1); cond_resched_lock(&vma->vm_mm->page_table_lock); @@ -246,10 +260,15 @@ static int show_smap(struct seq_file *m, void *v) { + struct task_struct *task = m->private; struct vm_area_struct *vma = v; struct mm_struct *mm = vma->vm_mm; unsigned long vma_len = (vma->vm_end - vma->vm_start); struct mem_size_stats mss; +#ifdef CONFIG_NUMA + int n; + char buffer[50]; +#endif memset(&mss, 0, sizeof mss); @@ -267,13 +286,33 @@ "Shared_Clean: %8lu kB\n" "Shared_Dirty: %8lu kB\n" "Private_Clean: %8lu kB\n" - "Private_Dirty: %8lu kB\n", + "Private_Dirty: %8lu kB\n" + "Anonymous: %8lu kB\n" + "Mapped: %8lu kB\n" + "MaxMapCount: %8lu\n", vma_len >> 10, mss.resident >> 10, mss.shared_clean >> 10, mss.shared_dirty >> 10, mss.private_clean >> 10, - mss.private_dirty >> 10); + mss.private_dirty >> 10, + mss.anon >> 10, + mss.mapped >> 10, + mss.mapcount_max); +#ifdef CONFIG_NUMA + for_each_node(n) + if (mss.node[n]) + seq_printf(m, "Node%-4d: %8lu kB\n", + n, mss.node[n]); + /* + * It is safe to access the memory policy of a vma since + * we do hold a read lock on mmap sem which protect from + * changes to the policy in a vma. + */ + if (mpol_to_str(buffer, sizeof(buffer), + get_vma_policy(task, vma, vma->vm_start)) >=0) + seq_printf(m, "Memory_Policy: %s\n", buffer); +#endif return 0; }