| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/mm.h> | 
|  | 2 | #include <linux/hugetlb.h> | 
|  | 3 | #include <linux/mount.h> | 
|  | 4 | #include <linux/seq_file.h> | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 5 | #include <linux/highmem.h> | 
| Christoph Lameter | 6e21c8f | 2005-09-03 15:54:45 -0700 | [diff] [blame] | 6 | #include <linux/pagemap.h> | 
|  | 7 | #include <linux/mempolicy.h> | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 8 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/elf.h> | 
|  | 10 | #include <asm/uaccess.h> | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 11 | #include <asm/tlbflush.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "internal.h" | 
|  | 13 |  | 
|  | 14 | char *task_mem(struct mm_struct *mm, char *buffer) | 
|  | 15 | { | 
|  | 16 | unsigned long data, text, lib; | 
| Hugh Dickins | 365e9c87 | 2005-10-29 18:16:18 -0700 | [diff] [blame] | 17 | unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss; | 
|  | 18 |  | 
|  | 19 | /* | 
|  | 20 | * Note: to minimize their overhead, mm maintains hiwater_vm and | 
|  | 21 | * hiwater_rss only when about to *lower* total_vm or rss.  Any | 
|  | 22 | * collector of these hiwater stats must therefore get total_vm | 
|  | 23 | * and rss too, which will usually be the higher.  Barriers? not | 
|  | 24 | * worth the effort, such snapshots can always be inconsistent. | 
|  | 25 | */ | 
|  | 26 | hiwater_vm = total_vm = mm->total_vm; | 
|  | 27 | if (hiwater_vm < mm->hiwater_vm) | 
|  | 28 | hiwater_vm = mm->hiwater_vm; | 
|  | 29 | hiwater_rss = total_rss = get_mm_rss(mm); | 
|  | 30 | if (hiwater_rss < mm->hiwater_rss) | 
|  | 31 | hiwater_rss = mm->hiwater_rss; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | data = mm->total_vm - mm->shared_vm - mm->stack_vm; | 
|  | 34 | text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; | 
|  | 35 | lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text; | 
|  | 36 | buffer += sprintf(buffer, | 
| Hugh Dickins | 365e9c87 | 2005-10-29 18:16:18 -0700 | [diff] [blame] | 37 | "VmPeak:\t%8lu kB\n" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | "VmSize:\t%8lu kB\n" | 
|  | 39 | "VmLck:\t%8lu kB\n" | 
| Hugh Dickins | 365e9c87 | 2005-10-29 18:16:18 -0700 | [diff] [blame] | 40 | "VmHWM:\t%8lu kB\n" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | "VmRSS:\t%8lu kB\n" | 
|  | 42 | "VmData:\t%8lu kB\n" | 
|  | 43 | "VmStk:\t%8lu kB\n" | 
|  | 44 | "VmExe:\t%8lu kB\n" | 
|  | 45 | "VmLib:\t%8lu kB\n" | 
|  | 46 | "VmPTE:\t%8lu kB\n", | 
| Hugh Dickins | 365e9c87 | 2005-10-29 18:16:18 -0700 | [diff] [blame] | 47 | hiwater_vm << (PAGE_SHIFT-10), | 
|  | 48 | (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | mm->locked_vm << (PAGE_SHIFT-10), | 
| Hugh Dickins | 365e9c87 | 2005-10-29 18:16:18 -0700 | [diff] [blame] | 50 | hiwater_rss << (PAGE_SHIFT-10), | 
|  | 51 | total_rss << (PAGE_SHIFT-10), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | data << (PAGE_SHIFT-10), | 
|  | 53 | mm->stack_vm << (PAGE_SHIFT-10), text, lib, | 
|  | 54 | (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10); | 
|  | 55 | return buffer; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | unsigned long task_vsize(struct mm_struct *mm) | 
|  | 59 | { | 
|  | 60 | return PAGE_SIZE * mm->total_vm; | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | int task_statm(struct mm_struct *mm, int *shared, int *text, | 
|  | 64 | int *data, int *resident) | 
|  | 65 | { | 
| Hugh Dickins | 4294621 | 2005-10-29 18:16:05 -0700 | [diff] [blame] | 66 | *shared = get_mm_counter(mm, file_rss); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) | 
|  | 68 | >> PAGE_SHIFT; | 
|  | 69 | *data = mm->total_vm - mm->shared_vm; | 
| Hugh Dickins | 4294621 | 2005-10-29 18:16:05 -0700 | [diff] [blame] | 70 | *resident = *shared + get_mm_counter(mm, anon_rss); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return mm->total_vm; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) | 
|  | 75 | { | 
|  | 76 | struct vm_area_struct * vma; | 
|  | 77 | int result = -ENOENT; | 
|  | 78 | struct task_struct *task = proc_task(inode); | 
|  | 79 | struct mm_struct * mm = get_task_mm(task); | 
|  | 80 |  | 
|  | 81 | if (!mm) | 
|  | 82 | goto out; | 
|  | 83 | down_read(&mm->mmap_sem); | 
|  | 84 |  | 
|  | 85 | vma = mm->mmap; | 
|  | 86 | while (vma) { | 
|  | 87 | if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) | 
|  | 88 | break; | 
|  | 89 | vma = vma->vm_next; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | if (vma) { | 
|  | 93 | *mnt = mntget(vma->vm_file->f_vfsmnt); | 
|  | 94 | *dentry = dget(vma->vm_file->f_dentry); | 
|  | 95 | result = 0; | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | up_read(&mm->mmap_sem); | 
|  | 99 | mmput(mm); | 
|  | 100 | out: | 
|  | 101 | return result; | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | static void pad_len_spaces(struct seq_file *m, int len) | 
|  | 105 | { | 
|  | 106 | len = 25 + sizeof(void*) * 6 - len; | 
|  | 107 | if (len < 1) | 
|  | 108 | len = 1; | 
|  | 109 | seq_printf(m, "%*c", len, ' '); | 
|  | 110 | } | 
|  | 111 |  | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 112 | struct mem_size_stats | 
|  | 113 | { | 
|  | 114 | unsigned long resident; | 
|  | 115 | unsigned long shared_clean; | 
|  | 116 | unsigned long shared_dirty; | 
|  | 117 | unsigned long private_clean; | 
|  | 118 | unsigned long private_dirty; | 
|  | 119 | }; | 
|  | 120 |  | 
|  | 121 | static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats *mss) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { | 
|  | 123 | struct task_struct *task = m->private; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 124 | struct vm_area_struct *vma = v; | 
|  | 125 | struct mm_struct *mm = vma->vm_mm; | 
|  | 126 | struct file *file = vma->vm_file; | 
|  | 127 | int flags = vma->vm_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | unsigned long ino = 0; | 
|  | 129 | dev_t dev = 0; | 
|  | 130 | int len; | 
|  | 131 |  | 
|  | 132 | if (file) { | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 133 | struct inode *inode = vma->vm_file->f_dentry->d_inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | dev = inode->i_sb->s_dev; | 
|  | 135 | ino = inode->i_ino; | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n", | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 139 | vma->vm_start, | 
|  | 140 | vma->vm_end, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | flags & VM_READ ? 'r' : '-', | 
|  | 142 | flags & VM_WRITE ? 'w' : '-', | 
|  | 143 | flags & VM_EXEC ? 'x' : '-', | 
|  | 144 | flags & VM_MAYSHARE ? 's' : 'p', | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 145 | vma->vm_pgoff << PAGE_SHIFT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | MAJOR(dev), MINOR(dev), ino, &len); | 
|  | 147 |  | 
|  | 148 | /* | 
|  | 149 | * Print the dentry name for named mappings, and a | 
|  | 150 | * special [heap] marker for the heap: | 
|  | 151 | */ | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 152 | if (file) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | pad_len_spaces(m, len); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 154 | seq_path(m, file->f_vfsmnt, file->f_dentry, "\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } else { | 
|  | 156 | if (mm) { | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 157 | if (vma->vm_start <= mm->start_brk && | 
|  | 158 | vma->vm_end >= mm->brk) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | pad_len_spaces(m, len); | 
|  | 160 | seq_puts(m, "[heap]"); | 
|  | 161 | } else { | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 162 | if (vma->vm_start <= mm->start_stack && | 
|  | 163 | vma->vm_end >= mm->start_stack) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
|  | 165 | pad_len_spaces(m, len); | 
|  | 166 | seq_puts(m, "[stack]"); | 
|  | 167 | } | 
|  | 168 | } | 
|  | 169 | } else { | 
|  | 170 | pad_len_spaces(m, len); | 
|  | 171 | seq_puts(m, "[vdso]"); | 
|  | 172 | } | 
|  | 173 | } | 
|  | 174 | seq_putc(m, '\n'); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 175 |  | 
|  | 176 | if (mss) | 
|  | 177 | seq_printf(m, | 
|  | 178 | "Size:          %8lu kB\n" | 
|  | 179 | "Rss:           %8lu kB\n" | 
|  | 180 | "Shared_Clean:  %8lu kB\n" | 
|  | 181 | "Shared_Dirty:  %8lu kB\n" | 
|  | 182 | "Private_Clean: %8lu kB\n" | 
|  | 183 | "Private_Dirty: %8lu kB\n", | 
|  | 184 | (vma->vm_end - vma->vm_start) >> 10, | 
|  | 185 | mss->resident >> 10, | 
|  | 186 | mss->shared_clean  >> 10, | 
|  | 187 | mss->shared_dirty  >> 10, | 
|  | 188 | mss->private_clean >> 10, | 
|  | 189 | mss->private_dirty >> 10); | 
|  | 190 |  | 
|  | 191 | if (m->count < m->size)  /* vma is copied successfully */ | 
|  | 192 | m->version = (vma != get_gate_vma(task))? vma->vm_start: 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return 0; | 
|  | 194 | } | 
|  | 195 |  | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 196 | static int show_map(struct seq_file *m, void *v) | 
|  | 197 | { | 
| Luiz Fernando Capitulino | 0f5c79f | 2005-11-13 16:07:20 -0800 | [diff] [blame] | 198 | return show_map_internal(m, v, NULL); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
|  | 201 | static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd, | 
|  | 202 | unsigned long addr, unsigned long end, | 
|  | 203 | struct mem_size_stats *mss) | 
|  | 204 | { | 
|  | 205 | pte_t *pte, ptent; | 
| Hugh Dickins | 705e87c | 2005-10-29 18:16:27 -0700 | [diff] [blame] | 206 | spinlock_t *ptl; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 207 | struct page *page; | 
|  | 208 |  | 
| Hugh Dickins | 705e87c | 2005-10-29 18:16:27 -0700 | [diff] [blame] | 209 | pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 210 | do { | 
|  | 211 | ptent = *pte; | 
| Hugh Dickins | 705e87c | 2005-10-29 18:16:27 -0700 | [diff] [blame] | 212 | if (!pte_present(ptent)) | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 213 | continue; | 
|  | 214 |  | 
|  | 215 | mss->resident += PAGE_SIZE; | 
| Nick Piggin | ad820c5 | 2006-03-06 15:42:58 -0800 | [diff] [blame] | 216 |  | 
|  | 217 | page = vm_normal_page(vma, addr, ptent); | 
|  | 218 | if (!page) | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 219 | continue; | 
|  | 220 |  | 
| Nick Piggin | ad820c5 | 2006-03-06 15:42:58 -0800 | [diff] [blame] | 221 | if (page_mapcount(page) >= 2) { | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 222 | if (pte_dirty(ptent)) | 
|  | 223 | mss->shared_dirty += PAGE_SIZE; | 
|  | 224 | else | 
|  | 225 | mss->shared_clean += PAGE_SIZE; | 
|  | 226 | } else { | 
|  | 227 | if (pte_dirty(ptent)) | 
|  | 228 | mss->private_dirty += PAGE_SIZE; | 
|  | 229 | else | 
|  | 230 | mss->private_clean += PAGE_SIZE; | 
|  | 231 | } | 
|  | 232 | } while (pte++, addr += PAGE_SIZE, addr != end); | 
| Hugh Dickins | 705e87c | 2005-10-29 18:16:27 -0700 | [diff] [blame] | 233 | pte_unmap_unlock(pte - 1, ptl); | 
|  | 234 | cond_resched(); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 235 | } | 
|  | 236 |  | 
|  | 237 | static inline void smaps_pmd_range(struct vm_area_struct *vma, pud_t *pud, | 
|  | 238 | unsigned long addr, unsigned long end, | 
|  | 239 | struct mem_size_stats *mss) | 
|  | 240 | { | 
|  | 241 | pmd_t *pmd; | 
|  | 242 | unsigned long next; | 
|  | 243 |  | 
|  | 244 | pmd = pmd_offset(pud, addr); | 
|  | 245 | do { | 
|  | 246 | next = pmd_addr_end(addr, end); | 
|  | 247 | if (pmd_none_or_clear_bad(pmd)) | 
|  | 248 | continue; | 
|  | 249 | smaps_pte_range(vma, pmd, addr, next, mss); | 
|  | 250 | } while (pmd++, addr = next, addr != end); | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | static inline void smaps_pud_range(struct vm_area_struct *vma, pgd_t *pgd, | 
|  | 254 | unsigned long addr, unsigned long end, | 
|  | 255 | struct mem_size_stats *mss) | 
|  | 256 | { | 
|  | 257 | pud_t *pud; | 
|  | 258 | unsigned long next; | 
|  | 259 |  | 
|  | 260 | pud = pud_offset(pgd, addr); | 
|  | 261 | do { | 
|  | 262 | next = pud_addr_end(addr, end); | 
|  | 263 | if (pud_none_or_clear_bad(pud)) | 
|  | 264 | continue; | 
|  | 265 | smaps_pmd_range(vma, pud, addr, next, mss); | 
|  | 266 | } while (pud++, addr = next, addr != end); | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 | static inline void smaps_pgd_range(struct vm_area_struct *vma, | 
|  | 270 | unsigned long addr, unsigned long end, | 
|  | 271 | struct mem_size_stats *mss) | 
|  | 272 | { | 
|  | 273 | pgd_t *pgd; | 
|  | 274 | unsigned long next; | 
|  | 275 |  | 
|  | 276 | pgd = pgd_offset(vma->vm_mm, addr); | 
|  | 277 | do { | 
|  | 278 | next = pgd_addr_end(addr, end); | 
|  | 279 | if (pgd_none_or_clear_bad(pgd)) | 
|  | 280 | continue; | 
|  | 281 | smaps_pud_range(vma, pgd, addr, next, mss); | 
|  | 282 | } while (pgd++, addr = next, addr != end); | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | static int show_smap(struct seq_file *m, void *v) | 
|  | 286 | { | 
|  | 287 | struct vm_area_struct *vma = v; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 288 | struct mem_size_stats mss; | 
|  | 289 |  | 
|  | 290 | memset(&mss, 0, sizeof mss); | 
| Nick Piggin | 5ddfae1 | 2006-03-06 15:42:57 -0800 | [diff] [blame] | 291 | if (vma->vm_mm && !is_vm_hugetlb_page(vma)) | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 292 | smaps_pgd_range(vma, vma->vm_start, vma->vm_end, &mss); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 293 | return show_map_internal(m, v, &mss); | 
|  | 294 | } | 
|  | 295 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | static void *m_start(struct seq_file *m, loff_t *pos) | 
|  | 297 | { | 
|  | 298 | struct task_struct *task = m->private; | 
|  | 299 | unsigned long last_addr = m->version; | 
|  | 300 | struct mm_struct *mm; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 301 | struct vm_area_struct *vma, *tail_vma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | loff_t l = *pos; | 
|  | 303 |  | 
|  | 304 | /* | 
|  | 305 | * We remember last_addr rather than next_addr to hit with | 
|  | 306 | * mmap_cache most of the time. We have zero last_addr at | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 307 | * the beginning and also after lseek. We will have -1 last_addr | 
|  | 308 | * after the end of the vmas. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | */ | 
|  | 310 |  | 
|  | 311 | if (last_addr == -1UL) | 
|  | 312 | return NULL; | 
|  | 313 |  | 
|  | 314 | mm = get_task_mm(task); | 
|  | 315 | if (!mm) | 
|  | 316 | return NULL; | 
|  | 317 |  | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 318 | tail_vma = get_gate_vma(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | down_read(&mm->mmap_sem); | 
|  | 320 |  | 
|  | 321 | /* Start with last addr hint */ | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 322 | if (last_addr && (vma = find_vma(mm, last_addr))) { | 
|  | 323 | vma = vma->vm_next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | goto out; | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | /* | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 328 | * Check the vma index is within the range and do | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | * sequential scan until m_index. | 
|  | 330 | */ | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 331 | vma = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if ((unsigned long)l < mm->map_count) { | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 333 | vma = mm->mmap; | 
|  | 334 | while (l-- && vma) | 
|  | 335 | vma = vma->vm_next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | goto out; | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | if (l != mm->map_count) | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 340 | tail_vma = NULL; /* After gate vma */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 |  | 
|  | 342 | out: | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 343 | if (vma) | 
|  | 344 | return vma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 |  | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 346 | /* End of vmas has been reached */ | 
|  | 347 | m->version = (tail_vma != NULL)? 0: -1UL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | up_read(&mm->mmap_sem); | 
|  | 349 | mmput(mm); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 350 | return tail_vma; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } | 
|  | 352 |  | 
|  | 353 | static void m_stop(struct seq_file *m, void *v) | 
|  | 354 | { | 
|  | 355 | struct task_struct *task = m->private; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 356 | struct vm_area_struct *vma = v; | 
|  | 357 | if (vma && vma != get_gate_vma(task)) { | 
|  | 358 | struct mm_struct *mm = vma->vm_mm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | up_read(&mm->mmap_sem); | 
|  | 360 | mmput(mm); | 
|  | 361 | } | 
|  | 362 | } | 
|  | 363 |  | 
|  | 364 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) | 
|  | 365 | { | 
|  | 366 | struct task_struct *task = m->private; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 367 | struct vm_area_struct *vma = v; | 
|  | 368 | struct vm_area_struct *tail_vma = get_gate_vma(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 |  | 
|  | 370 | (*pos)++; | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 371 | if (vma && (vma != tail_vma) && vma->vm_next) | 
|  | 372 | return vma->vm_next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | m_stop(m, v); | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 374 | return (vma != tail_vma)? tail_vma: NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
|  | 377 | struct seq_operations proc_pid_maps_op = { | 
|  | 378 | .start	= m_start, | 
|  | 379 | .next	= m_next, | 
|  | 380 | .stop	= m_stop, | 
|  | 381 | .show	= show_map | 
|  | 382 | }; | 
| Christoph Lameter | 6e21c8f | 2005-09-03 15:54:45 -0700 | [diff] [blame] | 383 |  | 
| Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 384 | struct seq_operations proc_pid_smaps_op = { | 
|  | 385 | .start	= m_start, | 
|  | 386 | .next	= m_next, | 
|  | 387 | .stop	= m_stop, | 
|  | 388 | .show	= show_smap | 
|  | 389 | }; | 
|  | 390 |  | 
| Christoph Lameter | 6e21c8f | 2005-09-03 15:54:45 -0700 | [diff] [blame] | 391 | #ifdef CONFIG_NUMA | 
| Christoph Lameter | 1a75a6c | 2006-01-08 01:01:02 -0800 | [diff] [blame] | 392 | extern int show_numa_map(struct seq_file *m, void *v); | 
| Christoph Lameter | 6e21c8f | 2005-09-03 15:54:45 -0700 | [diff] [blame] | 393 |  | 
|  | 394 | struct seq_operations proc_pid_numa_maps_op = { | 
| Christoph Lameter | 1a75a6c | 2006-01-08 01:01:02 -0800 | [diff] [blame] | 395 | .start  = m_start, | 
|  | 396 | .next   = m_next, | 
|  | 397 | .stop   = m_stop, | 
|  | 398 | .show   = show_numa_map | 
| Christoph Lameter | 6e21c8f | 2005-09-03 15:54:45 -0700 | [diff] [blame] | 399 | }; | 
|  | 400 | #endif |