Skip to content

Commit 0bf5513

Browse files
sashalevintorvalds
authored andcommitted
mm: introduce dump_vma
Introduce a helper to dump information about a VMA, this also makes dump_page_flags more generic and re-uses that so the output looks very similar to dump_page: [ 61.903437] vma ffff88070f88be00 start 00007fff25970000 end 00007fff25992000 [ 61.903437] next ffff88070facd600 prev ffff88070face400 mm ffff88070fade000 [ 61.903437] prot 8000000000000025 anon_vma ffff88070fa1e200 vm_ops (null) [ 61.903437] pgoff 7ffffffdd file (null) private_data (null) [ 61.909129] flags: 0x100173(read|write|mayread|maywrite|mayexec|growsdown|account) [akpm@linux-foundation.org: make dump_vma() require CONFIG_DEBUG_VM] [swarren@nvidia.com: fix dump_vma() compilation] Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <khlebnikov@openvz.org> Cc: Rik van Riel <riel@redhat.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Michal Hocko <mhocko@suse.cz> Cc: Hugh Dickins <hughd@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Michel Lespinasse <walken@google.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b208ce3 commit 0bf5513

2 files changed

Lines changed: 75 additions & 9 deletions

File tree

‎include/linux/mmdebug.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include <linux/stringify.h>
55

66
struct page;
7+
struct vm_area_struct;
78

89
extern void dump_page(struct page *page, const char *reason);
910
extern void dump_page_badflags(struct page *page, const char *reason,
1011
unsigned long badflags);
12+
void dump_vma(const struct vm_area_struct *vma);
1113

1214
#ifdef CONFIG_DEBUG_VM
1315
#define VM_BUG_ON(cond) BUG_ON(cond)

‎mm/page_alloc.c‎

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,27 +6626,26 @@ static const struct trace_print_flags pageflag_names[] = {
66266626
#endif
66276627
};
66286628

6629-
static void dump_page_flags(unsigned long flags)
6629+
static void dump_flags(unsigned long flags,
6630+
const struct trace_print_flags *names, int count)
66306631
{
66316632
const char *delim = "";
66326633
unsigned long mask;
66336634
int i;
66346635

6635-
BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS);
6636-
6637-
printk(KERN_ALERT "page flags: %#lx(", flags);
6636+
printk(KERN_ALERT "flags: %#lx(", flags);
66386637

66396638
/* remove zone id */
66406639
flags &= (1UL << NR_PAGEFLAGS) - 1;
66416640

6642-
for (i = 0; i < ARRAY_SIZE(pageflag_names) && flags; i++) {
6641+
for (i = 0; i < count && flags; i++) {
66436642

6644-
mask = pageflag_names[i].mask;
6643+
mask = names[i].mask;
66456644
if ((flags & mask) != mask)
66466645
continue;
66476646

66486647
flags &= ~mask;
6649-
printk("%s%s", delim, pageflag_names[i].name);
6648+
printk("%s%s", delim, names[i].name);
66506649
delim = "|";
66516650
}
66526651

@@ -6664,12 +6663,14 @@ void dump_page_badflags(struct page *page, const char *reason,
66646663
"page:%p count:%d mapcount:%d mapping:%p index:%#lx\n",
66656664
page, atomic_read(&page->_count), page_mapcount(page),
66666665
page->mapping, page->index);
6667-
dump_page_flags(page->flags);
6666+
BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS);
6667+
dump_flags(page->flags, pageflag_names, ARRAY_SIZE(pageflag_names));
66686668
if (reason)
66696669
pr_alert("page dumped because: %s\n", reason);
66706670
if (page->flags & badflags) {
66716671
pr_alert("bad because of flags:\n");
6672-
dump_page_flags(page->flags & badflags);
6672+
dump_flags(page->flags & badflags,
6673+
pageflag_names, ARRAY_SIZE(pageflag_names));
66736674
}
66746675
mem_cgroup_print_bad_page(page);
66756676
}
@@ -6679,3 +6680,66 @@ void dump_page(struct page *page, const char *reason)
66796680
dump_page_badflags(page, reason, 0);
66806681
}
66816682
EXPORT_SYMBOL(dump_page);
6683+
6684+
#ifdef CONFIG_DEBUG_VM
6685+
6686+
static const struct trace_print_flags vmaflags_names[] = {
6687+
{VM_READ, "read" },
6688+
{VM_WRITE, "write" },
6689+
{VM_EXEC, "exec" },
6690+
{VM_SHARED, "shared" },
6691+
{VM_MAYREAD, "mayread" },
6692+
{VM_MAYWRITE, "maywrite" },
6693+
{VM_MAYEXEC, "mayexec" },
6694+
{VM_MAYSHARE, "mayshare" },
6695+
{VM_GROWSDOWN, "growsdown" },
6696+
{VM_PFNMAP, "pfnmap" },
6697+
{VM_DENYWRITE, "denywrite" },
6698+
{VM_LOCKED, "locked" },
6699+
{VM_IO, "io" },
6700+
{VM_SEQ_READ, "seqread" },
6701+
{VM_RAND_READ, "randread" },
6702+
{VM_DONTCOPY, "dontcopy" },
6703+
{VM_DONTEXPAND, "dontexpand" },
6704+
{VM_ACCOUNT, "account" },
6705+
{VM_NORESERVE, "noreserve" },
6706+
{VM_HUGETLB, "hugetlb" },
6707+
{VM_NONLINEAR, "nonlinear" },
6708+
#if defined(CONFIG_X86)
6709+
{VM_PAT, "pat" },
6710+
#elif defined(CONFIG_PPC)
6711+
{VM_SAO, "sao" },
6712+
#elif defined(CONFIG_PARISC) || defined(CONFIG_METAG) || defined(CONFIG_IA64)
6713+
{VM_GROWSUP, "growsup" },
6714+
#elif !defined(CONFIG_MMU)
6715+
{VM_MAPPED_COPY, "mappedcopy" },
6716+
#else
6717+
{VM_ARCH_1, "arch_1" },
6718+
#endif
6719+
{VM_DONTDUMP, "dontdump" },
6720+
#ifdef CONFIG_MEM_SOFT_DIRTY
6721+
{VM_SOFTDIRTY, "softdirty" },
6722+
#endif
6723+
{VM_MIXEDMAP, "mixedmap" },
6724+
{VM_HUGEPAGE, "hugepage" },
6725+
{VM_NOHUGEPAGE, "nohugepage" },
6726+
{VM_MERGEABLE, "mergeable" },
6727+
};
6728+
6729+
void dump_vma(const struct vm_area_struct *vma)
6730+
{
6731+
printk(KERN_ALERT
6732+
"vma %p start %p end %p\n"
6733+
"next %p prev %p mm %p\n"
6734+
"prot %lx anon_vma %p vm_ops %p\n"
6735+
"pgoff %lx file %p private_data %p\n",
6736+
vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
6737+
vma->vm_prev, vma->vm_mm,
6738+
(unsigned long)pgprot_val(vma->vm_page_prot),
6739+
vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
6740+
vma->vm_file, vma->vm_private_data);
6741+
dump_flags(vma->vm_flags, vmaflags_names, ARRAY_SIZE(vmaflags_names));
6742+
}
6743+
EXPORT_SYMBOL(dump_vma);
6744+
6745+
#endif /* CONFIG_DEBUG_VM */

0 commit comments

Comments
 (0)