Back to home page

LXR

 
 

    


0001 /*
0002  * mm/debug.c
0003  *
0004  * mm/ specific debug routines.
0005  *
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/mm.h>
0010 #include <linux/trace_events.h>
0011 #include <linux/memcontrol.h>
0012 #include <trace/events/mmflags.h>
0013 #include <linux/migrate.h>
0014 #include <linux/page_owner.h>
0015 
0016 #include "internal.h"
0017 
0018 char *migrate_reason_names[MR_TYPES] = {
0019     "compaction",
0020     "memory_failure",
0021     "memory_hotplug",
0022     "syscall_or_cpuset",
0023     "mempolicy_mbind",
0024     "numa_misplaced",
0025     "cma",
0026 };
0027 
0028 const struct trace_print_flags pageflag_names[] = {
0029     __def_pageflag_names,
0030     {0, NULL}
0031 };
0032 
0033 const struct trace_print_flags gfpflag_names[] = {
0034     __def_gfpflag_names,
0035     {0, NULL}
0036 };
0037 
0038 const struct trace_print_flags vmaflag_names[] = {
0039     __def_vmaflag_names,
0040     {0, NULL}
0041 };
0042 
0043 void __dump_page(struct page *page, const char *reason)
0044 {
0045     /*
0046      * Avoid VM_BUG_ON() in page_mapcount().
0047      * page->_mapcount space in struct page is used by sl[aou]b pages to
0048      * encode own info.
0049      */
0050     int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
0051 
0052     pr_emerg("page:%p count:%d mapcount:%d mapping:%p index:%#lx",
0053           page, page_ref_count(page), mapcount,
0054           page->mapping, page_to_pgoff(page));
0055     if (PageCompound(page))
0056         pr_cont(" compound_mapcount: %d", compound_mapcount(page));
0057     pr_cont("\n");
0058     BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);
0059 
0060     pr_emerg("flags: %#lx(%pGp)\n", page->flags, &page->flags);
0061 
0062     print_hex_dump(KERN_ALERT, "raw: ", DUMP_PREFIX_NONE, 32,
0063             sizeof(unsigned long), page,
0064             sizeof(struct page), false);
0065 
0066     if (reason)
0067         pr_alert("page dumped because: %s\n", reason);
0068 
0069 #ifdef CONFIG_MEMCG
0070     if (page->mem_cgroup)
0071         pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup);
0072 #endif
0073 }
0074 
0075 void dump_page(struct page *page, const char *reason)
0076 {
0077     __dump_page(page, reason);
0078     dump_page_owner(page);
0079 }
0080 EXPORT_SYMBOL(dump_page);
0081 
0082 #ifdef CONFIG_DEBUG_VM
0083 
0084 void dump_vma(const struct vm_area_struct *vma)
0085 {
0086     pr_emerg("vma %p start %p end %p\n"
0087         "next %p prev %p mm %p\n"
0088         "prot %lx anon_vma %p vm_ops %p\n"
0089         "pgoff %lx file %p private_data %p\n"
0090         "flags: %#lx(%pGv)\n",
0091         vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
0092         vma->vm_prev, vma->vm_mm,
0093         (unsigned long)pgprot_val(vma->vm_page_prot),
0094         vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
0095         vma->vm_file, vma->vm_private_data,
0096         vma->vm_flags, &vma->vm_flags);
0097 }
0098 EXPORT_SYMBOL(dump_vma);
0099 
0100 void dump_mm(const struct mm_struct *mm)
0101 {
0102     pr_emerg("mm %p mmap %p seqnum %d task_size %lu\n"
0103 #ifdef CONFIG_MMU
0104         "get_unmapped_area %p\n"
0105 #endif
0106         "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
0107         "pgd %p mm_users %d mm_count %d nr_ptes %lu nr_pmds %lu map_count %d\n"
0108         "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
0109         "pinned_vm %lx data_vm %lx exec_vm %lx stack_vm %lx\n"
0110         "start_code %lx end_code %lx start_data %lx end_data %lx\n"
0111         "start_brk %lx brk %lx start_stack %lx\n"
0112         "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
0113         "binfmt %p flags %lx core_state %p\n"
0114 #ifdef CONFIG_AIO
0115         "ioctx_table %p\n"
0116 #endif
0117 #ifdef CONFIG_MEMCG
0118         "owner %p "
0119 #endif
0120         "exe_file %p\n"
0121 #ifdef CONFIG_MMU_NOTIFIER
0122         "mmu_notifier_mm %p\n"
0123 #endif
0124 #ifdef CONFIG_NUMA_BALANCING
0125         "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
0126 #endif
0127 #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
0128         "tlb_flush_pending %d\n"
0129 #endif
0130         "def_flags: %#lx(%pGv)\n",
0131 
0132         mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
0133 #ifdef CONFIG_MMU
0134         mm->get_unmapped_area,
0135 #endif
0136         mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
0137         mm->pgd, atomic_read(&mm->mm_users),
0138         atomic_read(&mm->mm_count),
0139         atomic_long_read((atomic_long_t *)&mm->nr_ptes),
0140         mm_nr_pmds((struct mm_struct *)mm),
0141         mm->map_count,
0142         mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
0143         mm->pinned_vm, mm->data_vm, mm->exec_vm, mm->stack_vm,
0144         mm->start_code, mm->end_code, mm->start_data, mm->end_data,
0145         mm->start_brk, mm->brk, mm->start_stack,
0146         mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
0147         mm->binfmt, mm->flags, mm->core_state,
0148 #ifdef CONFIG_AIO
0149         mm->ioctx_table,
0150 #endif
0151 #ifdef CONFIG_MEMCG
0152         mm->owner,
0153 #endif
0154         mm->exe_file,
0155 #ifdef CONFIG_MMU_NOTIFIER
0156         mm->mmu_notifier_mm,
0157 #endif
0158 #ifdef CONFIG_NUMA_BALANCING
0159         mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
0160 #endif
0161 #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
0162         mm->tlb_flush_pending,
0163 #endif
0164         mm->def_flags, &mm->def_flags
0165     );
0166 }
0167 
0168 #endif      /* CONFIG_DEBUG_VM */