blob: 410af904a7d513a5fae5424458dcd70e39ce9e05 [file] [log] [blame]
Sasha Levin31c9afa2014-10-09 15:28:37 -07001/*
2 * mm/debug.c
3 *
4 * mm/ specific debug routines.
5 *
6 */
7
Sasha Levin82742a32014-10-09 15:28:34 -07008#include <linux/kernel.h>
9#include <linux/mm.h>
Steven Rostedt (Red Hat)af658dc2015-04-29 14:36:05 -040010#include <linux/trace_events.h>
Sasha Levin82742a32014-10-09 15:28:34 -070011#include <linux/memcontrol.h>
Vlastimil Babka420adbe92016-03-15 14:55:52 -070012#include <trace/events/mmflags.h>
Sasha Levin82742a32014-10-09 15:28:34 -070013
14static const struct trace_print_flags pageflag_names[] = {
Vlastimil Babka420adbe92016-03-15 14:55:52 -070015 __def_pageflag_names
16};
17
18static const struct trace_print_flags gfpflag_names[] = {
19 __def_gfpflag_names
Sasha Levin82742a32014-10-09 15:28:34 -070020};
21
22static void dump_flags(unsigned long flags,
23 const struct trace_print_flags *names, int count)
24{
25 const char *delim = "";
26 unsigned long mask;
27 int i;
28
Andrew Morton7a82ca02014-10-09 15:28:41 -070029 pr_emerg("flags: %#lx(", flags);
Sasha Levin82742a32014-10-09 15:28:34 -070030
31 /* remove zone id */
32 flags &= (1UL << NR_PAGEFLAGS) - 1;
33
34 for (i = 0; i < count && flags; i++) {
35
36 mask = names[i].mask;
37 if ((flags & mask) != mask)
38 continue;
39
40 flags &= ~mask;
Andrew Morton7a82ca02014-10-09 15:28:41 -070041 pr_cont("%s%s", delim, names[i].name);
Sasha Levin82742a32014-10-09 15:28:34 -070042 delim = "|";
43 }
44
45 /* check for left over flags */
46 if (flags)
Andrew Morton7a82ca02014-10-09 15:28:41 -070047 pr_cont("%s%#lx", delim, flags);
Sasha Levin82742a32014-10-09 15:28:34 -070048
Andrew Morton7a82ca02014-10-09 15:28:41 -070049 pr_cont(")\n");
Sasha Levin82742a32014-10-09 15:28:34 -070050}
51
52void dump_page_badflags(struct page *page, const char *reason,
53 unsigned long badflags)
54{
Kirill A. Shutemov53f92632016-01-15 16:53:42 -080055 pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",
Andrew Morton7a82ca02014-10-09 15:28:41 -070056 page, atomic_read(&page->_count), page_mapcount(page),
57 page->mapping, page->index);
Kirill A. Shutemov53f92632016-01-15 16:53:42 -080058 if (PageCompound(page))
59 pr_cont(" compound_mapcount: %d", compound_mapcount(page));
60 pr_cont("\n");
Sasha Levin82742a32014-10-09 15:28:34 -070061 BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS);
62 dump_flags(page->flags, pageflag_names, ARRAY_SIZE(pageflag_names));
63 if (reason)
64 pr_alert("page dumped because: %s\n", reason);
65 if (page->flags & badflags) {
66 pr_alert("bad because of flags:\n");
67 dump_flags(page->flags & badflags,
68 pageflag_names, ARRAY_SIZE(pageflag_names));
69 }
Johannes Weiner9edad6e2014-12-10 15:44:58 -080070#ifdef CONFIG_MEMCG
71 if (page->mem_cgroup)
72 pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup);
73#endif
Sasha Levin82742a32014-10-09 15:28:34 -070074}
75
76void dump_page(struct page *page, const char *reason)
77{
78 dump_page_badflags(page, reason, 0);
79}
80EXPORT_SYMBOL(dump_page);
81
82#ifdef CONFIG_DEBUG_VM
83
Vlastimil Babka420adbe92016-03-15 14:55:52 -070084static const struct trace_print_flags vmaflag_names[] = {
85 __def_vmaflag_names
Sasha Levin82742a32014-10-09 15:28:34 -070086};
87
88void dump_vma(const struct vm_area_struct *vma)
89{
Andrew Morton7a82ca02014-10-09 15:28:41 -070090 pr_emerg("vma %p start %p end %p\n"
Sasha Levin82742a32014-10-09 15:28:34 -070091 "next %p prev %p mm %p\n"
92 "prot %lx anon_vma %p vm_ops %p\n"
93 "pgoff %lx file %p private_data %p\n",
94 vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
95 vma->vm_prev, vma->vm_mm,
96 (unsigned long)pgprot_val(vma->vm_page_prot),
97 vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
98 vma->vm_file, vma->vm_private_data);
Vlastimil Babka420adbe92016-03-15 14:55:52 -070099 dump_flags(vma->vm_flags, vmaflag_names, ARRAY_SIZE(vmaflag_names));
Sasha Levin82742a32014-10-09 15:28:34 -0700100}
101EXPORT_SYMBOL(dump_vma);
102
Sasha Levin31c9afa2014-10-09 15:28:37 -0700103void dump_mm(const struct mm_struct *mm)
104{
Andrew Morton7a82ca02014-10-09 15:28:41 -0700105 pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n"
Sasha Levin31c9afa2014-10-09 15:28:37 -0700106#ifdef CONFIG_MMU
107 "get_unmapped_area %p\n"
108#endif
109 "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800110 "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n"
Sasha Levin31c9afa2014-10-09 15:28:37 -0700111 "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
Konstantin Khlebnikov84638332016-01-14 15:22:07 -0800112 "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n"
Sasha Levin31c9afa2014-10-09 15:28:37 -0700113 "start_code %lx end_code %lx start_data %lx end_data %lx\n"
114 "start_brk %lx brk %lx start_stack %lx\n"
115 "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
116 "binfmt %p flags %lx core_state %p\n"
117#ifdef CONFIG_AIO
118 "ioctx_table %p\n"
119#endif
120#ifdef CONFIG_MEMCG
121 "owner %p "
122#endif
123 "exe_file %p\n"
124#ifdef CONFIG_MMU_NOTIFIER
125 "mmu_notifier_mm %p\n"
126#endif
127#ifdef CONFIG_NUMA_BALANCING
128 "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
129#endif
130#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
131 "tlb_flush_pending %d\n"
132#endif
133 "%s", /* This is here to hold the comma */
134
135 mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
136#ifdef CONFIG_MMU
137 mm->get_unmapped_area,
138#endif
139 mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
140 mm->pgd, atomic_read(&mm->mm_users),
141 atomic_read(&mm->mm_count),
142 atomic_long_read((atomic_long_t *)&mm->nr_ptes),
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800143 mm_nr_pmds((struct mm_struct *)mm),
Sasha Levin31c9afa2014-10-09 15:28:37 -0700144 mm->map_count,
145 mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
Konstantin Khlebnikov84638332016-01-14 15:22:07 -0800146 mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm,
Sasha Levin31c9afa2014-10-09 15:28:37 -0700147 mm->start_code, mm->end_code, mm->start_data, mm->end_data,
148 mm->start_brk, mm->brk, mm->start_stack,
149 mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
150 mm->binfmt, mm->flags, mm->core_state,
151#ifdef CONFIG_AIO
152 mm->ioctx_table,
153#endif
154#ifdef CONFIG_MEMCG
155 mm->owner,
156#endif
157 mm->exe_file,
158#ifdef CONFIG_MMU_NOTIFIER
159 mm->mmu_notifier_mm,
160#endif
161#ifdef CONFIG_NUMA_BALANCING
162 mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
163#endif
164#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
165 mm->tlb_flush_pending,
166#endif
167 "" /* This is here to not have a comma! */
168 );
169
Vlastimil Babka420adbe92016-03-15 14:55:52 -0700170 dump_flags(mm->def_flags, vmaflag_names,
171 ARRAY_SIZE(vmaflag_names));
Sasha Levin31c9afa2014-10-09 15:28:37 -0700172}
173
Sasha Levin82742a32014-10-09 15:28:34 -0700174#endif /* CONFIG_DEBUG_VM */