Skip to content

Commit 871305b

Browse files
tehcastertorvalds
authored andcommitted
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 b764375 ("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 b18cb64 ("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/[email protected] Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Alexey Dobriyan <[email protected]> Cc: Daniel Colascione <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 431f42f commit 871305b

File tree

4 files changed

+18
-144
lines changed

4 files changed

+18
-144
lines changed

fs/proc/base.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,12 +3309,12 @@ static const struct pid_entry tid_base_stuff[] = {
33093309
REG("cmdline", S_IRUGO, proc_pid_cmdline_ops),
33103310
ONE("stat", S_IRUGO, proc_tid_stat),
33113311
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),
33133313
#ifdef CONFIG_PROC_CHILDREN
33143314
REG("children", S_IRUGO, proc_tid_children_operations),
33153315
#endif
33163316
#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),
33183318
#endif
33193319
REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
33203320
LNK("cwd", proc_cwd_link),
@@ -3324,7 +3324,7 @@ static const struct pid_entry tid_base_stuff[] = {
33243324
REG("mountinfo", S_IRUGO, proc_mountinfo_operations),
33253325
#ifdef CONFIG_PROC_PAGE_MONITOR
33263326
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),
33283328
REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations),
33293329
REG("pagemap", S_IRUSR, proc_pagemap_operations),
33303330
#endif

fs/proc/internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,9 @@ struct proc_maps_private {
297297
struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
298298

299299
extern const struct file_operations proc_pid_maps_operations;
300-
extern const struct file_operations proc_tid_maps_operations;
301300
extern const struct file_operations proc_pid_numa_maps_operations;
302-
extern const struct file_operations proc_tid_numa_maps_operations;
303301
extern const struct file_operations proc_pid_smaps_operations;
304302
extern const struct file_operations proc_pid_smaps_rollup_operations;
305-
extern const struct file_operations proc_tid_smaps_operations;
306303
extern const struct file_operations proc_clear_refs_operations;
307304
extern const struct file_operations proc_pagemap_operations;
308305

fs/proc/task_mmu.c

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static void show_vma_header_prefix(struct seq_file *m,
294294
}
295295

296296
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)
298298
{
299299
struct mm_struct *mm = vma->vm_mm;
300300
struct file *file = vma->vm_file;
@@ -357,61 +357,32 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
357357
seq_putc(m, '\n');
358358
}
359359

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)
361361
{
362-
show_map_vma(m, v, is_pid);
362+
show_map_vma(m, v);
363363
m_cache_vma(m, v);
364364
return 0;
365365
}
366366

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-
}
376-
377367
static const struct seq_operations proc_pid_maps_op = {
378368
.start = m_start,
379369
.next = m_next,
380370
.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
389372
};
390373

391374
static int pid_maps_open(struct inode *inode, struct file *file)
392375
{
393376
return do_maps_open(inode, file, &proc_pid_maps_op);
394377
}
395378

396-
static int tid_maps_open(struct inode *inode, struct file *file)
397-
{
398-
return do_maps_open(inode, file, &proc_tid_maps_op);
399-
}
400-
401379
const struct file_operations proc_pid_maps_operations = {
402380
.open = pid_maps_open,
403381
.read = seq_read,
404382
.llseek = seq_lseek,
405383
.release = proc_map_release,
406384
};
407385

408-
const struct file_operations proc_tid_maps_operations = {
409-
.open = tid_maps_open,
410-
.read = seq_read,
411-
.llseek = seq_lseek,
412-
.release = proc_map_release,
413-
};
414-
415386
/*
416387
* Proportional Set Size(PSS): my share of RSS.
417388
*
@@ -733,7 +704,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
733704

734705
#define SEQ_PUT_DEC(str, val) \
735706
seq_put_decimal_ull_width(m, str, (val) >> 10, 8)
736-
static int show_smap(struct seq_file *m, void *v, int is_pid)
707+
static int show_smap(struct seq_file *m, void *v)
737708
{
738709
struct proc_maps_private *priv = m->private;
739710
struct vm_area_struct *vma = v;
@@ -796,7 +767,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
796767
mss->pss_locked += mss->pss;
797768

798769
if (!rollup_mode) {
799-
show_map_vma(m, vma, is_pid);
770+
show_map_vma(m, vma);
800771
} else if (last_vma) {
801772
show_vma_header_prefix(
802773
m, mss->first_vma_start, vma->vm_end, 0, 0, 0, 0);
@@ -845,28 +816,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
845816
}
846817
#undef SEQ_PUT_DEC
847818

848-
static int show_pid_smap(struct seq_file *m, void *v)
849-
{
850-
return show_smap(m, v, 1);
851-
}
852-
853-
static int show_tid_smap(struct seq_file *m, void *v)
854-
{
855-
return show_smap(m, v, 0);
856-
}
857-
858819
static const struct seq_operations proc_pid_smaps_op = {
859820
.start = m_start,
860821
.next = m_next,
861822
.stop = m_stop,
862-
.show = show_pid_smap
863-
};
864-
865-
static const struct seq_operations proc_tid_smaps_op = {
866-
.start = m_start,
867-
.next = m_next,
868-
.stop = m_stop,
869-
.show = show_tid_smap
823+
.show = show_smap
870824
};
871825

872826
static int pid_smaps_open(struct inode *inode, struct file *file)
@@ -893,11 +847,6 @@ static int pid_smaps_rollup_open(struct inode *inode, struct file *file)
893847
return 0;
894848
}
895849

896-
static int tid_smaps_open(struct inode *inode, struct file *file)
897-
{
898-
return do_maps_open(inode, file, &proc_tid_smaps_op);
899-
}
900-
901850
const struct file_operations proc_pid_smaps_operations = {
902851
.open = pid_smaps_open,
903852
.read = seq_read,
@@ -912,13 +861,6 @@ const struct file_operations proc_pid_smaps_rollup_operations = {
912861
.release = proc_map_release,
913862
};
914863

915-
const struct file_operations proc_tid_smaps_operations = {
916-
.open = tid_smaps_open,
917-
.read = seq_read,
918-
.llseek = seq_lseek,
919-
.release = proc_map_release,
920-
};
921-
922864
enum clear_refs_types {
923865
CLEAR_REFS_ALL = 1,
924866
CLEAR_REFS_ANON,
@@ -1728,7 +1670,7 @@ static int gather_hugetlb_stats(pte_t *pte, unsigned long hmask,
17281670
/*
17291671
* Display pages allocated per node and memory policy via /proc.
17301672
*/
1731-
static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1673+
static int show_numa_map(struct seq_file *m, void *v)
17321674
{
17331675
struct numa_maps_private *numa_priv = m->private;
17341676
struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
@@ -1812,45 +1754,17 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
18121754
return 0;
18131755
}
18141756

1815-
static int show_pid_numa_map(struct seq_file *m, void *v)
1816-
{
1817-
return show_numa_map(m, v, 1);
1818-
}
1819-
1820-
static int show_tid_numa_map(struct seq_file *m, void *v)
1821-
{
1822-
return show_numa_map(m, v, 0);
1823-
}
1824-
18251757
static const struct seq_operations proc_pid_numa_maps_op = {
18261758
.start = m_start,
18271759
.next = m_next,
18281760
.stop = m_stop,
1829-
.show = show_pid_numa_map,
1761+
.show = show_numa_map,
18301762
};
18311763

1832-
static const struct seq_operations proc_tid_numa_maps_op = {
1833-
.start = m_start,
1834-
.next = m_next,
1835-
.stop = m_stop,
1836-
.show = show_tid_numa_map,
1837-
};
1838-
1839-
static int numa_maps_open(struct inode *inode, struct file *file,
1840-
const struct seq_operations *ops)
1841-
{
1842-
return proc_maps_open(inode, file, ops,
1843-
sizeof(struct numa_maps_private));
1844-
}
1845-
18461764
static int pid_numa_maps_open(struct inode *inode, struct file *file)
18471765
{
1848-
return numa_maps_open(inode, file, &proc_pid_numa_maps_op);
1849-
}
1850-
1851-
static int tid_numa_maps_open(struct inode *inode, struct file *file)
1852-
{
1853-
return numa_maps_open(inode, file, &proc_tid_numa_maps_op);
1766+
return proc_maps_open(inode, file, &proc_pid_numa_maps_op,
1767+
sizeof(struct numa_maps_private));
18541768
}
18551769

18561770
const struct file_operations proc_pid_numa_maps_operations = {
@@ -1860,10 +1774,4 @@ const struct file_operations proc_pid_numa_maps_operations = {
18601774
.release = proc_map_release,
18611775
};
18621776

1863-
const struct file_operations proc_tid_numa_maps_operations = {
1864-
.open = tid_numa_maps_open,
1865-
.read = seq_read,
1866-
.llseek = seq_lseek,
1867-
.release = proc_map_release,
1868-
};
18691777
#endif /* CONFIG_NUMA */

fs/proc/task_nommu.c

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ static int is_stack(struct vm_area_struct *vma)
142142
/*
143143
* display a single VMA to a sequenced file
144144
*/
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)
147146
{
148147
struct mm_struct *mm = vma->vm_mm;
149148
unsigned long ino = 0;
@@ -189,22 +188,11 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
189188
/*
190189
* display mapping lines for a particular process's /proc/pid/maps
191190
*/
192-
static int show_map(struct seq_file *m, void *_p, int is_pid)
191+
static int show_map(struct seq_file *m, void *_p)
193192
{
194193
struct rb_node *p = _p;
195194

196-
return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb),
197-
is_pid);
198-
}
199-
200-
static int show_pid_map(struct seq_file *m, void *_p)
201-
{
202-
return show_map(m, _p, 1);
203-
}
204-
205-
static int show_tid_map(struct seq_file *m, void *_p)
206-
{
207-
return show_map(m, _p, 0);
195+
return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb));
208196
}
209197

210198
static void *m_start(struct seq_file *m, loff_t *pos)
@@ -260,14 +248,7 @@ static const struct seq_operations proc_pid_maps_ops = {
260248
.start = m_start,
261249
.next = m_next,
262250
.stop = m_stop,
263-
.show = show_pid_map
264-
};
265-
266-
static const struct seq_operations proc_tid_maps_ops = {
267-
.start = m_start,
268-
.next = m_next,
269-
.stop = m_stop,
270-
.show = show_tid_map
251+
.show = show_map
271252
};
272253

273254
static int maps_open(struct inode *inode, struct file *file,
@@ -308,22 +289,10 @@ static int pid_maps_open(struct inode *inode, struct file *file)
308289
return maps_open(inode, file, &proc_pid_maps_ops);
309290
}
310291

311-
static int tid_maps_open(struct inode *inode, struct file *file)
312-
{
313-
return maps_open(inode, file, &proc_tid_maps_ops);
314-
}
315-
316292
const struct file_operations proc_pid_maps_operations = {
317293
.open = pid_maps_open,
318294
.read = seq_read,
319295
.llseek = seq_lseek,
320296
.release = map_release,
321297
};
322298

323-
const struct file_operations proc_tid_maps_operations = {
324-
.open = tid_maps_open,
325-
.read = seq_read,
326-
.llseek = seq_lseek,
327-
.release = map_release,
328-
};
329-

0 commit comments

Comments
 (0)