提交 20d28cde 编写于 作者: A Alexey Dobriyan 提交者: Linus Torvalds

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@avx2Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 593bc695
...@@ -2026,9 +2026,9 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) ...@@ -2026,9 +2026,9 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
} }
struct map_files_info { struct map_files_info {
unsigned long start;
unsigned long end;
fmode_t mode; fmode_t mode;
unsigned int len;
unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
}; };
/* /*
...@@ -2198,10 +2198,9 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2198,10 +2198,9 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
if (++pos <= ctx->pos) if (++pos <= ctx->pos)
continue; continue;
info.start = vma->vm_start;
info.end = vma->vm_end;
info.mode = vma->vm_file->f_mode; info.mode = vma->vm_file->f_mode;
info.len = snprintf(info.name,
sizeof(info.name), "%lx-%lx",
vma->vm_start, vma->vm_end);
if (flex_array_put(fa, i++, &info, GFP_KERNEL)) if (flex_array_put(fa, i++, &info, GFP_KERNEL))
BUG(); BUG();
} }
...@@ -2209,9 +2208,13 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2209,9 +2208,13 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
for (i = 0; i < nr_files; i++) { for (i = 0; i < nr_files; i++) {
char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */
unsigned int len;
p = flex_array_get(fa, i); p = flex_array_get(fa, i);
len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end);
if (!proc_fill_cache(file, ctx, if (!proc_fill_cache(file, ctx,
p->name, p->len, buf, len,
proc_map_files_instantiate, proc_map_files_instantiate,
task, task,
(void *)(unsigned long)p->mode)) (void *)(unsigned long)p->mode))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册