Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/mm.h> |
2 | #include <linux/hugetlb.h> | |
22e057c5 | 3 | #include <linux/huge_mm.h> |
1da177e4 LT |
4 | #include <linux/mount.h> |
5 | #include <linux/seq_file.h> | |
e070ad49 | 6 | #include <linux/highmem.h> |
5096add8 | 7 | #include <linux/ptrace.h> |
5a0e3ad6 | 8 | #include <linux/slab.h> |
6e21c8f1 CL |
9 | #include <linux/pagemap.h> |
10 | #include <linux/mempolicy.h> | |
22e057c5 | 11 | #include <linux/rmap.h> |
85863e47 MM |
12 | #include <linux/swap.h> |
13 | #include <linux/swapops.h> | |
e070ad49 | 14 | |
1da177e4 LT |
15 | #include <asm/elf.h> |
16 | #include <asm/uaccess.h> | |
e070ad49 | 17 | #include <asm/tlbflush.h> |
1da177e4 LT |
18 | #include "internal.h" |
19 | ||
df5f8314 | 20 | void task_mem(struct seq_file *m, struct mm_struct *mm) |
1da177e4 | 21 | { |
b084d435 | 22 | unsigned long data, text, lib, swap; |
365e9c87 HD |
23 | unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss; |
24 | ||
25 | /* | |
26 | * Note: to minimize their overhead, mm maintains hiwater_vm and | |
27 | * hiwater_rss only when about to *lower* total_vm or rss. Any | |
28 | * collector of these hiwater stats must therefore get total_vm | |
29 | * and rss too, which will usually be the higher. Barriers? not | |
30 | * worth the effort, such snapshots can always be inconsistent. | |
31 | */ | |
32 | hiwater_vm = total_vm = mm->total_vm; | |
33 | if (hiwater_vm < mm->hiwater_vm) | |
34 | hiwater_vm = mm->hiwater_vm; | |
35 | hiwater_rss = total_rss = get_mm_rss(mm); | |
36 | if (hiwater_rss < mm->hiwater_rss) | |
37 | hiwater_rss = mm->hiwater_rss; | |
1da177e4 LT |
38 | |
39 | data = mm->total_vm - mm->shared_vm - mm->stack_vm; | |
40 | text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; | |
41 | lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text; | |
b084d435 | 42 | swap = get_mm_counter(mm, MM_SWAPENTS); |
df5f8314 | 43 | seq_printf(m, |
365e9c87 | 44 | "VmPeak:\t%8lu kB\n" |
1da177e4 LT |
45 | "VmSize:\t%8lu kB\n" |
46 | "VmLck:\t%8lu kB\n" | |
bc3e53f6 | 47 | "VmPin:\t%8lu kB\n" |
365e9c87 | 48 | "VmHWM:\t%8lu kB\n" |
1da177e4 LT |
49 | "VmRSS:\t%8lu kB\n" |
50 | "VmData:\t%8lu kB\n" | |
51 | "VmStk:\t%8lu kB\n" | |
52 | "VmExe:\t%8lu kB\n" | |
53 | "VmLib:\t%8lu kB\n" | |
b084d435 KH |
54 | "VmPTE:\t%8lu kB\n" |
55 | "VmSwap:\t%8lu kB\n", | |
365e9c87 | 56 | hiwater_vm << (PAGE_SHIFT-10), |
314e51b9 | 57 | total_vm << (PAGE_SHIFT-10), |
1da177e4 | 58 | mm->locked_vm << (PAGE_SHIFT-10), |
bc3e53f6 | 59 | mm->pinned_vm << (PAGE_SHIFT-10), |
365e9c87 HD |
60 | hiwater_rss << (PAGE_SHIFT-10), |
61 | total_rss << (PAGE_SHIFT-10), | |
1da177e4 LT |
62 | data << (PAGE_SHIFT-10), |
63 | mm->stack_vm << (PAGE_SHIFT-10), text, lib, | |
b084d435 KH |
64 | (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10, |
65 | swap << (PAGE_SHIFT-10)); | |
1da177e4 LT |
66 | } |
67 | ||
68 | unsigned long task_vsize(struct mm_struct *mm) | |
69 | { | |
70 | return PAGE_SIZE * mm->total_vm; | |
71 | } | |
72 | ||
a2ade7b6 AD |
73 | unsigned long task_statm(struct mm_struct *mm, |
74 | unsigned long *shared, unsigned long *text, | |
75 | unsigned long *data, unsigned long *resident) | |
1da177e4 | 76 | { |
d559db08 | 77 | *shared = get_mm_counter(mm, MM_FILEPAGES); |
1da177e4 LT |
78 | *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) |
79 | >> PAGE_SHIFT; | |
80 | *data = mm->total_vm - mm->shared_vm; | |
d559db08 | 81 | *resident = *shared + get_mm_counter(mm, MM_ANONPAGES); |
1da177e4 LT |
82 | return mm->total_vm; |
83 | } | |
84 | ||
1da177e4 LT |
85 | static void pad_len_spaces(struct seq_file *m, int len) |
86 | { | |
87 | len = 25 + sizeof(void*) * 6 - len; | |
88 | if (len < 1) | |
89 | len = 1; | |
90 | seq_printf(m, "%*c", len, ' '); | |
91 | } | |
92 | ||
9e781440 KH |
93 | #ifdef CONFIG_NUMA |
94 | /* | |
95 | * These functions are for numa_maps but called in generic **maps seq_file | |
96 | * ->start(), ->stop() ops. | |
97 | * | |
98 | * numa_maps scans all vmas under mmap_sem and checks their mempolicy. | |
99 | * Each mempolicy object is controlled by reference counting. The problem here | |
100 | * is how to avoid accessing dead mempolicy object. | |
101 | * | |
102 | * Because we're holding mmap_sem while reading seq_file, it's safe to access | |
103 | * each vma's mempolicy, no vma objects will never drop refs to mempolicy. | |
104 | * | |
105 | * A task's mempolicy (task->mempolicy) has different behavior. task->mempolicy | |
106 | * is set and replaced under mmap_sem but unrefed and cleared under task_lock(). | |
107 | * So, without task_lock(), we cannot trust get_vma_policy() because we cannot | |
108 | * gurantee the task never exits under us. But taking task_lock() around | |
109 | * get_vma_plicy() causes lock order problem. | |
110 | * | |
111 | * To access task->mempolicy without lock, we hold a reference count of an | |
112 | * object pointed by task->mempolicy and remember it. This will guarantee | |
113 | * that task->mempolicy points to an alive object or NULL in numa_maps accesses. | |
114 | */ | |
115 | static void hold_task_mempolicy(struct proc_maps_private *priv) | |
116 | { | |
117 | struct task_struct *task = priv->task; | |
118 | ||
119 | task_lock(task); | |
120 | priv->task_mempolicy = task->mempolicy; | |
121 | mpol_get(priv->task_mempolicy); | |
122 | task_unlock(task); | |
123 | } | |
124 | static void release_task_mempolicy(struct proc_maps_private *priv) | |
125 | { | |
126 | mpol_put(priv->task_mempolicy); | |
127 | } | |
128 | #else | |
129 | static void hold_task_mempolicy(struct proc_maps_private *priv) | |
130 | { | |
131 | } | |
132 | static void release_task_mempolicy(struct proc_maps_private *priv) | |
133 | { | |
134 | } | |
135 | #endif | |
136 | ||
6fa3eb70 S |
137 | static void seq_print_vma_name(struct seq_file *m, struct vm_area_struct *vma) |
138 | { | |
139 | const char __user *name = vma_get_anon_name(vma); | |
140 | struct mm_struct *mm = vma->vm_mm; | |
141 | ||
142 | unsigned long page_start_vaddr; | |
143 | unsigned long page_offset; | |
144 | unsigned long num_pages; | |
145 | unsigned long max_len = NAME_MAX; | |
146 | int i; | |
147 | ||
148 | page_start_vaddr = (unsigned long)name & PAGE_MASK; | |
149 | page_offset = (unsigned long)name - page_start_vaddr; | |
150 | num_pages = DIV_ROUND_UP(page_offset + max_len, PAGE_SIZE); | |
151 | ||
152 | seq_puts(m, "[anon:"); | |
153 | ||
154 | for (i = 0; i < num_pages; i++) { | |
155 | int len; | |
156 | int write_len; | |
157 | const char *kaddr; | |
158 | long pages_pinned; | |
159 | struct page *page; | |
160 | ||
161 | pages_pinned = get_user_pages(current, mm, page_start_vaddr, | |
162 | 1, 0, 0, &page, NULL); | |
163 | if (pages_pinned < 1) { | |
164 | seq_puts(m, "<fault>]"); | |
165 | return; | |
166 | } | |
167 | ||
168 | kaddr = (const char *)kmap(page); | |
169 | len = min(max_len, PAGE_SIZE - page_offset); | |
170 | write_len = strnlen(kaddr + page_offset, len); | |
171 | seq_write(m, kaddr + page_offset, write_len); | |
172 | kunmap(page); | |
173 | put_page(page); | |
174 | ||
175 | /* if strnlen hit a null terminator then we're done */ | |
176 | if (write_len != len) | |
177 | break; | |
178 | ||
179 | max_len -= len; | |
180 | page_offset = 0; | |
181 | page_start_vaddr += PAGE_SIZE; | |
182 | } | |
183 | ||
184 | seq_putc(m, ']'); | |
185 | } | |
186 | ||
a6198797 MM |
187 | static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma) |
188 | { | |
189 | if (vma && vma != priv->tail_vma) { | |
190 | struct mm_struct *mm = vma->vm_mm; | |
9e781440 | 191 | release_task_mempolicy(priv); |
a6198797 MM |
192 | up_read(&mm->mmap_sem); |
193 | mmput(mm); | |
194 | } | |
195 | } | |
ec4dd3eb | 196 | |
a6198797 | 197 | static void *m_start(struct seq_file *m, loff_t *pos) |
e070ad49 | 198 | { |
a6198797 MM |
199 | struct proc_maps_private *priv = m->private; |
200 | unsigned long last_addr = m->version; | |
201 | struct mm_struct *mm; | |
202 | struct vm_area_struct *vma, *tail_vma = NULL; | |
203 | loff_t l = *pos; | |
204 | ||
205 | /* Clear the per syscall fields in priv */ | |
206 | priv->task = NULL; | |
207 | priv->tail_vma = NULL; | |
208 | ||
209 | /* | |
210 | * We remember last_addr rather than next_addr to hit with | |
211 | * mmap_cache most of the time. We have zero last_addr at | |
212 | * the beginning and also after lseek. We will have -1 last_addr | |
213 | * after the end of the vmas. | |
214 | */ | |
215 | ||
216 | if (last_addr == -1UL) | |
217 | return NULL; | |
218 | ||
219 | priv->task = get_pid_task(priv->pid, PIDTYPE_PID); | |
220 | if (!priv->task) | |
ec6fd8a4 | 221 | return ERR_PTR(-ESRCH); |
a6198797 | 222 | |
b048b93f | 223 | mm = mm_access(priv->task, PTRACE_MODE_READ_FSCREDS); |
ec6fd8a4 AV |
224 | if (!mm || IS_ERR(mm)) |
225 | return mm; | |
00f89d21 | 226 | down_read(&mm->mmap_sem); |
a6198797 | 227 | |
31db58b3 | 228 | tail_vma = get_gate_vma(priv->task->mm); |
a6198797 | 229 | priv->tail_vma = tail_vma; |
9e781440 | 230 | hold_task_mempolicy(priv); |
a6198797 MM |
231 | /* Start with last addr hint */ |
232 | vma = find_vma(mm, last_addr); | |
233 | if (last_addr && vma) { | |
234 | vma = vma->vm_next; | |
235 | goto out; | |
236 | } | |
237 | ||
238 | /* | |
239 | * Check the vma index is within the range and do | |
240 | * sequential scan until m_index. | |
241 | */ | |
242 | vma = NULL; | |
243 | if ((unsigned long)l < mm->map_count) { | |
244 | vma = mm->mmap; | |
245 | while (l-- && vma) | |
246 | vma = vma->vm_next; | |
247 | goto out; | |
248 | } | |
249 | ||
250 | if (l != mm->map_count) | |
251 | tail_vma = NULL; /* After gate vma */ | |
252 | ||
253 | out: | |
254 | if (vma) | |
255 | return vma; | |
256 | ||
9e781440 | 257 | release_task_mempolicy(priv); |
a6198797 MM |
258 | /* End of vmas has been reached */ |
259 | m->version = (tail_vma != NULL)? 0: -1UL; | |
260 | up_read(&mm->mmap_sem); | |
261 | mmput(mm); | |
262 | return tail_vma; | |
263 | } | |
264 | ||
265 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) | |
266 | { | |
267 | struct proc_maps_private *priv = m->private; | |
268 | struct vm_area_struct *vma = v; | |
269 | struct vm_area_struct *tail_vma = priv->tail_vma; | |
270 | ||
271 | (*pos)++; | |
272 | if (vma && (vma != tail_vma) && vma->vm_next) | |
273 | return vma->vm_next; | |
274 | vma_stop(priv, vma); | |
275 | return (vma != tail_vma)? tail_vma: NULL; | |
276 | } | |
277 | ||
278 | static void m_stop(struct seq_file *m, void *v) | |
279 | { | |
280 | struct proc_maps_private *priv = m->private; | |
281 | struct vm_area_struct *vma = v; | |
282 | ||
76597cd3 LT |
283 | if (!IS_ERR(vma)) |
284 | vma_stop(priv, vma); | |
a6198797 MM |
285 | if (priv->task) |
286 | put_task_struct(priv->task); | |
287 | } | |
288 | ||
289 | static int do_maps_open(struct inode *inode, struct file *file, | |
03a44825 | 290 | const struct seq_operations *ops) |
a6198797 MM |
291 | { |
292 | struct proc_maps_private *priv; | |
293 | int ret = -ENOMEM; | |
294 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | |
295 | if (priv) { | |
296 | priv->pid = proc_pid(inode); | |
297 | ret = seq_open(file, ops); | |
298 | if (!ret) { | |
299 | struct seq_file *m = file->private_data; | |
300 | m->private = priv; | |
301 | } else { | |
302 | kfree(priv); | |
303 | } | |
304 | } | |
305 | return ret; | |
306 | } | |
e070ad49 | 307 | |
b7643757 SP |
308 | static void |
309 | show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) | |
1da177e4 | 310 | { |
e070ad49 ML |
311 | struct mm_struct *mm = vma->vm_mm; |
312 | struct file *file = vma->vm_file; | |
b7643757 SP |
313 | struct proc_maps_private *priv = m->private; |
314 | struct task_struct *task = priv->task; | |
ca16d140 | 315 | vm_flags_t flags = vma->vm_flags; |
1da177e4 | 316 | unsigned long ino = 0; |
6260a4b0 | 317 | unsigned long long pgoff = 0; |
a09a79f6 | 318 | unsigned long start, end; |
1da177e4 LT |
319 | dev_t dev = 0; |
320 | int len; | |
b7643757 | 321 | const char *name = NULL; |
1da177e4 LT |
322 | |
323 | if (file) { | |
496ad9aa | 324 | struct inode *inode = file_inode(vma->vm_file); |
1da177e4 LT |
325 | dev = inode->i_sb->s_dev; |
326 | ino = inode->i_ino; | |
6260a4b0 | 327 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; |
1da177e4 LT |
328 | } |
329 | ||
d7824370 LT |
330 | /* We don't show the stack guard page in /proc/maps */ |
331 | start = vma->vm_start; | |
a09a79f6 | 332 | end = vma->vm_end; |
d7824370 | 333 | |
1804dc6e | 334 | seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n", |
d7824370 | 335 | start, |
a09a79f6 | 336 | end, |
1da177e4 LT |
337 | flags & VM_READ ? 'r' : '-', |
338 | flags & VM_WRITE ? 'w' : '-', | |
339 | flags & VM_EXEC ? 'x' : '-', | |
340 | flags & VM_MAYSHARE ? 's' : 'p', | |
6260a4b0 | 341 | pgoff, |
1da177e4 LT |
342 | MAJOR(dev), MINOR(dev), ino, &len); |
343 | ||
344 | /* | |
345 | * Print the dentry name for named mappings, and a | |
346 | * special [heap] marker for the heap: | |
347 | */ | |
e070ad49 | 348 | if (file) { |
1da177e4 | 349 | pad_len_spaces(m, len); |
c32c2f63 | 350 | seq_path(m, &file->f_path, "\n"); |
b7643757 SP |
351 | goto done; |
352 | } | |
353 | ||
354 | name = arch_vma_name(vma); | |
355 | if (!name) { | |
356 | pid_t tid; | |
357 | ||
358 | if (!mm) { | |
359 | name = "[vdso]"; | |
360 | goto done; | |
361 | } | |
362 | ||
363 | if (vma->vm_start <= mm->brk && | |
364 | vma->vm_end >= mm->start_brk) { | |
365 | name = "[heap]"; | |
366 | goto done; | |
367 | } | |
368 | ||
369 | tid = vm_is_stack(task, vma, is_pid); | |
370 | ||
371 | if (tid != 0) { | |
372 | /* | |
373 | * Thread stack in /proc/PID/task/TID/maps or | |
374 | * the main process stack. | |
375 | */ | |
376 | if (!is_pid || (vma->vm_start <= mm->start_stack && | |
377 | vma->vm_end >= mm->start_stack)) { | |
378 | name = "[stack]"; | |
e6e5494c | 379 | } else { |
b7643757 SP |
380 | /* Thread stack in /proc/PID/maps */ |
381 | pad_len_spaces(m, len); | |
382 | seq_printf(m, "[stack:%d]", tid); | |
1da177e4 | 383 | } |
6fa3eb70 S |
384 | goto done; |
385 | } | |
386 | ||
387 | if (vma_get_anon_name(vma)) { | |
388 | pad_len_spaces(m, len); | |
389 | seq_print_vma_name(m, vma); | |
e6e5494c | 390 | } |
b7643757 SP |
391 | } |
392 | ||
393 | done: | |
394 | if (name) { | |
395 | pad_len_spaces(m, len); | |
396 | seq_puts(m, name); | |
1da177e4 LT |
397 | } |
398 | seq_putc(m, '\n'); | |
7c88db0c JK |
399 | } |
400 | ||
b7643757 | 401 | static int show_map(struct seq_file *m, void *v, int is_pid) |
7c88db0c JK |
402 | { |
403 | struct vm_area_struct *vma = v; | |
404 | struct proc_maps_private *priv = m->private; | |
405 | struct task_struct *task = priv->task; | |
406 | ||
b7643757 | 407 | show_map_vma(m, vma, is_pid); |
e070ad49 | 408 | |
e070ad49 | 409 | if (m->count < m->size) /* vma is copied successfully */ |
31db58b3 SW |
410 | m->version = (vma != get_gate_vma(task->mm)) |
411 | ? vma->vm_start : 0; | |
1da177e4 LT |
412 | return 0; |
413 | } | |
414 | ||
b7643757 SP |
415 | static int show_pid_map(struct seq_file *m, void *v) |
416 | { | |
417 | return show_map(m, v, 1); | |
418 | } | |
419 | ||
420 | static int show_tid_map(struct seq_file *m, void *v) | |
421 | { | |
422 | return show_map(m, v, 0); | |
423 | } | |
424 | ||
03a44825 | 425 | static const struct seq_operations proc_pid_maps_op = { |
a6198797 MM |
426 | .start = m_start, |
427 | .next = m_next, | |
428 | .stop = m_stop, | |
b7643757 SP |
429 | .show = show_pid_map |
430 | }; | |
431 | ||
432 | static const struct seq_operations proc_tid_maps_op = { | |
433 | .start = m_start, | |
434 | .next = m_next, | |
435 | .stop = m_stop, | |
436 | .show = show_tid_map | |
a6198797 MM |
437 | }; |
438 | ||
b7643757 | 439 | static int pid_maps_open(struct inode *inode, struct file *file) |
a6198797 MM |
440 | { |
441 | return do_maps_open(inode, file, &proc_pid_maps_op); | |
442 | } | |
443 | ||
b7643757 SP |
444 | static int tid_maps_open(struct inode *inode, struct file *file) |
445 | { | |
446 | return do_maps_open(inode, file, &proc_tid_maps_op); | |
447 | } | |
448 | ||
449 | const struct file_operations proc_pid_maps_operations = { | |
450 | .open = pid_maps_open, | |
451 | .read = seq_read, | |
452 | .llseek = seq_lseek, | |
453 | .release = seq_release_private, | |
454 | }; | |
455 | ||
456 | const struct file_operations proc_tid_maps_operations = { | |
457 | .open = tid_maps_open, | |
a6198797 MM |
458 | .read = seq_read, |
459 | .llseek = seq_lseek, | |
460 | .release = seq_release_private, | |
461 | }; | |
462 | ||
463 | /* | |
464 | * Proportional Set Size(PSS): my share of RSS. | |
465 | * | |
466 | * PSS of a process is the count of pages it has in memory, where each | |
467 | * page is divided by the number of processes sharing it. So if a | |
468 | * process has 1000 pages all to itself, and 1000 shared with one other | |
469 | * process, its PSS will be 1500. | |
470 | * | |
471 | * To keep (accumulated) division errors low, we adopt a 64bit | |
472 | * fixed-point pss counter to minimize division errors. So (pss >> | |
473 | * PSS_SHIFT) would be the real byte count. | |
474 | * | |
475 | * A shift of 12 before division means (assuming 4K page size): | |
476 | * - 1M 3-user-pages add up to 8KB errors; | |
477 | * - supports mapcount up to 2^24, or 16M; | |
478 | * - supports PSS up to 2^52 bytes, or 4PB. | |
479 | */ | |
480 | #define PSS_SHIFT 12 | |
481 | ||
1e883281 | 482 | #ifdef CONFIG_PROC_PAGE_MONITOR |
214e471f | 483 | struct mem_size_stats { |
a6198797 MM |
484 | struct vm_area_struct *vma; |
485 | unsigned long resident; | |
486 | unsigned long shared_clean; | |
487 | unsigned long shared_dirty; | |
488 | unsigned long private_clean; | |
489 | unsigned long private_dirty; | |
490 | unsigned long referenced; | |
b40d4f84 | 491 | unsigned long anonymous; |
4031a219 | 492 | unsigned long anonymous_thp; |
214e471f | 493 | unsigned long swap; |
bca15543 | 494 | unsigned long nonlinear; |
a6198797 | 495 | u64 pss; |
6fa3eb70 | 496 | u64 pswap; |
a6198797 MM |
497 | }; |
498 | ||
6fa3eb70 S |
499 | #ifdef CONFIG_SWAP |
500 | extern struct swap_info_struct *swap_info_get(swp_entry_t entry); | |
501 | extern void swap_info_unlock(struct swap_info_struct *si); | |
502 | #endif // CONFIG_SWAP | |
503 | ||
504 | static inline unsigned char swap_count(unsigned char ent) | |
505 | { | |
506 | return ent & ~SWAP_HAS_CACHE; /* may include SWAP_HAS_CONT flag */ | |
507 | } | |
ae11c4d9 DH |
508 | |
509 | static void smaps_pte_entry(pte_t ptent, unsigned long addr, | |
3c9acc78 | 510 | unsigned long ptent_size, struct mm_walk *walk) |
ae11c4d9 DH |
511 | { |
512 | struct mem_size_stats *mss = walk->private; | |
513 | struct vm_area_struct *vma = mss->vma; | |
bca15543 | 514 | pgoff_t pgoff = linear_page_index(vma, addr); |
b1d4d9e0 | 515 | struct page *page = NULL; |
ae11c4d9 DH |
516 | int mapcount; |
517 | ||
b1d4d9e0 KK |
518 | if (pte_present(ptent)) { |
519 | page = vm_normal_page(vma, addr, ptent); | |
520 | } else if (is_swap_pte(ptent)) { | |
521 | swp_entry_t swpent = pte_to_swp_entry(ptent); | |
ae11c4d9 | 522 | |
6fa3eb70 S |
523 | if (!non_swap_entry(swpent)) { |
524 | #ifdef CONFIG_SWAP | |
525 | swp_entry_t entry; | |
526 | struct swap_info_struct *p; | |
527 | #endif // CONFIG_SWAP | |
528 | ||
b1d4d9e0 | 529 | mss->swap += ptent_size; |
6fa3eb70 S |
530 | |
531 | #ifdef CONFIG_SWAP | |
532 | entry = pte_to_swp_entry(ptent); | |
533 | if (non_swap_entry(entry)) | |
534 | return; | |
535 | p = swap_info_get(entry); | |
536 | if (p) { | |
537 | int swapcount = swap_count(p->swap_map[swp_offset(entry)]); | |
538 | if (swapcount == 0) { | |
539 | swapcount = 1; | |
540 | } | |
541 | mss->pswap += (ptent_size << PSS_SHIFT) / swapcount; | |
542 | swap_info_unlock(p); | |
543 | } | |
544 | #endif // CONFIG_SWAP | |
545 | } else if (is_migration_entry(swpent)) | |
b1d4d9e0 | 546 | page = migration_entry_to_page(swpent); |
bca15543 KK |
547 | } else if (pte_file(ptent)) { |
548 | if (pte_to_pgoff(ptent) != pgoff) | |
549 | mss->nonlinear += ptent_size; | |
b1d4d9e0 | 550 | } |
ae11c4d9 | 551 | |
ae11c4d9 DH |
552 | if (!page) |
553 | return; | |
554 | ||
555 | if (PageAnon(page)) | |
3c9acc78 | 556 | mss->anonymous += ptent_size; |
ae11c4d9 | 557 | |
bca15543 KK |
558 | if (page->index != pgoff) |
559 | mss->nonlinear += ptent_size; | |
560 | ||
3c9acc78 | 561 | mss->resident += ptent_size; |
ae11c4d9 DH |
562 | /* Accumulate the size in pages that have been accessed. */ |
563 | if (pte_young(ptent) || PageReferenced(page)) | |
3c9acc78 | 564 | mss->referenced += ptent_size; |
ae11c4d9 DH |
565 | mapcount = page_mapcount(page); |
566 | if (mapcount >= 2) { | |
567 | if (pte_dirty(ptent) || PageDirty(page)) | |
3c9acc78 | 568 | mss->shared_dirty += ptent_size; |
ae11c4d9 | 569 | else |
3c9acc78 DH |
570 | mss->shared_clean += ptent_size; |
571 | mss->pss += (ptent_size << PSS_SHIFT) / mapcount; | |
ae11c4d9 DH |
572 | } else { |
573 | if (pte_dirty(ptent) || PageDirty(page)) | |
3c9acc78 | 574 | mss->private_dirty += ptent_size; |
ae11c4d9 | 575 | else |
3c9acc78 DH |
576 | mss->private_clean += ptent_size; |
577 | mss->pss += (ptent_size << PSS_SHIFT); | |
ae11c4d9 DH |
578 | } |
579 | } | |
580 | ||
b3ae5acb | 581 | static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, |
2165009b | 582 | struct mm_walk *walk) |
e070ad49 | 583 | { |
2165009b | 584 | struct mem_size_stats *mss = walk->private; |
b3ae5acb | 585 | struct vm_area_struct *vma = mss->vma; |
ae11c4d9 | 586 | pte_t *pte; |
705e87c0 | 587 | spinlock_t *ptl; |
e070ad49 | 588 | |
025c5b24 NH |
589 | if (pmd_trans_huge_lock(pmd, vma) == 1) { |
590 | smaps_pte_entry(*(pte_t *)pmd, addr, HPAGE_PMD_SIZE, walk); | |
22e057c5 | 591 | spin_unlock(&walk->mm->page_table_lock); |
025c5b24 NH |
592 | mss->anonymous_thp += HPAGE_PMD_SIZE; |
593 | return 0; | |
22e057c5 | 594 | } |
1a5a9906 AA |
595 | |
596 | if (pmd_trans_unstable(pmd)) | |
597 | return 0; | |
22e057c5 DH |
598 | /* |
599 | * The mmap_sem held all the way back in m_start() is what | |
600 | * keeps khugepaged out of here and from collapsing things | |
601 | * in here. | |
602 | */ | |
705e87c0 | 603 | pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); |
ae11c4d9 | 604 | for (; addr != end; pte++, addr += PAGE_SIZE) |
3c9acc78 | 605 | smaps_pte_entry(*pte, addr, PAGE_SIZE, walk); |
705e87c0 HD |
606 | pte_unmap_unlock(pte - 1, ptl); |
607 | cond_resched(); | |
b3ae5acb | 608 | return 0; |
e070ad49 ML |
609 | } |
610 | ||
834f82e2 CG |
611 | static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) |
612 | { | |
613 | /* | |
614 | * Don't forget to update Documentation/ on changes. | |
615 | */ | |
616 | static const char mnemonics[BITS_PER_LONG][2] = { | |
617 | /* | |
618 | * In case if we meet a flag we don't know about. | |
619 | */ | |
620 | [0 ... (BITS_PER_LONG-1)] = "??", | |
621 | ||
622 | [ilog2(VM_READ)] = "rd", | |
623 | [ilog2(VM_WRITE)] = "wr", | |
624 | [ilog2(VM_EXEC)] = "ex", | |
625 | [ilog2(VM_SHARED)] = "sh", | |
626 | [ilog2(VM_MAYREAD)] = "mr", | |
627 | [ilog2(VM_MAYWRITE)] = "mw", | |
628 | [ilog2(VM_MAYEXEC)] = "me", | |
629 | [ilog2(VM_MAYSHARE)] = "ms", | |
630 | [ilog2(VM_GROWSDOWN)] = "gd", | |
631 | [ilog2(VM_PFNMAP)] = "pf", | |
632 | [ilog2(VM_DENYWRITE)] = "dw", | |
633 | [ilog2(VM_LOCKED)] = "lo", | |
634 | [ilog2(VM_IO)] = "io", | |
635 | [ilog2(VM_SEQ_READ)] = "sr", | |
636 | [ilog2(VM_RAND_READ)] = "rr", | |
637 | [ilog2(VM_DONTCOPY)] = "dc", | |
638 | [ilog2(VM_DONTEXPAND)] = "de", | |
639 | [ilog2(VM_ACCOUNT)] = "ac", | |
640 | [ilog2(VM_NORESERVE)] = "nr", | |
641 | [ilog2(VM_HUGETLB)] = "ht", | |
642 | [ilog2(VM_NONLINEAR)] = "nl", | |
643 | [ilog2(VM_ARCH_1)] = "ar", | |
644 | [ilog2(VM_DONTDUMP)] = "dd", | |
645 | [ilog2(VM_MIXEDMAP)] = "mm", | |
646 | [ilog2(VM_HUGEPAGE)] = "hg", | |
647 | [ilog2(VM_NOHUGEPAGE)] = "nh", | |
648 | [ilog2(VM_MERGEABLE)] = "mg", | |
649 | }; | |
650 | size_t i; | |
651 | ||
652 | seq_puts(m, "VmFlags: "); | |
653 | for (i = 0; i < BITS_PER_LONG; i++) { | |
654 | if (vma->vm_flags & (1UL << i)) { | |
655 | seq_printf(m, "%c%c ", | |
656 | mnemonics[i][0], mnemonics[i][1]); | |
657 | } | |
658 | } | |
659 | seq_putc(m, '\n'); | |
660 | } | |
661 | ||
b7643757 | 662 | static int show_smap(struct seq_file *m, void *v, int is_pid) |
e070ad49 | 663 | { |
7c88db0c JK |
664 | struct proc_maps_private *priv = m->private; |
665 | struct task_struct *task = priv->task; | |
e070ad49 | 666 | struct vm_area_struct *vma = v; |
e070ad49 | 667 | struct mem_size_stats mss; |
2165009b DH |
668 | struct mm_walk smaps_walk = { |
669 | .pmd_entry = smaps_pte_range, | |
670 | .mm = vma->vm_mm, | |
671 | .private = &mss, | |
672 | }; | |
e070ad49 ML |
673 | |
674 | memset(&mss, 0, sizeof mss); | |
b3ae5acb | 675 | mss.vma = vma; |
d82ef020 | 676 | /* mmap_sem is held in m_start */ |
5ddfae16 | 677 | if (vma->vm_mm && !is_vm_hugetlb_page(vma)) |
2165009b | 678 | walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk); |
4752c369 | 679 | |
b7643757 | 680 | show_map_vma(m, vma, is_pid); |
4752c369 MM |
681 | |
682 | seq_printf(m, | |
683 | "Size: %8lu kB\n" | |
684 | "Rss: %8lu kB\n" | |
685 | "Pss: %8lu kB\n" | |
686 | "Shared_Clean: %8lu kB\n" | |
687 | "Shared_Dirty: %8lu kB\n" | |
688 | "Private_Clean: %8lu kB\n" | |
689 | "Private_Dirty: %8lu kB\n" | |
214e471f | 690 | "Referenced: %8lu kB\n" |
b40d4f84 | 691 | "Anonymous: %8lu kB\n" |
4031a219 | 692 | "AnonHugePages: %8lu kB\n" |
08fba699 | 693 | "Swap: %8lu kB\n" |
6fa3eb70 | 694 | "PSwap: %8lu kB\n" |
3340289d | 695 | "KernelPageSize: %8lu kB\n" |
2d90508f NK |
696 | "MMUPageSize: %8lu kB\n" |
697 | "Locked: %8lu kB\n", | |
4752c369 MM |
698 | (vma->vm_end - vma->vm_start) >> 10, |
699 | mss.resident >> 10, | |
700 | (unsigned long)(mss.pss >> (10 + PSS_SHIFT)), | |
701 | mss.shared_clean >> 10, | |
702 | mss.shared_dirty >> 10, | |
703 | mss.private_clean >> 10, | |
704 | mss.private_dirty >> 10, | |
214e471f | 705 | mss.referenced >> 10, |
b40d4f84 | 706 | mss.anonymous >> 10, |
4031a219 | 707 | mss.anonymous_thp >> 10, |
08fba699 | 708 | mss.swap >> 10, |
6fa3eb70 | 709 | (unsigned long)(mss.pswap >> (10 + PSS_SHIFT)), |
3340289d | 710 | vma_kernel_pagesize(vma) >> 10, |
2d90508f NK |
711 | vma_mmu_pagesize(vma) >> 10, |
712 | (vma->vm_flags & VM_LOCKED) ? | |
713 | (unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0); | |
4752c369 | 714 | |
bca15543 KK |
715 | if (vma->vm_flags & VM_NONLINEAR) |
716 | seq_printf(m, "Nonlinear: %8lu kB\n", | |
717 | mss.nonlinear >> 10); | |
718 | ||
834f82e2 CG |
719 | show_smap_vma_flags(m, vma); |
720 | ||
6fa3eb70 S |
721 | if (vma_get_anon_name(vma)) { |
722 | seq_puts(m, "Name: "); | |
723 | seq_print_vma_name(m, vma); | |
724 | seq_putc(m, '\n'); | |
725 | } | |
726 | ||
7c88db0c | 727 | if (m->count < m->size) /* vma is copied successfully */ |
31db58b3 SW |
728 | m->version = (vma != get_gate_vma(task->mm)) |
729 | ? vma->vm_start : 0; | |
7c88db0c | 730 | return 0; |
e070ad49 ML |
731 | } |
732 | ||
b7643757 SP |
733 | static int show_pid_smap(struct seq_file *m, void *v) |
734 | { | |
735 | return show_smap(m, v, 1); | |
736 | } | |
737 | ||
738 | static int show_tid_smap(struct seq_file *m, void *v) | |
739 | { | |
740 | return show_smap(m, v, 0); | |
741 | } | |
742 | ||
03a44825 | 743 | static const struct seq_operations proc_pid_smaps_op = { |
a6198797 MM |
744 | .start = m_start, |
745 | .next = m_next, | |
746 | .stop = m_stop, | |
b7643757 SP |
747 | .show = show_pid_smap |
748 | }; | |
749 | ||
750 | static const struct seq_operations proc_tid_smaps_op = { | |
751 | .start = m_start, | |
752 | .next = m_next, | |
753 | .stop = m_stop, | |
754 | .show = show_tid_smap | |
a6198797 MM |
755 | }; |
756 | ||
b7643757 | 757 | static int pid_smaps_open(struct inode *inode, struct file *file) |
a6198797 MM |
758 | { |
759 | return do_maps_open(inode, file, &proc_pid_smaps_op); | |
760 | } | |
761 | ||
b7643757 SP |
762 | static int tid_smaps_open(struct inode *inode, struct file *file) |
763 | { | |
764 | return do_maps_open(inode, file, &proc_tid_smaps_op); | |
765 | } | |
766 | ||
767 | const struct file_operations proc_pid_smaps_operations = { | |
768 | .open = pid_smaps_open, | |
769 | .read = seq_read, | |
770 | .llseek = seq_lseek, | |
771 | .release = seq_release_private, | |
772 | }; | |
773 | ||
774 | const struct file_operations proc_tid_smaps_operations = { | |
775 | .open = tid_smaps_open, | |
a6198797 MM |
776 | .read = seq_read, |
777 | .llseek = seq_lseek, | |
778 | .release = seq_release_private, | |
779 | }; | |
780 | ||
781 | static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr, | |
2165009b | 782 | unsigned long end, struct mm_walk *walk) |
a6198797 | 783 | { |
2165009b | 784 | struct vm_area_struct *vma = walk->private; |
a6198797 MM |
785 | pte_t *pte, ptent; |
786 | spinlock_t *ptl; | |
787 | struct page *page; | |
788 | ||
e180377f | 789 | split_huge_page_pmd(vma, addr, pmd); |
1a5a9906 AA |
790 | if (pmd_trans_unstable(pmd)) |
791 | return 0; | |
03319327 | 792 | |
a6198797 MM |
793 | pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); |
794 | for (; addr != end; pte++, addr += PAGE_SIZE) { | |
795 | ptent = *pte; | |
796 | if (!pte_present(ptent)) | |
797 | continue; | |
798 | ||
799 | page = vm_normal_page(vma, addr, ptent); | |
800 | if (!page) | |
801 | continue; | |
802 | ||
803 | /* Clear accessed and referenced bits. */ | |
804 | ptep_test_and_clear_young(vma, addr, pte); | |
805 | ClearPageReferenced(page); | |
806 | } | |
807 | pte_unmap_unlock(pte - 1, ptl); | |
808 | cond_resched(); | |
809 | return 0; | |
810 | } | |
811 | ||
398499d5 MB |
812 | #define CLEAR_REFS_ALL 1 |
813 | #define CLEAR_REFS_ANON 2 | |
814 | #define CLEAR_REFS_MAPPED 3 | |
815 | ||
f248dcb3 MM |
816 | static ssize_t clear_refs_write(struct file *file, const char __user *buf, |
817 | size_t count, loff_t *ppos) | |
b813e931 | 818 | { |
f248dcb3 | 819 | struct task_struct *task; |
fb92a4b0 | 820 | char buffer[PROC_NUMBUF]; |
f248dcb3 | 821 | struct mm_struct *mm; |
b813e931 | 822 | struct vm_area_struct *vma; |
0a8cb8e3 AD |
823 | int type; |
824 | int rv; | |
b813e931 | 825 | |
f248dcb3 MM |
826 | memset(buffer, 0, sizeof(buffer)); |
827 | if (count > sizeof(buffer) - 1) | |
828 | count = sizeof(buffer) - 1; | |
829 | if (copy_from_user(buffer, buf, count)) | |
830 | return -EFAULT; | |
0a8cb8e3 AD |
831 | rv = kstrtoint(strstrip(buffer), 10, &type); |
832 | if (rv < 0) | |
833 | return rv; | |
398499d5 | 834 | if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED) |
f248dcb3 | 835 | return -EINVAL; |
496ad9aa | 836 | task = get_proc_task(file_inode(file)); |
f248dcb3 MM |
837 | if (!task) |
838 | return -ESRCH; | |
839 | mm = get_task_mm(task); | |
840 | if (mm) { | |
20cbc972 AM |
841 | struct mm_walk clear_refs_walk = { |
842 | .pmd_entry = clear_refs_pte_range, | |
843 | .mm = mm, | |
844 | }; | |
f248dcb3 | 845 | down_read(&mm->mmap_sem); |
2165009b DH |
846 | for (vma = mm->mmap; vma; vma = vma->vm_next) { |
847 | clear_refs_walk.private = vma; | |
398499d5 MB |
848 | if (is_vm_hugetlb_page(vma)) |
849 | continue; | |
850 | /* | |
851 | * Writing 1 to /proc/pid/clear_refs affects all pages. | |
852 | * | |
853 | * Writing 2 to /proc/pid/clear_refs only affects | |
854 | * Anonymous pages. | |
855 | * | |
856 | * Writing 3 to /proc/pid/clear_refs only affects file | |
857 | * mapped pages. | |
858 | */ | |
859 | if (type == CLEAR_REFS_ANON && vma->vm_file) | |
860 | continue; | |
861 | if (type == CLEAR_REFS_MAPPED && !vma->vm_file) | |
862 | continue; | |
863 | walk_page_range(vma->vm_start, vma->vm_end, | |
864 | &clear_refs_walk); | |
2165009b | 865 | } |
f248dcb3 MM |
866 | flush_tlb_mm(mm); |
867 | up_read(&mm->mmap_sem); | |
868 | mmput(mm); | |
869 | } | |
870 | put_task_struct(task); | |
fb92a4b0 VL |
871 | |
872 | return count; | |
b813e931 DR |
873 | } |
874 | ||
f248dcb3 MM |
875 | const struct file_operations proc_clear_refs_operations = { |
876 | .write = clear_refs_write, | |
6038f373 | 877 | .llseek = noop_llseek, |
f248dcb3 MM |
878 | }; |
879 | ||
092b50ba NH |
880 | typedef struct { |
881 | u64 pme; | |
882 | } pagemap_entry_t; | |
883 | ||
85863e47 | 884 | struct pagemapread { |
f30d87b0 | 885 | int pos, len; /* units: PM_ENTRY_BYTES, not bytes */ |
092b50ba | 886 | pagemap_entry_t *buffer; |
85863e47 MM |
887 | }; |
888 | ||
5aaabe83 NH |
889 | #define PAGEMAP_WALK_SIZE (PMD_SIZE) |
890 | #define PAGEMAP_WALK_MASK (PMD_MASK) | |
891 | ||
f30d87b0 | 892 | #define PM_ENTRY_BYTES sizeof(pagemap_entry_t) |
f16278c6 HR |
893 | #define PM_STATUS_BITS 3 |
894 | #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS) | |
895 | #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET) | |
896 | #define PM_STATUS(nr) (((nr) << PM_STATUS_OFFSET) & PM_STATUS_MASK) | |
897 | #define PM_PSHIFT_BITS 6 | |
898 | #define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS) | |
899 | #define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET) | |
900 | #define PM_PSHIFT(x) (((u64) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK) | |
901 | #define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1) | |
902 | #define PM_PFRAME(x) ((x) & PM_PFRAME_MASK) | |
903 | ||
904 | #define PM_PRESENT PM_STATUS(4LL) | |
905 | #define PM_SWAP PM_STATUS(2LL) | |
052fb0d6 | 906 | #define PM_FILE PM_STATUS(1LL) |
f16278c6 | 907 | #define PM_NOT_PRESENT PM_PSHIFT(PAGE_SHIFT) |
85863e47 MM |
908 | #define PM_END_OF_BUFFER 1 |
909 | ||
092b50ba NH |
910 | static inline pagemap_entry_t make_pme(u64 val) |
911 | { | |
912 | return (pagemap_entry_t) { .pme = val }; | |
913 | } | |
914 | ||
915 | static int add_to_pagemap(unsigned long addr, pagemap_entry_t *pme, | |
85863e47 MM |
916 | struct pagemapread *pm) |
917 | { | |
092b50ba | 918 | pm->buffer[pm->pos++] = *pme; |
d82ef020 | 919 | if (pm->pos >= pm->len) |
aae8679b | 920 | return PM_END_OF_BUFFER; |
85863e47 MM |
921 | return 0; |
922 | } | |
923 | ||
924 | static int pagemap_pte_hole(unsigned long start, unsigned long end, | |
2165009b | 925 | struct mm_walk *walk) |
85863e47 | 926 | { |
2165009b | 927 | struct pagemapread *pm = walk->private; |
85863e47 MM |
928 | unsigned long addr; |
929 | int err = 0; | |
092b50ba NH |
930 | pagemap_entry_t pme = make_pme(PM_NOT_PRESENT); |
931 | ||
85863e47 | 932 | for (addr = start; addr < end; addr += PAGE_SIZE) { |
092b50ba | 933 | err = add_to_pagemap(addr, &pme, pm); |
85863e47 MM |
934 | if (err) |
935 | break; | |
936 | } | |
937 | return err; | |
938 | } | |
939 | ||
052fb0d6 KK |
940 | static void pte_to_pagemap_entry(pagemap_entry_t *pme, |
941 | struct vm_area_struct *vma, unsigned long addr, pte_t pte) | |
85863e47 | 942 | { |
052fb0d6 KK |
943 | u64 frame, flags; |
944 | struct page *page = NULL; | |
85863e47 | 945 | |
052fb0d6 KK |
946 | if (pte_present(pte)) { |
947 | frame = pte_pfn(pte); | |
948 | flags = PM_PRESENT; | |
949 | page = vm_normal_page(vma, addr, pte); | |
950 | } else if (is_swap_pte(pte)) { | |
951 | swp_entry_t entry = pte_to_swp_entry(pte); | |
952 | ||
953 | frame = swp_type(entry) | | |
954 | (swp_offset(entry) << MAX_SWAPFILES_SHIFT); | |
955 | flags = PM_SWAP; | |
956 | if (is_migration_entry(entry)) | |
957 | page = migration_entry_to_page(entry); | |
958 | } else { | |
16fbdce6 | 959 | *pme = make_pme(PM_NOT_PRESENT); |
052fb0d6 KK |
960 | return; |
961 | } | |
962 | ||
963 | if (page && !PageAnon(page)) | |
964 | flags |= PM_FILE; | |
965 | ||
966 | *pme = make_pme(PM_PFRAME(frame) | PM_PSHIFT(PAGE_SHIFT) | flags); | |
bcf8039e DH |
967 | } |
968 | ||
5aaabe83 | 969 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
092b50ba NH |
970 | static void thp_pmd_to_pagemap_entry(pagemap_entry_t *pme, |
971 | pmd_t pmd, int offset) | |
5aaabe83 | 972 | { |
5aaabe83 NH |
973 | /* |
974 | * Currently pmd for thp is always present because thp can not be | |
975 | * swapped-out, migrated, or HWPOISONed (split in such cases instead.) | |
976 | * This if-check is just to prepare for future implementation. | |
977 | */ | |
978 | if (pmd_present(pmd)) | |
092b50ba NH |
979 | *pme = make_pme(PM_PFRAME(pmd_pfn(pmd) + offset) |
980 | | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); | |
16fbdce6 KK |
981 | else |
982 | *pme = make_pme(PM_NOT_PRESENT); | |
5aaabe83 NH |
983 | } |
984 | #else | |
092b50ba NH |
985 | static inline void thp_pmd_to_pagemap_entry(pagemap_entry_t *pme, |
986 | pmd_t pmd, int offset) | |
5aaabe83 | 987 | { |
5aaabe83 NH |
988 | } |
989 | #endif | |
990 | ||
85863e47 | 991 | static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, |
2165009b | 992 | struct mm_walk *walk) |
85863e47 | 993 | { |
bcf8039e | 994 | struct vm_area_struct *vma; |
2165009b | 995 | struct pagemapread *pm = walk->private; |
85863e47 MM |
996 | pte_t *pte; |
997 | int err = 0; | |
092b50ba | 998 | pagemap_entry_t pme = make_pme(PM_NOT_PRESENT); |
85863e47 | 999 | |
bcf8039e DH |
1000 | /* find the first VMA at or above 'addr' */ |
1001 | vma = find_vma(walk->mm, addr); | |
08fa29d9 | 1002 | if (vma && pmd_trans_huge_lock(pmd, vma) == 1) { |
025c5b24 NH |
1003 | for (; addr != end; addr += PAGE_SIZE) { |
1004 | unsigned long offset; | |
1005 | ||
1006 | offset = (addr & ~PAGEMAP_WALK_MASK) >> | |
1007 | PAGE_SHIFT; | |
092b50ba NH |
1008 | thp_pmd_to_pagemap_entry(&pme, *pmd, offset); |
1009 | err = add_to_pagemap(addr, &pme, pm); | |
025c5b24 NH |
1010 | if (err) |
1011 | break; | |
5aaabe83 | 1012 | } |
5aaabe83 | 1013 | spin_unlock(&walk->mm->page_table_lock); |
025c5b24 | 1014 | return err; |
5aaabe83 NH |
1015 | } |
1016 | ||
45f83cef AA |
1017 | if (pmd_trans_unstable(pmd)) |
1018 | return 0; | |
85863e47 | 1019 | for (; addr != end; addr += PAGE_SIZE) { |
bcf8039e DH |
1020 | |
1021 | /* check to see if we've left 'vma' behind | |
1022 | * and need a new, higher one */ | |
16fbdce6 | 1023 | if (vma && (addr >= vma->vm_end)) { |
bcf8039e | 1024 | vma = find_vma(walk->mm, addr); |
16fbdce6 KK |
1025 | pme = make_pme(PM_NOT_PRESENT); |
1026 | } | |
bcf8039e DH |
1027 | |
1028 | /* check that 'vma' actually covers this address, | |
1029 | * and that it isn't a huge page vma */ | |
1030 | if (vma && (vma->vm_start <= addr) && | |
1031 | !is_vm_hugetlb_page(vma)) { | |
1032 | pte = pte_offset_map(pmd, addr); | |
052fb0d6 | 1033 | pte_to_pagemap_entry(&pme, vma, addr, *pte); |
bcf8039e DH |
1034 | /* unmap before userspace copy */ |
1035 | pte_unmap(pte); | |
1036 | } | |
092b50ba | 1037 | err = add_to_pagemap(addr, &pme, pm); |
85863e47 MM |
1038 | if (err) |
1039 | return err; | |
1040 | } | |
1041 | ||
1042 | cond_resched(); | |
1043 | ||
1044 | return err; | |
1045 | } | |
1046 | ||
1a5cb814 | 1047 | #ifdef CONFIG_HUGETLB_PAGE |
092b50ba NH |
1048 | static void huge_pte_to_pagemap_entry(pagemap_entry_t *pme, |
1049 | pte_t pte, int offset) | |
5dc37642 | 1050 | { |
5dc37642 | 1051 | if (pte_present(pte)) |
092b50ba NH |
1052 | *pme = make_pme(PM_PFRAME(pte_pfn(pte) + offset) |
1053 | | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); | |
16fbdce6 KK |
1054 | else |
1055 | *pme = make_pme(PM_NOT_PRESENT); | |
5dc37642 NH |
1056 | } |
1057 | ||
116354d1 NH |
1058 | /* This function walks within one hugetlb entry in the single call */ |
1059 | static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask, | |
1060 | unsigned long addr, unsigned long end, | |
1061 | struct mm_walk *walk) | |
5dc37642 | 1062 | { |
5dc37642 | 1063 | struct pagemapread *pm = walk->private; |
5dc37642 | 1064 | int err = 0; |
16fbdce6 | 1065 | pagemap_entry_t pme; |
5dc37642 | 1066 | |
5dc37642 | 1067 | for (; addr != end; addr += PAGE_SIZE) { |
116354d1 | 1068 | int offset = (addr & ~hmask) >> PAGE_SHIFT; |
092b50ba NH |
1069 | huge_pte_to_pagemap_entry(&pme, *pte, offset); |
1070 | err = add_to_pagemap(addr, &pme, pm); | |
5dc37642 NH |
1071 | if (err) |
1072 | return err; | |
1073 | } | |
1074 | ||
1075 | cond_resched(); | |
1076 | ||
1077 | return err; | |
1078 | } | |
1a5cb814 | 1079 | #endif /* HUGETLB_PAGE */ |
5dc37642 | 1080 | |
85863e47 MM |
1081 | /* |
1082 | * /proc/pid/pagemap - an array mapping virtual pages to pfns | |
1083 | * | |
f16278c6 HR |
1084 | * For each page in the address space, this file contains one 64-bit entry |
1085 | * consisting of the following: | |
1086 | * | |
052fb0d6 | 1087 | * Bits 0-54 page frame number (PFN) if present |
f16278c6 | 1088 | * Bits 0-4 swap type if swapped |
052fb0d6 | 1089 | * Bits 5-54 swap offset if swapped |
f16278c6 | 1090 | * Bits 55-60 page shift (page size = 1<<page shift) |
052fb0d6 | 1091 | * Bit 61 page is file-page or shared-anon |
f16278c6 HR |
1092 | * Bit 62 page swapped |
1093 | * Bit 63 page present | |
1094 | * | |
1095 | * If the page is not present but in swap, then the PFN contains an | |
1096 | * encoding of the swap file number and the page's offset into the | |
1097 | * swap. Unmapped pages return a null PFN. This allows determining | |
85863e47 MM |
1098 | * precisely which pages are mapped (or in swap) and comparing mapped |
1099 | * pages between processes. | |
1100 | * | |
1101 | * Efficient users of this interface will use /proc/pid/maps to | |
1102 | * determine which areas of memory are actually mapped and llseek to | |
1103 | * skip over unmapped regions. | |
1104 | */ | |
1105 | static ssize_t pagemap_read(struct file *file, char __user *buf, | |
1106 | size_t count, loff_t *ppos) | |
1107 | { | |
496ad9aa | 1108 | struct task_struct *task = get_proc_task(file_inode(file)); |
85863e47 MM |
1109 | struct mm_struct *mm; |
1110 | struct pagemapread pm; | |
85863e47 | 1111 | int ret = -ESRCH; |
ee1e6ab6 | 1112 | struct mm_walk pagemap_walk = {}; |
5d7e0d2b AM |
1113 | unsigned long src; |
1114 | unsigned long svpfn; | |
1115 | unsigned long start_vaddr; | |
1116 | unsigned long end_vaddr; | |
d82ef020 | 1117 | int copied = 0; |
85863e47 MM |
1118 | |
1119 | if (!task) | |
1120 | goto out; | |
1121 | ||
85863e47 MM |
1122 | ret = -EINVAL; |
1123 | /* file position must be aligned */ | |
aae8679b | 1124 | if ((*ppos % PM_ENTRY_BYTES) || (count % PM_ENTRY_BYTES)) |
fb39380b | 1125 | goto out_task; |
85863e47 MM |
1126 | |
1127 | ret = 0; | |
08161786 VM |
1128 | if (!count) |
1129 | goto out_task; | |
1130 | ||
f30d87b0 | 1131 | pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT); |
1132 | pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_TEMPORARY); | |
5d7e0d2b | 1133 | ret = -ENOMEM; |
d82ef020 | 1134 | if (!pm.buffer) |
98bc93e5 KM |
1135 | goto out_task; |
1136 | ||
b048b93f | 1137 | mm = mm_access(task, PTRACE_MODE_READ_FSCREDS); |
98bc93e5 KM |
1138 | ret = PTR_ERR(mm); |
1139 | if (!mm || IS_ERR(mm)) | |
1140 | goto out_free; | |
85863e47 | 1141 | |
5d7e0d2b AM |
1142 | pagemap_walk.pmd_entry = pagemap_pte_range; |
1143 | pagemap_walk.pte_hole = pagemap_pte_hole; | |
1a5cb814 | 1144 | #ifdef CONFIG_HUGETLB_PAGE |
5dc37642 | 1145 | pagemap_walk.hugetlb_entry = pagemap_hugetlb_range; |
1a5cb814 | 1146 | #endif |
5d7e0d2b AM |
1147 | pagemap_walk.mm = mm; |
1148 | pagemap_walk.private = ± | |
1149 | ||
1150 | src = *ppos; | |
1151 | svpfn = src / PM_ENTRY_BYTES; | |
1152 | start_vaddr = svpfn << PAGE_SHIFT; | |
1153 | end_vaddr = TASK_SIZE_OF(task); | |
1154 | ||
1155 | /* watch out for wraparound */ | |
1156 | if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT) | |
1157 | start_vaddr = end_vaddr; | |
1158 | ||
1159 | /* | |
1160 | * The odds are that this will stop walking way | |
1161 | * before end_vaddr, because the length of the | |
1162 | * user buffer is tracked in "pm", and the walk | |
1163 | * will stop when we hit the end of the buffer. | |
1164 | */ | |
d82ef020 KH |
1165 | ret = 0; |
1166 | while (count && (start_vaddr < end_vaddr)) { | |
1167 | int len; | |
1168 | unsigned long end; | |
1169 | ||
1170 | pm.pos = 0; | |
ea251c1d | 1171 | end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK; |
d82ef020 KH |
1172 | /* overflow ? */ |
1173 | if (end < start_vaddr || end > end_vaddr) | |
1174 | end = end_vaddr; | |
1175 | down_read(&mm->mmap_sem); | |
1176 | ret = walk_page_range(start_vaddr, end, &pagemap_walk); | |
1177 | up_read(&mm->mmap_sem); | |
1178 | start_vaddr = end; | |
1179 | ||
1180 | len = min(count, PM_ENTRY_BYTES * pm.pos); | |
309361e0 | 1181 | if (copy_to_user(buf, pm.buffer, len)) { |
d82ef020 | 1182 | ret = -EFAULT; |
98bc93e5 | 1183 | goto out_mm; |
d82ef020 KH |
1184 | } |
1185 | copied += len; | |
1186 | buf += len; | |
1187 | count -= len; | |
85863e47 | 1188 | } |
d82ef020 KH |
1189 | *ppos += copied; |
1190 | if (!ret || ret == PM_END_OF_BUFFER) | |
1191 | ret = copied; | |
1192 | ||
fb39380b MT |
1193 | out_mm: |
1194 | mmput(mm); | |
98bc93e5 KM |
1195 | out_free: |
1196 | kfree(pm.buffer); | |
85863e47 MM |
1197 | out_task: |
1198 | put_task_struct(task); | |
1199 | out: | |
1200 | return ret; | |
1201 | } | |
1202 | ||
e11b7085 KS |
1203 | static int pagemap_open(struct inode *inode, struct file *file) |
1204 | { | |
1205 | /* do not disclose physical addresses to unprivileged | |
1206 | userspace (closes a rowhammer attack vector) */ | |
1207 | if (!capable(CAP_SYS_ADMIN)) | |
1208 | return -EPERM; | |
1209 | return 0; | |
1210 | } | |
1211 | ||
85863e47 MM |
1212 | const struct file_operations proc_pagemap_operations = { |
1213 | .llseek = mem_lseek, /* borrow this */ | |
1214 | .read = pagemap_read, | |
e11b7085 | 1215 | .open = pagemap_open, |
85863e47 | 1216 | }; |
1e883281 | 1217 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
85863e47 | 1218 | |
6e21c8f1 | 1219 | #ifdef CONFIG_NUMA |
6e21c8f1 | 1220 | |
f69ff943 SW |
1221 | struct numa_maps { |
1222 | struct vm_area_struct *vma; | |
1223 | unsigned long pages; | |
1224 | unsigned long anon; | |
1225 | unsigned long active; | |
1226 | unsigned long writeback; | |
1227 | unsigned long mapcount_max; | |
1228 | unsigned long dirty; | |
1229 | unsigned long swapcache; | |
1230 | unsigned long node[MAX_NUMNODES]; | |
1231 | }; | |
1232 | ||
5b52fc89 SW |
1233 | struct numa_maps_private { |
1234 | struct proc_maps_private proc_maps; | |
1235 | struct numa_maps md; | |
1236 | }; | |
1237 | ||
eb4866d0 DH |
1238 | static void gather_stats(struct page *page, struct numa_maps *md, int pte_dirty, |
1239 | unsigned long nr_pages) | |
f69ff943 SW |
1240 | { |
1241 | int count = page_mapcount(page); | |
1242 | ||
eb4866d0 | 1243 | md->pages += nr_pages; |
f69ff943 | 1244 | if (pte_dirty || PageDirty(page)) |
eb4866d0 | 1245 | md->dirty += nr_pages; |
f69ff943 SW |
1246 | |
1247 | if (PageSwapCache(page)) | |
eb4866d0 | 1248 | md->swapcache += nr_pages; |
f69ff943 SW |
1249 | |
1250 | if (PageActive(page) || PageUnevictable(page)) | |
eb4866d0 | 1251 | md->active += nr_pages; |
f69ff943 SW |
1252 | |
1253 | if (PageWriteback(page)) | |
eb4866d0 | 1254 | md->writeback += nr_pages; |
f69ff943 SW |
1255 | |
1256 | if (PageAnon(page)) | |
eb4866d0 | 1257 | md->anon += nr_pages; |
f69ff943 SW |
1258 | |
1259 | if (count > md->mapcount_max) | |
1260 | md->mapcount_max = count; | |
1261 | ||
eb4866d0 | 1262 | md->node[page_to_nid(page)] += nr_pages; |
f69ff943 SW |
1263 | } |
1264 | ||
3200a8aa DH |
1265 | static struct page *can_gather_numa_stats(pte_t pte, struct vm_area_struct *vma, |
1266 | unsigned long addr) | |
1267 | { | |
1268 | struct page *page; | |
1269 | int nid; | |
1270 | ||
1271 | if (!pte_present(pte)) | |
1272 | return NULL; | |
1273 | ||
1274 | page = vm_normal_page(vma, addr, pte); | |
1275 | if (!page) | |
1276 | return NULL; | |
1277 | ||
1278 | if (PageReserved(page)) | |
1279 | return NULL; | |
1280 | ||
1281 | nid = page_to_nid(page); | |
4ff1b2c2 | 1282 | if (!node_isset(nid, node_states[N_MEMORY])) |
3200a8aa DH |
1283 | return NULL; |
1284 | ||
1285 | return page; | |
1286 | } | |
1287 | ||
f69ff943 SW |
1288 | static int gather_pte_stats(pmd_t *pmd, unsigned long addr, |
1289 | unsigned long end, struct mm_walk *walk) | |
1290 | { | |
1291 | struct numa_maps *md; | |
1292 | spinlock_t *ptl; | |
1293 | pte_t *orig_pte; | |
1294 | pte_t *pte; | |
1295 | ||
1296 | md = walk->private; | |
025c5b24 NH |
1297 | |
1298 | if (pmd_trans_huge_lock(pmd, md->vma) == 1) { | |
1299 | pte_t huge_pte = *(pte_t *)pmd; | |
1300 | struct page *page; | |
1301 | ||
1302 | page = can_gather_numa_stats(huge_pte, md->vma, addr); | |
1303 | if (page) | |
1304 | gather_stats(page, md, pte_dirty(huge_pte), | |
1305 | HPAGE_PMD_SIZE/PAGE_SIZE); | |
32ef4384 | 1306 | spin_unlock(&walk->mm->page_table_lock); |
025c5b24 | 1307 | return 0; |
32ef4384 DH |
1308 | } |
1309 | ||
1a5a9906 AA |
1310 | if (pmd_trans_unstable(pmd)) |
1311 | return 0; | |
f69ff943 SW |
1312 | orig_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); |
1313 | do { | |
3200a8aa | 1314 | struct page *page = can_gather_numa_stats(*pte, md->vma, addr); |
f69ff943 SW |
1315 | if (!page) |
1316 | continue; | |
eb4866d0 | 1317 | gather_stats(page, md, pte_dirty(*pte), 1); |
f69ff943 SW |
1318 | |
1319 | } while (pte++, addr += PAGE_SIZE, addr != end); | |
1320 | pte_unmap_unlock(orig_pte, ptl); | |
1321 | return 0; | |
1322 | } | |
1323 | #ifdef CONFIG_HUGETLB_PAGE | |
1324 | static int gather_hugetbl_stats(pte_t *pte, unsigned long hmask, | |
1325 | unsigned long addr, unsigned long end, struct mm_walk *walk) | |
1326 | { | |
1327 | struct numa_maps *md; | |
1328 | struct page *page; | |
1329 | ||
1330 | if (pte_none(*pte)) | |
1331 | return 0; | |
1332 | ||
1333 | page = pte_page(*pte); | |
1334 | if (!page) | |
1335 | return 0; | |
1336 | ||
1337 | md = walk->private; | |
eb4866d0 | 1338 | gather_stats(page, md, pte_dirty(*pte), 1); |
f69ff943 SW |
1339 | return 0; |
1340 | } | |
1341 | ||
1342 | #else | |
1343 | static int gather_hugetbl_stats(pte_t *pte, unsigned long hmask, | |
1344 | unsigned long addr, unsigned long end, struct mm_walk *walk) | |
1345 | { | |
1346 | return 0; | |
1347 | } | |
1348 | #endif | |
1349 | ||
1350 | /* | |
1351 | * Display pages allocated per node and memory policy via /proc. | |
1352 | */ | |
b7643757 | 1353 | static int show_numa_map(struct seq_file *m, void *v, int is_pid) |
f69ff943 | 1354 | { |
5b52fc89 SW |
1355 | struct numa_maps_private *numa_priv = m->private; |
1356 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; | |
f69ff943 | 1357 | struct vm_area_struct *vma = v; |
5b52fc89 | 1358 | struct numa_maps *md = &numa_priv->md; |
f69ff943 | 1359 | struct file *file = vma->vm_file; |
32f8516a | 1360 | struct task_struct *task = proc_priv->task; |
f69ff943 SW |
1361 | struct mm_struct *mm = vma->vm_mm; |
1362 | struct mm_walk walk = {}; | |
1363 | struct mempolicy *pol; | |
1364 | int n; | |
1365 | char buffer[50]; | |
1366 | ||
1367 | if (!mm) | |
1368 | return 0; | |
1369 | ||
5b52fc89 SW |
1370 | /* Ensure we start with an empty set of numa_maps statistics. */ |
1371 | memset(md, 0, sizeof(*md)); | |
f69ff943 SW |
1372 | |
1373 | md->vma = vma; | |
1374 | ||
1375 | walk.hugetlb_entry = gather_hugetbl_stats; | |
1376 | walk.pmd_entry = gather_pte_stats; | |
1377 | walk.private = md; | |
1378 | walk.mm = mm; | |
1379 | ||
32f8516a | 1380 | pol = get_vma_policy(task, vma, vma->vm_start); |
a7a88b23 | 1381 | mpol_to_str(buffer, sizeof(buffer), pol); |
f69ff943 SW |
1382 | mpol_cond_put(pol); |
1383 | ||
1384 | seq_printf(m, "%08lx %s", vma->vm_start, buffer); | |
1385 | ||
1386 | if (file) { | |
1387 | seq_printf(m, " file="); | |
1388 | seq_path(m, &file->f_path, "\n\t= "); | |
1389 | } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { | |
1390 | seq_printf(m, " heap"); | |
b7643757 | 1391 | } else { |
32f8516a | 1392 | pid_t tid = vm_is_stack(task, vma, is_pid); |
b7643757 SP |
1393 | if (tid != 0) { |
1394 | /* | |
1395 | * Thread stack in /proc/PID/task/TID/maps or | |
1396 | * the main process stack. | |
1397 | */ | |
1398 | if (!is_pid || (vma->vm_start <= mm->start_stack && | |
1399 | vma->vm_end >= mm->start_stack)) | |
1400 | seq_printf(m, " stack"); | |
1401 | else | |
1402 | seq_printf(m, " stack:%d", tid); | |
1403 | } | |
f69ff943 SW |
1404 | } |
1405 | ||
fc360bd9 AM |
1406 | if (is_vm_hugetlb_page(vma)) |
1407 | seq_printf(m, " huge"); | |
1408 | ||
f69ff943 SW |
1409 | walk_page_range(vma->vm_start, vma->vm_end, &walk); |
1410 | ||
1411 | if (!md->pages) | |
1412 | goto out; | |
1413 | ||
1414 | if (md->anon) | |
1415 | seq_printf(m, " anon=%lu", md->anon); | |
1416 | ||
1417 | if (md->dirty) | |
1418 | seq_printf(m, " dirty=%lu", md->dirty); | |
1419 | ||
1420 | if (md->pages != md->anon && md->pages != md->dirty) | |
1421 | seq_printf(m, " mapped=%lu", md->pages); | |
1422 | ||
1423 | if (md->mapcount_max > 1) | |
1424 | seq_printf(m, " mapmax=%lu", md->mapcount_max); | |
1425 | ||
1426 | if (md->swapcache) | |
1427 | seq_printf(m, " swapcache=%lu", md->swapcache); | |
1428 | ||
1429 | if (md->active < md->pages && !is_vm_hugetlb_page(vma)) | |
1430 | seq_printf(m, " active=%lu", md->active); | |
1431 | ||
1432 | if (md->writeback) | |
1433 | seq_printf(m, " writeback=%lu", md->writeback); | |
1434 | ||
4ff1b2c2 | 1435 | for_each_node_state(n, N_MEMORY) |
f69ff943 SW |
1436 | if (md->node[n]) |
1437 | seq_printf(m, " N%d=%lu", n, md->node[n]); | |
1438 | out: | |
1439 | seq_putc(m, '\n'); | |
f69ff943 SW |
1440 | |
1441 | if (m->count < m->size) | |
5b52fc89 | 1442 | m->version = (vma != proc_priv->tail_vma) ? vma->vm_start : 0; |
f69ff943 SW |
1443 | return 0; |
1444 | } | |
5b52fc89 | 1445 | |
b7643757 SP |
1446 | static int show_pid_numa_map(struct seq_file *m, void *v) |
1447 | { | |
1448 | return show_numa_map(m, v, 1); | |
1449 | } | |
1450 | ||
1451 | static int show_tid_numa_map(struct seq_file *m, void *v) | |
1452 | { | |
1453 | return show_numa_map(m, v, 0); | |
1454 | } | |
1455 | ||
03a44825 | 1456 | static const struct seq_operations proc_pid_numa_maps_op = { |
b7643757 SP |
1457 | .start = m_start, |
1458 | .next = m_next, | |
1459 | .stop = m_stop, | |
1460 | .show = show_pid_numa_map, | |
6e21c8f1 | 1461 | }; |
662795de | 1462 | |
b7643757 SP |
1463 | static const struct seq_operations proc_tid_numa_maps_op = { |
1464 | .start = m_start, | |
1465 | .next = m_next, | |
1466 | .stop = m_stop, | |
1467 | .show = show_tid_numa_map, | |
1468 | }; | |
1469 | ||
1470 | static int numa_maps_open(struct inode *inode, struct file *file, | |
1471 | const struct seq_operations *ops) | |
662795de | 1472 | { |
5b52fc89 SW |
1473 | struct numa_maps_private *priv; |
1474 | int ret = -ENOMEM; | |
1475 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | |
1476 | if (priv) { | |
1477 | priv->proc_maps.pid = proc_pid(inode); | |
b7643757 | 1478 | ret = seq_open(file, ops); |
5b52fc89 SW |
1479 | if (!ret) { |
1480 | struct seq_file *m = file->private_data; | |
1481 | m->private = priv; | |
1482 | } else { | |
1483 | kfree(priv); | |
1484 | } | |
1485 | } | |
1486 | return ret; | |
662795de EB |
1487 | } |
1488 | ||
b7643757 SP |
1489 | static int pid_numa_maps_open(struct inode *inode, struct file *file) |
1490 | { | |
1491 | return numa_maps_open(inode, file, &proc_pid_numa_maps_op); | |
1492 | } | |
1493 | ||
1494 | static int tid_numa_maps_open(struct inode *inode, struct file *file) | |
1495 | { | |
1496 | return numa_maps_open(inode, file, &proc_tid_numa_maps_op); | |
1497 | } | |
1498 | ||
1499 | const struct file_operations proc_pid_numa_maps_operations = { | |
1500 | .open = pid_numa_maps_open, | |
1501 | .read = seq_read, | |
1502 | .llseek = seq_lseek, | |
1503 | .release = seq_release_private, | |
1504 | }; | |
1505 | ||
1506 | const struct file_operations proc_tid_numa_maps_operations = { | |
1507 | .open = tid_numa_maps_open, | |
662795de EB |
1508 | .read = seq_read, |
1509 | .llseek = seq_lseek, | |
99f89551 | 1510 | .release = seq_release_private, |
662795de | 1511 | }; |
f69ff943 | 1512 | #endif /* CONFIG_NUMA */ |