Skip to content

Commit ee17e48

Browse files
Alexey Dobriyanvbajs
authored andcommitted
[BACKPORT] proc: less memory for /proc/*/map_files readdir
dentry name can be evaluated later, right before calling into VFS. Also, spend less time under ->mmap_sem. Link: http://lkml.kernel.org/r/20171110163034.GA2534@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Yahya Wessam <yahyawessam2002@gmail.com>
1 parent d0b1772 commit ee17e48

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

fs/proc/base.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,9 +2277,9 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
22772277
}
22782278

22792279
struct map_files_info {
2280+
unsigned long start;
2281+
unsigned long end;
22802282
fmode_t mode;
2281-
unsigned int len;
2282-
unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
22832283
};
22842284

22852285
/*
@@ -2449,10 +2449,9 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
24492449
if (++pos <= ctx->pos)
24502450
continue;
24512451

2452+
info.start = vma->vm_start;
2453+
info.end = vma->vm_end;
24522454
info.mode = vma->vm_file->f_mode;
2453-
info.len = snprintf(info.name,
2454-
sizeof(info.name), "%lx-%lx",
2455-
vma->vm_start, vma->vm_end);
24562455
if (flex_array_put(fa, i++, &info, GFP_KERNEL))
24572456
BUG();
24582457
}
@@ -2461,9 +2460,13 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
24612460
mmput(mm);
24622461

24632462
for (i = 0; i < nr_files; i++) {
2463+
char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */
2464+
unsigned int len;
2465+
24642466
p = flex_array_get(fa, i);
2467+
len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end);
24652468
if (!proc_fill_cache(file, ctx,
2466-
p->name, p->len,
2469+
buf, len,
24672470
proc_map_files_instantiate,
24682471
task,
24692472
(void *)(unsigned long)p->mode))

0 commit comments

Comments
 (0)