blob: e784110fb51d1056e28ada2bd5bd26b859e68778 [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>
12
13static const struct trace_print_flags pageflag_names[] = {
14 {1UL << PG_locked, "locked" },
15 {1UL << PG_error, "error" },
16 {1UL << PG_referenced, "referenced" },
17 {1UL << PG_uptodate, "uptodate" },
18 {1UL << PG_dirty, "dirty" },
19 {1UL << PG_lru, "lru" },
20 {1UL << PG_active, "active" },
21 {1UL << PG_slab, "slab" },
22 {1UL << PG_owner_priv_1, "owner_priv_1" },
23 {1UL << PG_arch_1, "arch_1" },
24 {1UL << PG_reserved, "reserved" },
25 {1UL << PG_private, "private" },
26 {1UL << PG_private_2, "private_2" },
27 {1UL << PG_writeback, "writeback" },
28#ifdef CONFIG_PAGEFLAGS_EXTENDED
29 {1UL << PG_head, "head" },
30 {1UL << PG_tail, "tail" },
31#else
32 {1UL << PG_compound, "compound" },
33#endif
34 {1UL << PG_swapcache, "swapcache" },
35 {1UL << PG_mappedtodisk, "mappedtodisk" },
36 {1UL << PG_reclaim, "reclaim" },
37 {1UL << PG_swapbacked, "swapbacked" },
38 {1UL << PG_unevictable, "unevictable" },
39#ifdef CONFIG_MMU
40 {1UL << PG_mlocked, "mlocked" },
41#endif
42#ifdef CONFIG_ARCH_USES_PG_UNCACHED
43 {1UL << PG_uncached, "uncached" },
44#endif
45#ifdef CONFIG_MEMORY_FAILURE
46 {1UL << PG_hwpoison, "hwpoison" },
47#endif
48#ifdef CONFIG_TRANSPARENT_HUGEPAGE
49 {1UL << PG_compound_lock, "compound_lock" },
50#endif
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070051#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT)
52 {1UL << PG_young, "young" },
53 {1UL << PG_idle, "idle" },
54#endif
Sasha Levin82742a32014-10-09 15:28:34 -070055};
56
57static void dump_flags(unsigned long flags,
58 const struct trace_print_flags *names, int count)
59{
60 const char *delim = "";
61 unsigned long mask;
62 int i;
63
Andrew Morton7a82ca02014-10-09 15:28:41 -070064 pr_emerg("flags: %#lx(", flags);
Sasha Levin82742a32014-10-09 15:28:34 -070065
66 /* remove zone id */
67 flags &= (1UL << NR_PAGEFLAGS) - 1;
68
69 for (i = 0; i < count && flags; i++) {
70
71 mask = names[i].mask;
72 if ((flags & mask) != mask)
73 continue;
74
75 flags &= ~mask;
Andrew Morton7a82ca02014-10-09 15:28:41 -070076 pr_cont("%s%s", delim, names[i].name);
Sasha Levin82742a32014-10-09 15:28:34 -070077 delim = "|";
78 }
79
80 /* check for left over flags */
81 if (flags)
Andrew Morton7a82ca02014-10-09 15:28:41 -070082 pr_cont("%s%#lx", delim, flags);
Sasha Levin82742a32014-10-09 15:28:34 -070083
Andrew Morton7a82ca02014-10-09 15:28:41 -070084 pr_cont(")\n");
Sasha Levin82742a32014-10-09 15:28:34 -070085}
86
87void dump_page_badflags(struct page *page, const char *reason,
88 unsigned long badflags)
89{
Andrew Morton7a82ca02014-10-09 15:28:41 -070090 pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx\n",
91 page, atomic_read(&page->_count), page_mapcount(page),
92 page->mapping, page->index);
Sasha Levin82742a32014-10-09 15:28:34 -070093 BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS);
94 dump_flags(page->flags, pageflag_names, ARRAY_SIZE(pageflag_names));
95 if (reason)
96 pr_alert("page dumped because: %s\n", reason);
97 if (page->flags & badflags) {
98 pr_alert("bad because of flags:\n");
99 dump_flags(page->flags & badflags,
100 pageflag_names, ARRAY_SIZE(pageflag_names));
101 }
Johannes Weiner9edad6e2014-12-10 15:44:58 -0800102#ifdef CONFIG_MEMCG
103 if (page->mem_cgroup)
104 pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup);
105#endif
Sasha Levin82742a32014-10-09 15:28:34 -0700106}
107
108void dump_page(struct page *page, const char *reason)
109{
110 dump_page_badflags(page, reason, 0);
111}
112EXPORT_SYMBOL(dump_page);
113
114#ifdef CONFIG_DEBUG_VM
115
116static const struct trace_print_flags vmaflags_names[] = {
117 {VM_READ, "read" },
118 {VM_WRITE, "write" },
119 {VM_EXEC, "exec" },
120 {VM_SHARED, "shared" },
121 {VM_MAYREAD, "mayread" },
122 {VM_MAYWRITE, "maywrite" },
123 {VM_MAYEXEC, "mayexec" },
124 {VM_MAYSHARE, "mayshare" },
125 {VM_GROWSDOWN, "growsdown" },
126 {VM_PFNMAP, "pfnmap" },
127 {VM_DENYWRITE, "denywrite" },
Eric B Munsonde60f5f2015-11-05 18:51:36 -0800128 {VM_LOCKONFAULT, "lockonfault" },
Sasha Levin82742a32014-10-09 15:28:34 -0700129 {VM_LOCKED, "locked" },
130 {VM_IO, "io" },
131 {VM_SEQ_READ, "seqread" },
132 {VM_RAND_READ, "randread" },
133 {VM_DONTCOPY, "dontcopy" },
134 {VM_DONTEXPAND, "dontexpand" },
135 {VM_ACCOUNT, "account" },
136 {VM_NORESERVE, "noreserve" },
137 {VM_HUGETLB, "hugetlb" },
Sasha Levin82742a32014-10-09 15:28:34 -0700138#if defined(CONFIG_X86)
139 {VM_PAT, "pat" },
140#elif defined(CONFIG_PPC)
141 {VM_SAO, "sao" },
142#elif defined(CONFIG_PARISC) || defined(CONFIG_METAG) || defined(CONFIG_IA64)
143 {VM_GROWSUP, "growsup" },
144#elif !defined(CONFIG_MMU)
145 {VM_MAPPED_COPY, "mappedcopy" },
146#else
147 {VM_ARCH_1, "arch_1" },
148#endif
149 {VM_DONTDUMP, "dontdump" },
150#ifdef CONFIG_MEM_SOFT_DIRTY
151 {VM_SOFTDIRTY, "softdirty" },
152#endif
153 {VM_MIXEDMAP, "mixedmap" },
154 {VM_HUGEPAGE, "hugepage" },
155 {VM_NOHUGEPAGE, "nohugepage" },
156 {VM_MERGEABLE, "mergeable" },
157};
158
159void dump_vma(const struct vm_area_struct *vma)
160{
Andrew Morton7a82ca02014-10-09 15:28:41 -0700161 pr_emerg("vma %p start %p end %p\n"
Sasha Levin82742a32014-10-09 15:28:34 -0700162 "next %p prev %p mm %p\n"
163 "prot %lx anon_vma %p vm_ops %p\n"
164 "pgoff %lx file %p private_data %p\n",
165 vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
166 vma->vm_prev, vma->vm_mm,
167 (unsigned long)pgprot_val(vma->vm_page_prot),
168 vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
169 vma->vm_file, vma->vm_private_data);
170 dump_flags(vma->vm_flags, vmaflags_names, ARRAY_SIZE(vmaflags_names));
171}
172EXPORT_SYMBOL(dump_vma);
173
Sasha Levin31c9afa2014-10-09 15:28:37 -0700174void dump_mm(const struct mm_struct *mm)
175{
Andrew Morton7a82ca02014-10-09 15:28:41 -0700176 pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n"
Sasha Levin31c9afa2014-10-09 15:28:37 -0700177#ifdef CONFIG_MMU
178 "get_unmapped_area %p\n"
179#endif
180 "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800181 "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 -0700182 "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
183 "pinned_vm %lx shared_vm %lx exec_vm %lx stack_vm %lx\n"
184 "start_code %lx end_code %lx start_data %lx end_data %lx\n"
185 "start_brk %lx brk %lx start_stack %lx\n"
186 "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
187 "binfmt %p flags %lx core_state %p\n"
188#ifdef CONFIG_AIO
189 "ioctx_table %p\n"
190#endif
191#ifdef CONFIG_MEMCG
192 "owner %p "
193#endif
194 "exe_file %p\n"
195#ifdef CONFIG_MMU_NOTIFIER
196 "mmu_notifier_mm %p\n"
197#endif
198#ifdef CONFIG_NUMA_BALANCING
199 "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
200#endif
201#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
202 "tlb_flush_pending %d\n"
203#endif
204 "%s", /* This is here to hold the comma */
205
206 mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
207#ifdef CONFIG_MMU
208 mm->get_unmapped_area,
209#endif
210 mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
211 mm->pgd, atomic_read(&mm->mm_users),
212 atomic_read(&mm->mm_count),
213 atomic_long_read((atomic_long_t *)&mm->nr_ptes),
Kirill A. Shutemovdc6c9a32015-02-11 15:26:50 -0800214 mm_nr_pmds((struct mm_struct *)mm),
Sasha Levin31c9afa2014-10-09 15:28:37 -0700215 mm->map_count,
216 mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
217 mm->pinned_vm, mm->shared_vm, mm->exec_vm, mm->stack_vm,
218 mm->start_code, mm->end_code, mm->start_data, mm->end_data,
219 mm->start_brk, mm->brk, mm->start_stack,
220 mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
221 mm->binfmt, mm->flags, mm->core_state,
222#ifdef CONFIG_AIO
223 mm->ioctx_table,
224#endif
225#ifdef CONFIG_MEMCG
226 mm->owner,
227#endif
228 mm->exe_file,
229#ifdef CONFIG_MMU_NOTIFIER
230 mm->mmu_notifier_mm,
231#endif
232#ifdef CONFIG_NUMA_BALANCING
233 mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
234#endif
235#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
236 mm->tlb_flush_pending,
237#endif
238 "" /* This is here to not have a comma! */
239 );
240
241 dump_flags(mm->def_flags, vmaflags_names,
242 ARRAY_SIZE(vmaflags_names));
243}
244
Sasha Levin82742a32014-10-09 15:28:34 -0700245#endif /* CONFIG_DEBUG_VM */