From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753365AbdKJQak (ORCPT ); Fri, 10 Nov 2017 11:30:40 -0500 Received: from mail-wr0-f169.google.com ([209.85.128.169]:43340 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753230AbdKJQai (ORCPT ); Fri, 10 Nov 2017 11:30:38 -0500 X-Google-Smtp-Source: AGs4zMauQvGjMi120mmqacPS2TjUeYTwEdoM8Z9RMGPQ1603029Pyn/yRXzQAROk3w1bKEeyMujAVg== Date: Fri, 10 Nov 2017 19:30:34 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, xemul@parallels.com Subject: [PATCH] proc: less memory for /proc/*/map_files readdir Message-ID: <20171110163034.GA2534@avx2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.2 (2016-11-26) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dentry name can be evaluated later, right before calling into VFS. Also, spend less time under ->mmap_sem. Signed-off-by: Alexey Dobriyan --- fs/proc/base.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2001,9 +2001,9 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) } struct map_files_info { + unsigned long start; + unsigned long end; fmode_t mode; - unsigned int len; - unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */ }; /* @@ -2173,10 +2173,9 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) if (++pos <= ctx->pos) continue; + info.start = vma->vm_start; + info.end = vma->vm_end; 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)) BUG(); } @@ -2184,9 +2183,13 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) up_read(&mm->mmap_sem); 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); + len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end); if (!proc_fill_cache(file, ctx, - p->name, p->len, + buf, len, proc_map_files_instantiate, task, (void *)(unsigned long)p->mode))