debug.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * mm/debug.c
  3. *
  4. * mm/ specific debug routines.
  5. *
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/mm.h>
  9. #include <linux/trace_events.h>
  10. #include <linux/memcontrol.h>
  11. #include <trace/events/mmflags.h>
  12. #include <linux/migrate.h>
  13. #include <linux/page_owner.h>
  14. #include "internal.h"
  15. char *migrate_reason_names[MR_TYPES] = {
  16. "compaction",
  17. "memory_failure",
  18. "memory_hotplug",
  19. "syscall_or_cpuset",
  20. "mempolicy_mbind",
  21. "numa_misplaced",
  22. "cma",
  23. };
  24. const struct trace_print_flags pageflag_names[] = {
  25. __def_pageflag_names,
  26. {0, NULL}
  27. };
  28. const struct trace_print_flags gfpflag_names[] = {
  29. __def_gfpflag_names,
  30. {0, NULL}
  31. };
  32. const struct trace_print_flags vmaflag_names[] = {
  33. __def_vmaflag_names,
  34. {0, NULL}
  35. };
  36. void __dump_page(struct page *page, const char *reason)
  37. {
  38. /*
  39. * Avoid VM_BUG_ON() in page_mapcount().
  40. * page->_mapcount space in struct page is used by sl[aou]b pages to
  41. * encode own info.
  42. */
  43. int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
  44. pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",
  45. page, page_ref_count(page), mapcount,
  46. page->mapping, page_to_pgoff(page));
  47. if (PageCompound(page))
  48. pr_cont(" compound_mapcount: %d", compound_mapcount(page));
  49. pr_cont("\n");
  50. BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);
  51. pr_emerg("flags: %#lx(%pGp)\n", page->flags, &page->flags);
  52. if (reason)
  53. pr_alert("page dumped because: %s\n", reason);
  54. #ifdef CONFIG_MEMCG
  55. if (page->mem_cgroup)
  56. pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup);
  57. #endif
  58. }
  59. void dump_page(struct page *page, const char *reason)
  60. {
  61. __dump_page(page, reason);
  62. dump_page_owner(page);
  63. }
  64. EXPORT_SYMBOL(dump_page);
  65. #ifdef CONFIG_DEBUG_VM
  66. void dump_vma(const struct vm_area_struct *vma)
  67. {
  68. pr_emerg("vma %p start %p end %p\n"
  69. "next %p prev %p mm %p\n"
  70. "prot %lx anon_vma %p vm_ops %p\n"
  71. "pgoff %lx file %p private_data %p\n"
  72. "flags: %#lx(%pGv)\n",
  73. vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
  74. vma->vm_prev, vma->vm_mm,
  75. (unsigned long)pgprot_val(vma->vm_page_prot),
  76. vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
  77. vma->vm_file, vma->vm_private_data,
  78. vma->vm_flags, &vma->vm_flags);
  79. }
  80. EXPORT_SYMBOL(dump_vma);
  81. void dump_mm(const struct mm_struct *mm)
  82. {
  83. pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n"
  84. #ifdef CONFIG_MMU
  85. "get_unmapped_area %p\n"
  86. #endif
  87. "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
  88. "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n"
  89. "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
  90. "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n"
  91. "start_code %lx end_code %lx start_data %lx end_data %lx\n"
  92. "start_brk %lx brk %lx start_stack %lx\n"
  93. "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
  94. "binfmt %p flags %lx core_state %p\n"
  95. #ifdef CONFIG_AIO
  96. "ioctx_table %p\n"
  97. #endif
  98. #ifdef CONFIG_MEMCG
  99. "owner %p "
  100. #endif
  101. "exe_file %p\n"
  102. #ifdef CONFIG_MMU_NOTIFIER
  103. "mmu_notifier_mm %p\n"
  104. #endif
  105. #ifdef CONFIG_NUMA_BALANCING
  106. "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
  107. #endif
  108. #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
  109. "tlb_flush_pending %d\n"
  110. #endif
  111. "def_flags: %#lx(%pGv)\n",
  112. mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
  113. #ifdef CONFIG_MMU
  114. mm->get_unmapped_area,
  115. #endif
  116. mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
  117. mm->pgd, atomic_read(&mm->mm_users),
  118. atomic_read(&mm->mm_count),
  119. atomic_long_read((atomic_long_t *)&mm->nr_ptes),
  120. mm_nr_pmds((struct mm_struct *)mm),
  121. mm->map_count,
  122. mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
  123. mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm,
  124. mm->start_code, mm->end_code, mm->start_data, mm->end_data,
  125. mm->start_brk, mm->brk, mm->start_stack,
  126. mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
  127. mm->binfmt, mm->flags, mm->core_state,
  128. #ifdef CONFIG_AIO
  129. mm->ioctx_table,
  130. #endif
  131. #ifdef CONFIG_MEMCG
  132. mm->owner,
  133. #endif
  134. mm->exe_file,
  135. #ifdef CONFIG_MMU_NOTIFIER
  136. mm->mmu_notifier_mm,
  137. #endif
  138. #ifdef CONFIG_NUMA_BALANCING
  139. mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
  140. #endif
  141. #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
  142. mm->tlb_flush_pending,
  143. #endif
  144. mm->def_flags, &mm->def_flags
  145. );
  146. }
  147. #endif /* CONFIG_DEBUG_VM */