proc/smaps: show amount of nonlinear ptes in vma
authorKonstantin Khlebnikov <khlebnikov@openvz.org>
Thu, 31 May 2012 23:26:20 +0000 (16:26 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 1 Jun 2012 00:49:29 +0000 (17:49 -0700)
Currently, nonlinear mappings can not be distinguished from ordinary
mappings.  This patch adds into /proc/pid/smaps line "Nonlinear: <size>
kB", where size is amount of nonlinear ptes in vma, this line appears only
if VM_NONLINEAR is set.  This information may be useful not only for
checkpoint/restore project.

Requested by Pavel Emelyanov.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/task_mmu.c

index e2c1155ac09a1aad7a6b7032e5732278321bf072..4540b8f76f163fbaaef250b6facf161424a90869 100644 (file)
@@ -393,6 +393,7 @@ struct mem_size_stats {
        unsigned long anonymous;
        unsigned long anonymous_thp;
        unsigned long swap;
+       unsigned long nonlinear;
        u64 pss;
 };
 
@@ -402,6 +403,7 @@ static void smaps_pte_entry(pte_t ptent, unsigned long addr,
 {
        struct mem_size_stats *mss = walk->private;
        struct vm_area_struct *vma = mss->vma;
+       pgoff_t pgoff = linear_page_index(vma, addr);
        struct page *page = NULL;
        int mapcount;
 
@@ -414,6 +416,9 @@ static void smaps_pte_entry(pte_t ptent, unsigned long addr,
                        mss->swap += ptent_size;
                else if (is_migration_entry(swpent))
                        page = migration_entry_to_page(swpent);
+       } else if (pte_file(ptent)) {
+               if (pte_to_pgoff(ptent) != pgoff)
+                       mss->nonlinear += ptent_size;
        }
 
        if (!page)
@@ -422,6 +427,9 @@ static void smaps_pte_entry(pte_t ptent, unsigned long addr,
        if (PageAnon(page))
                mss->anonymous += ptent_size;
 
+       if (page->index != pgoff)
+               mss->nonlinear += ptent_size;
+
        mss->resident += ptent_size;
        /* Accumulate the size in pages that have been accessed. */
        if (pte_young(ptent) || PageReferenced(page))
@@ -523,6 +531,10 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
                   (vma->vm_flags & VM_LOCKED) ?
                        (unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0);
 
+       if (vma->vm_flags & VM_NONLINEAR)
+               seq_printf(m, "Nonlinear:      %8lu kB\n",
+                               mss.nonlinear >> 10);
+
        if (m->count < m->size)  /* vma is copied successfully */
                m->version = (vma != get_gate_vma(task->mm))
                        ? vma->vm_start : 0;