Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mm/debug.c |
| 3 | * |
| 4 | * mm/ specific debug routines. |
| 5 | * |
| 6 | */ |
| 7 | |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
| 9 | #include <linux/mm.h> |
Steven Rostedt (Red Hat) | af658dc | 2015-04-29 14:36:05 -0400 | [diff] [blame] | 10 | #include <linux/trace_events.h> |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 11 | #include <linux/memcontrol.h> |
Vlastimil Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame^] | 12 | #include <trace/events/mmflags.h> |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 13 | |
| 14 | static const struct trace_print_flags pageflag_names[] = { |
Vlastimil Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame^] | 15 | __def_pageflag_names |
| 16 | }; |
| 17 | |
| 18 | static const struct trace_print_flags gfpflag_names[] = { |
| 19 | __def_gfpflag_names |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | static 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 Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 29 | pr_emerg("flags: %#lx(", flags); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 30 | |
| 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 Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 41 | pr_cont("%s%s", delim, names[i].name); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 42 | delim = "|"; |
| 43 | } |
| 44 | |
| 45 | /* check for left over flags */ |
| 46 | if (flags) |
Andrew Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 47 | pr_cont("%s%#lx", delim, flags); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 48 | |
Andrew Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 49 | pr_cont(")\n"); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void dump_page_badflags(struct page *page, const char *reason, |
| 53 | unsigned long badflags) |
| 54 | { |
Kirill A. Shutemov | 53f9263 | 2016-01-15 16:53:42 -0800 | [diff] [blame] | 55 | pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx", |
Andrew Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 56 | page, atomic_read(&page->_count), page_mapcount(page), |
| 57 | page->mapping, page->index); |
Kirill A. Shutemov | 53f9263 | 2016-01-15 16:53:42 -0800 | [diff] [blame] | 58 | if (PageCompound(page)) |
| 59 | pr_cont(" compound_mapcount: %d", compound_mapcount(page)); |
| 60 | pr_cont("\n"); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 61 | 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 Weiner | 9edad6e | 2014-12-10 15:44:58 -0800 | [diff] [blame] | 70 | #ifdef CONFIG_MEMCG |
| 71 | if (page->mem_cgroup) |
| 72 | pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup); |
| 73 | #endif |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void dump_page(struct page *page, const char *reason) |
| 77 | { |
| 78 | dump_page_badflags(page, reason, 0); |
| 79 | } |
| 80 | EXPORT_SYMBOL(dump_page); |
| 81 | |
| 82 | #ifdef CONFIG_DEBUG_VM |
| 83 | |
Vlastimil Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame^] | 84 | static const struct trace_print_flags vmaflag_names[] = { |
| 85 | __def_vmaflag_names |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | void dump_vma(const struct vm_area_struct *vma) |
| 89 | { |
Andrew Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 90 | pr_emerg("vma %p start %p end %p\n" |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 91 | "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 Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame^] | 99 | dump_flags(vma->vm_flags, vmaflag_names, ARRAY_SIZE(vmaflag_names)); |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 100 | } |
| 101 | EXPORT_SYMBOL(dump_vma); |
| 102 | |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 103 | void dump_mm(const struct mm_struct *mm) |
| 104 | { |
Andrew Morton | 7a82ca0 | 2014-10-09 15:28:41 -0700 | [diff] [blame] | 105 | pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n" |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 106 | #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. Shutemov | dc6c9a3 | 2015-02-11 15:26:50 -0800 | [diff] [blame] | 110 | "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n" |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 111 | "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n" |
Konstantin Khlebnikov | 8463833 | 2016-01-14 15:22:07 -0800 | [diff] [blame] | 112 | "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n" |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 113 | "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. Shutemov | dc6c9a3 | 2015-02-11 15:26:50 -0800 | [diff] [blame] | 143 | mm_nr_pmds((struct mm_struct *)mm), |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 144 | mm->map_count, |
| 145 | mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm, |
Konstantin Khlebnikov | 8463833 | 2016-01-14 15:22:07 -0800 | [diff] [blame] | 146 | mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm, |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 147 | 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 Babka | 420adbe9 | 2016-03-15 14:55:52 -0700 | [diff] [blame^] | 170 | dump_flags(mm->def_flags, vmaflag_names, |
| 171 | ARRAY_SIZE(vmaflag_names)); |
Sasha Levin | 31c9afa | 2014-10-09 15:28:37 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Sasha Levin | 82742a3 | 2014-10-09 15:28:34 -0700 | [diff] [blame] | 174 | #endif /* CONFIG_DEBUG_VM */ |