Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: /proc/pid/*maps remove is_pid and related wrappers

Patch series "cleanups and refactor of /proc/pid/smaps*".

The recent regression in /proc/pid/smaps made me look more into the code.
Especially the issues with smaps_rollup reported in [1] as explained in
Patch 4, which fixes them by refactoring the code. Patches 2 and 3 are
preparations for that. Patch 1 is me realizing that there's a lot of
boilerplate left from times where we tried (unsuccessfuly) to mark thread
stacks in the output.

Originally I had also plans to rework the translation from
/proc/pid/*maps* file offsets to the internal structures. Now the offset
means "vma number", which is not really stable (vma's can come and go
between read() calls) and there's an extra caching of last vma's address.
My idea was that offsets would be interpreted directly as addresses, which
would also allow meaningful seeks (see the ugly seek_to_smaps_entry() in
tools/testing/selftests/vm/mlock2.h). However loff_t is (signed) long
long so that might be insufficient somewhere for the unsigned long
addresses.

So the result is fixed issues with skewed /proc/pid/smaps_rollup results,
simpler smaps code, and a lot of unused code removed.

[1] https://marc.info/?l=linux-mm&m=151927723128134&w=2

This patch (of 4):

Commit b76437579d13 ("procfs: mark thread stack correctly in
proc/<pid>/maps") introduced differences between /proc/PID/maps and
/proc/PID/task/TID/maps to mark thread stacks properly, and this was
also done for smaps and numa_maps. However it didn't work properly and
was ultimately removed by commit b18cb64ead40 ("fs/proc: Stop trying to
report thread stacks").

Now the is_pid parameter for the related show_*() functions is unused
and we can remove it together with wrapper functions and ops structures
that differ for PID and TID cases only in this parameter.

Link: http://lkml.kernel.org/r/20180723111933.15443-2-vbabka@suse.cz
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Daniel Colascione <dancol@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Vlastimil Babka and committed by
Linus Torvalds
871305bb 431f42fd

+18 -144
+3 -3
fs/proc/base.c
··· 3309 3309 REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), 3310 3310 ONE("stat", S_IRUGO, proc_tid_stat), 3311 3311 ONE("statm", S_IRUGO, proc_pid_statm), 3312 - REG("maps", S_IRUGO, proc_tid_maps_operations), 3312 + REG("maps", S_IRUGO, proc_pid_maps_operations), 3313 3313 #ifdef CONFIG_PROC_CHILDREN 3314 3314 REG("children", S_IRUGO, proc_tid_children_operations), 3315 3315 #endif 3316 3316 #ifdef CONFIG_NUMA 3317 - REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations), 3317 + REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), 3318 3318 #endif 3319 3319 REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), 3320 3320 LNK("cwd", proc_cwd_link), ··· 3324 3324 REG("mountinfo", S_IRUGO, proc_mountinfo_operations), 3325 3325 #ifdef CONFIG_PROC_PAGE_MONITOR 3326 3326 REG("clear_refs", S_IWUSR, proc_clear_refs_operations), 3327 - REG("smaps", S_IRUGO, proc_tid_smaps_operations), 3327 + REG("smaps", S_IRUGO, proc_pid_smaps_operations), 3328 3328 REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), 3329 3329 REG("pagemap", S_IRUSR, proc_pagemap_operations), 3330 3330 #endif
-3
fs/proc/internal.h
··· 297 297 struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode); 298 298 299 299 extern const struct file_operations proc_pid_maps_operations; 300 - extern const struct file_operations proc_tid_maps_operations; 301 300 extern const struct file_operations proc_pid_numa_maps_operations; 302 - extern const struct file_operations proc_tid_numa_maps_operations; 303 301 extern const struct file_operations proc_pid_smaps_operations; 304 302 extern const struct file_operations proc_pid_smaps_rollup_operations; 305 - extern const struct file_operations proc_tid_smaps_operations; 306 303 extern const struct file_operations proc_clear_refs_operations; 307 304 extern const struct file_operations proc_pagemap_operations; 308 305
+11 -103
fs/proc/task_mmu.c
··· 294 294 } 295 295 296 296 static void 297 - show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) 297 + show_map_vma(struct seq_file *m, struct vm_area_struct *vma) 298 298 { 299 299 struct mm_struct *mm = vma->vm_mm; 300 300 struct file *file = vma->vm_file; ··· 357 357 seq_putc(m, '\n'); 358 358 } 359 359 360 - static int show_map(struct seq_file *m, void *v, int is_pid) 360 + static int show_map(struct seq_file *m, void *v) 361 361 { 362 - show_map_vma(m, v, is_pid); 362 + show_map_vma(m, v); 363 363 m_cache_vma(m, v); 364 364 return 0; 365 - } 366 - 367 - static int show_pid_map(struct seq_file *m, void *v) 368 - { 369 - return show_map(m, v, 1); 370 - } 371 - 372 - static int show_tid_map(struct seq_file *m, void *v) 373 - { 374 - return show_map(m, v, 0); 375 365 } 376 366 377 367 static const struct seq_operations proc_pid_maps_op = { 378 368 .start = m_start, 379 369 .next = m_next, 380 370 .stop = m_stop, 381 - .show = show_pid_map 382 - }; 383 - 384 - static const struct seq_operations proc_tid_maps_op = { 385 - .start = m_start, 386 - .next = m_next, 387 - .stop = m_stop, 388 - .show = show_tid_map 371 + .show = show_map 389 372 }; 390 373 391 374 static int pid_maps_open(struct inode *inode, struct file *file) ··· 376 393 return do_maps_open(inode, file, &proc_pid_maps_op); 377 394 } 378 395 379 - static int tid_maps_open(struct inode *inode, struct file *file) 380 - { 381 - return do_maps_open(inode, file, &proc_tid_maps_op); 382 - } 383 - 384 396 const struct file_operations proc_pid_maps_operations = { 385 397 .open = pid_maps_open, 386 - .read = seq_read, 387 - .llseek = seq_lseek, 388 - .release = proc_map_release, 389 - }; 390 - 391 - const struct file_operations proc_tid_maps_operations = { 392 - .open = tid_maps_open, 393 398 .read = seq_read, 394 399 .llseek = seq_lseek, 395 400 .release = proc_map_release, ··· 704 733 705 734 #define SEQ_PUT_DEC(str, val) \ 706 735 seq_put_decimal_ull_width(m, str, (val) >> 10, 8) 707 - static int show_smap(struct seq_file *m, void *v, int is_pid) 736 + static int show_smap(struct seq_file *m, void *v) 708 737 { 709 738 struct proc_maps_private *priv = m->private; 710 739 struct vm_area_struct *vma = v; ··· 767 796 mss->pss_locked += mss->pss; 768 797 769 798 if (!rollup_mode) { 770 - show_map_vma(m, vma, is_pid); 799 + show_map_vma(m, vma); 771 800 } else if (last_vma) { 772 801 show_vma_header_prefix( 773 802 m, mss->first_vma_start, vma->vm_end, 0, 0, 0, 0); ··· 816 845 } 817 846 #undef SEQ_PUT_DEC 818 847 819 - static int show_pid_smap(struct seq_file *m, void *v) 820 - { 821 - return show_smap(m, v, 1); 822 - } 823 - 824 - static int show_tid_smap(struct seq_file *m, void *v) 825 - { 826 - return show_smap(m, v, 0); 827 - } 828 - 829 848 static const struct seq_operations proc_pid_smaps_op = { 830 849 .start = m_start, 831 850 .next = m_next, 832 851 .stop = m_stop, 833 - .show = show_pid_smap 834 - }; 835 - 836 - static const struct seq_operations proc_tid_smaps_op = { 837 - .start = m_start, 838 - .next = m_next, 839 - .stop = m_stop, 840 - .show = show_tid_smap 852 + .show = show_smap 841 853 }; 842 854 843 855 static int pid_smaps_open(struct inode *inode, struct file *file) ··· 847 893 return 0; 848 894 } 849 895 850 - static int tid_smaps_open(struct inode *inode, struct file *file) 851 - { 852 - return do_maps_open(inode, file, &proc_tid_smaps_op); 853 - } 854 - 855 896 const struct file_operations proc_pid_smaps_operations = { 856 897 .open = pid_smaps_open, 857 898 .read = seq_read, ··· 856 907 857 908 const struct file_operations proc_pid_smaps_rollup_operations = { 858 909 .open = pid_smaps_rollup_open, 859 - .read = seq_read, 860 - .llseek = seq_lseek, 861 - .release = proc_map_release, 862 - }; 863 - 864 - const struct file_operations proc_tid_smaps_operations = { 865 - .open = tid_smaps_open, 866 910 .read = seq_read, 867 911 .llseek = seq_lseek, 868 912 .release = proc_map_release, ··· 1670 1728 /* 1671 1729 * Display pages allocated per node and memory policy via /proc. 1672 1730 */ 1673 - static int show_numa_map(struct seq_file *m, void *v, int is_pid) 1731 + static int show_numa_map(struct seq_file *m, void *v) 1674 1732 { 1675 1733 struct numa_maps_private *numa_priv = m->private; 1676 1734 struct proc_maps_private *proc_priv = &numa_priv->proc_maps; ··· 1754 1812 return 0; 1755 1813 } 1756 1814 1757 - static int show_pid_numa_map(struct seq_file *m, void *v) 1758 - { 1759 - return show_numa_map(m, v, 1); 1760 - } 1761 - 1762 - static int show_tid_numa_map(struct seq_file *m, void *v) 1763 - { 1764 - return show_numa_map(m, v, 0); 1765 - } 1766 - 1767 1815 static const struct seq_operations proc_pid_numa_maps_op = { 1768 1816 .start = m_start, 1769 1817 .next = m_next, 1770 1818 .stop = m_stop, 1771 - .show = show_pid_numa_map, 1819 + .show = show_numa_map, 1772 1820 }; 1773 - 1774 - static const struct seq_operations proc_tid_numa_maps_op = { 1775 - .start = m_start, 1776 - .next = m_next, 1777 - .stop = m_stop, 1778 - .show = show_tid_numa_map, 1779 - }; 1780 - 1781 - static int numa_maps_open(struct inode *inode, struct file *file, 1782 - const struct seq_operations *ops) 1783 - { 1784 - return proc_maps_open(inode, file, ops, 1785 - sizeof(struct numa_maps_private)); 1786 - } 1787 1821 1788 1822 static int pid_numa_maps_open(struct inode *inode, struct file *file) 1789 1823 { 1790 - return numa_maps_open(inode, file, &proc_pid_numa_maps_op); 1791 - } 1792 - 1793 - static int tid_numa_maps_open(struct inode *inode, struct file *file) 1794 - { 1795 - return numa_maps_open(inode, file, &proc_tid_numa_maps_op); 1824 + return proc_maps_open(inode, file, &proc_pid_numa_maps_op, 1825 + sizeof(struct numa_maps_private)); 1796 1826 } 1797 1827 1798 1828 const struct file_operations proc_pid_numa_maps_operations = { ··· 1774 1860 .release = proc_map_release, 1775 1861 }; 1776 1862 1777 - const struct file_operations proc_tid_numa_maps_operations = { 1778 - .open = tid_numa_maps_open, 1779 - .read = seq_read, 1780 - .llseek = seq_lseek, 1781 - .release = proc_map_release, 1782 - }; 1783 1863 #endif /* CONFIG_NUMA */
+4 -35
fs/proc/task_nommu.c
··· 142 142 /* 143 143 * display a single VMA to a sequenced file 144 144 */ 145 - static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, 146 - int is_pid) 145 + static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) 147 146 { 148 147 struct mm_struct *mm = vma->vm_mm; 149 148 unsigned long ino = 0; ··· 188 189 /* 189 190 * display mapping lines for a particular process's /proc/pid/maps 190 191 */ 191 - static int show_map(struct seq_file *m, void *_p, int is_pid) 192 + static int show_map(struct seq_file *m, void *_p) 192 193 { 193 194 struct rb_node *p = _p; 194 195 195 - return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb), 196 - is_pid); 197 - } 198 - 199 - static int show_pid_map(struct seq_file *m, void *_p) 200 - { 201 - return show_map(m, _p, 1); 202 - } 203 - 204 - static int show_tid_map(struct seq_file *m, void *_p) 205 - { 206 - return show_map(m, _p, 0); 196 + return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb)); 207 197 } 208 198 209 199 static void *m_start(struct seq_file *m, loff_t *pos) ··· 248 260 .start = m_start, 249 261 .next = m_next, 250 262 .stop = m_stop, 251 - .show = show_pid_map 252 - }; 253 - 254 - static const struct seq_operations proc_tid_maps_ops = { 255 - .start = m_start, 256 - .next = m_next, 257 - .stop = m_stop, 258 - .show = show_tid_map 263 + .show = show_map 259 264 }; 260 265 261 266 static int maps_open(struct inode *inode, struct file *file, ··· 289 308 return maps_open(inode, file, &proc_pid_maps_ops); 290 309 } 291 310 292 - static int tid_maps_open(struct inode *inode, struct file *file) 293 - { 294 - return maps_open(inode, file, &proc_tid_maps_ops); 295 - } 296 - 297 311 const struct file_operations proc_pid_maps_operations = { 298 312 .open = pid_maps_open, 299 - .read = seq_read, 300 - .llseek = seq_lseek, 301 - .release = map_release, 302 - }; 303 - 304 - const struct file_operations proc_tid_maps_operations = { 305 - .open = tid_maps_open, 306 313 .read = seq_read, 307 314 .llseek = seq_lseek, 308 315 .release = map_release,