diff options
Diffstat (limited to 'mm/debug.c')
| -rw-r--r-- | mm/debug.c | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/mm/debug.c b/mm/debug.c new file mode 100644 index 000000000000..5ce45c9a29b5 --- /dev/null +++ b/mm/debug.c | |||
| @@ -0,0 +1,237 @@ | |||
| 1 | /* | ||
| 2 | * mm/debug.c | ||
| 3 | * | ||
| 4 | * mm/ specific debug routines. | ||
| 5 | * | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/kernel.h> | ||
| 9 | #include <linux/mm.h> | ||
| 10 | #include <linux/ftrace_event.h> | ||
| 11 | #include <linux/memcontrol.h> | ||
| 12 | |||
| 13 | static 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 | ||
| 51 | }; | ||
| 52 | |||
| 53 | static void dump_flags(unsigned long flags, | ||
| 54 | const struct trace_print_flags *names, int count) | ||
| 55 | { | ||
| 56 | const char *delim = ""; | ||
| 57 | unsigned long mask; | ||
| 58 | int i; | ||
| 59 | |||
| 60 | pr_emerg("flags: %#lx(", flags); | ||
| 61 | |||
| 62 | /* remove zone id */ | ||
| 63 | flags &= (1UL << NR_PAGEFLAGS) - 1; | ||
| 64 | |||
| 65 | for (i = 0; i < count && flags; i++) { | ||
| 66 | |||
| 67 | mask = names[i].mask; | ||
| 68 | if ((flags & mask) != mask) | ||
| 69 | continue; | ||
| 70 | |||
| 71 | flags &= ~mask; | ||
| 72 | pr_cont("%s%s", delim, names[i].name); | ||
| 73 | delim = "|"; | ||
| 74 | } | ||
| 75 | |||
| 76 | /* check for left over flags */ | ||
| 77 | if (flags) | ||
| 78 | pr_cont("%s%#lx", delim, flags); | ||
| 79 | |||
| 80 | pr_cont(")\n"); | ||
| 81 | } | ||
| 82 | |||
| 83 | void dump_page_badflags(struct page *page, const char *reason, | ||
| 84 | unsigned long badflags) | ||
| 85 | { | ||
| 86 | pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx\n", | ||
| 87 | page, atomic_read(&page->_count), page_mapcount(page), | ||
| 88 | page->mapping, page->index); | ||
| 89 | BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS); | ||
| 90 | dump_flags(page->flags, pageflag_names, ARRAY_SIZE(pageflag_names)); | ||
| 91 | if (reason) | ||
| 92 | pr_alert("page dumped because: %s\n", reason); | ||
| 93 | if (page->flags & badflags) { | ||
| 94 | pr_alert("bad because of flags:\n"); | ||
| 95 | dump_flags(page->flags & badflags, | ||
| 96 | pageflag_names, ARRAY_SIZE(pageflag_names)); | ||
| 97 | } | ||
| 98 | mem_cgroup_print_bad_page(page); | ||
| 99 | } | ||
| 100 | |||
| 101 | void dump_page(struct page *page, const char *reason) | ||
| 102 | { | ||
| 103 | dump_page_badflags(page, reason, 0); | ||
| 104 | } | ||
| 105 | EXPORT_SYMBOL(dump_page); | ||
| 106 | |||
| 107 | #ifdef CONFIG_DEBUG_VM | ||
| 108 | |||
| 109 | static const struct trace_print_flags vmaflags_names[] = { | ||
| 110 | {VM_READ, "read" }, | ||
| 111 | {VM_WRITE, "write" }, | ||
| 112 | {VM_EXEC, "exec" }, | ||
| 113 | {VM_SHARED, "shared" }, | ||
| 114 | {VM_MAYREAD, "mayread" }, | ||
| 115 | {VM_MAYWRITE, "maywrite" }, | ||
| 116 | {VM_MAYEXEC, "mayexec" }, | ||
| 117 | {VM_MAYSHARE, "mayshare" }, | ||
| 118 | {VM_GROWSDOWN, "growsdown" }, | ||
| 119 | {VM_PFNMAP, "pfnmap" }, | ||
| 120 | {VM_DENYWRITE, "denywrite" }, | ||
| 121 | {VM_LOCKED, "locked" }, | ||
| 122 | {VM_IO, "io" }, | ||
| 123 | {VM_SEQ_READ, "seqread" }, | ||
| 124 | {VM_RAND_READ, "randread" }, | ||
| 125 | {VM_DONTCOPY, "dontcopy" }, | ||
| 126 | {VM_DONTEXPAND, "dontexpand" }, | ||
| 127 | {VM_ACCOUNT, "account" }, | ||
| 128 | {VM_NORESERVE, "noreserve" }, | ||
| 129 | {VM_HUGETLB, "hugetlb" }, | ||
| 130 | {VM_NONLINEAR, "nonlinear" }, | ||
| 131 | #if defined(CONFIG_X86) | ||
| 132 | {VM_PAT, "pat" }, | ||
| 133 | #elif defined(CONFIG_PPC) | ||
| 134 | {VM_SAO, "sao" }, | ||
| 135 | #elif defined(CONFIG_PARISC) || defined(CONFIG_METAG) || defined(CONFIG_IA64) | ||
| 136 | {VM_GROWSUP, "growsup" }, | ||
| 137 | #elif !defined(CONFIG_MMU) | ||
| 138 | {VM_MAPPED_COPY, "mappedcopy" }, | ||
| 139 | #else | ||
| 140 | {VM_ARCH_1, "arch_1" }, | ||
| 141 | #endif | ||
| 142 | {VM_DONTDUMP, "dontdump" }, | ||
| 143 | #ifdef CONFIG_MEM_SOFT_DIRTY | ||
| 144 | {VM_SOFTDIRTY, "softdirty" }, | ||
| 145 | #endif | ||
| 146 | {VM_MIXEDMAP, "mixedmap" }, | ||
| 147 | {VM_HUGEPAGE, "hugepage" }, | ||
| 148 | {VM_NOHUGEPAGE, "nohugepage" }, | ||
| 149 | {VM_MERGEABLE, "mergeable" }, | ||
| 150 | }; | ||
| 151 | |||
| 152 | void dump_vma(const struct vm_area_struct *vma) | ||
| 153 | { | ||
| 154 | pr_emerg("vma %p start %p end %p\n" | ||
| 155 | "next %p prev %p mm %p\n" | ||
| 156 | "prot %lx anon_vma %p vm_ops %p\n" | ||
| 157 | "pgoff %lx file %p private_data %p\n", | ||
| 158 | vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next, | ||
| 159 | vma->vm_prev, vma->vm_mm, | ||
| 160 | (unsigned long)pgprot_val(vma->vm_page_prot), | ||
| 161 | vma->anon_vma, vma->vm_ops, vma->vm_pgoff, | ||
| 162 | vma->vm_file, vma->vm_private_data); | ||
| 163 | dump_flags(vma->vm_flags, vmaflags_names, ARRAY_SIZE(vmaflags_names)); | ||
| 164 | } | ||
| 165 | EXPORT_SYMBOL(dump_vma); | ||
| 166 | |||
| 167 | void dump_mm(const struct mm_struct *mm) | ||
| 168 | { | ||
| 169 | pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n" | ||
| 170 | #ifdef CONFIG_MMU | ||
| 171 | "get_unmapped_area %p\n" | ||
| 172 | #endif | ||
| 173 | "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n" | ||
| 174 | "pgd %p mm_users %d mm_count %d nr_ptes %lu map_count %d\n" | ||
| 175 | "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n" | ||
| 176 | "pinned_vm %lx shared_vm %lx exec_vm %lx stack_vm %lx\n" | ||
| 177 | "start_code %lx end_code %lx start_data %lx end_data %lx\n" | ||
| 178 | "start_brk %lx brk %lx start_stack %lx\n" | ||
| 179 | "arg_start %lx arg_end %lx env_start %lx env_end %lx\n" | ||
| 180 | "binfmt %p flags %lx core_state %p\n" | ||
| 181 | #ifdef CONFIG_AIO | ||
| 182 | "ioctx_table %p\n" | ||
| 183 | #endif | ||
| 184 | #ifdef CONFIG_MEMCG | ||
| 185 | "owner %p " | ||
| 186 | #endif | ||
| 187 | "exe_file %p\n" | ||
| 188 | #ifdef CONFIG_MMU_NOTIFIER | ||
| 189 | "mmu_notifier_mm %p\n" | ||
| 190 | #endif | ||
| 191 | #ifdef CONFIG_NUMA_BALANCING | ||
| 192 | "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n" | ||
| 193 | #endif | ||
| 194 | #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION) | ||
| 195 | "tlb_flush_pending %d\n" | ||
| 196 | #endif | ||
| 197 | "%s", /* This is here to hold the comma */ | ||
| 198 | |||
| 199 | mm, mm->mmap, mm->vmacache_seqnum, mm->task_size, | ||
| 200 | #ifdef CONFIG_MMU | ||
| 201 | mm->get_unmapped_area, | ||
| 202 | #endif | ||
| 203 | mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end, | ||
| 204 | mm->pgd, atomic_read(&mm->mm_users), | ||
| 205 | atomic_read(&mm->mm_count), | ||
| 206 | atomic_long_read((atomic_long_t *)&mm->nr_ptes), | ||
| 207 | mm->map_count, | ||
| 208 | mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm, | ||
| 209 | mm->pinned_vm, mm->shared_vm, mm->exec_vm, mm->stack_vm, | ||
| 210 | mm->start_code, mm->end_code, mm->start_data, mm->end_data, | ||
| 211 | mm->start_brk, mm->brk, mm->start_stack, | ||
| 212 | mm->arg_start, mm->arg_end, mm->env_start, mm->env_end, | ||
| 213 | mm->binfmt, mm->flags, mm->core_state, | ||
| 214 | #ifdef CONFIG_AIO | ||
| 215 | mm->ioctx_table, | ||
| 216 | #endif | ||
| 217 | #ifdef CONFIG_MEMCG | ||
| 218 | mm->owner, | ||
| 219 | #endif | ||
| 220 | mm->exe_file, | ||
| 221 | #ifdef CONFIG_MMU_NOTIFIER | ||
| 222 | mm->mmu_notifier_mm, | ||
| 223 | #endif | ||
| 224 | #ifdef CONFIG_NUMA_BALANCING | ||
| 225 | mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq, | ||
| 226 | #endif | ||
| 227 | #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION) | ||
| 228 | mm->tlb_flush_pending, | ||
| 229 | #endif | ||
| 230 | "" /* This is here to not have a comma! */ | ||
| 231 | ); | ||
| 232 | |||
| 233 | dump_flags(mm->def_flags, vmaflags_names, | ||
| 234 | ARRAY_SIZE(vmaflags_names)); | ||
| 235 | } | ||
| 236 | |||
| 237 | #endif /* CONFIG_DEBUG_VM */ | ||
