Commit 94f8f3b0 authored by Kent Overstreet's avatar Kent Overstreet Committed by Linus Torvalds

proc: commit to genradix

The new generic radix trees have a simpler API and implementation, and
no limitations on number of elements, so all flex_array users are being
converted

Link: http://lkml.kernel.org/r/20181217131929.11727-6-kent.overstreet@gmail.comSigned-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Reviewed-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Eric Paris <eparis@parisplace.org>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Pravin B Shelar <pshelar@ovn.org>
Cc: Shaohua Li <shli@kernel.org>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ba20ba2e
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/file.h> #include <linux/file.h>
#include <linux/fdtable.h> #include <linux/fdtable.h>
#include <linux/generic-radix-tree.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/namei.h> #include <linux/namei.h>
...@@ -92,7 +93,6 @@ ...@@ -92,7 +93,6 @@
#include <linux/sched/coredump.h> #include <linux/sched/coredump.h>
#include <linux/sched/debug.h> #include <linux/sched/debug.h>
#include <linux/sched/stat.h> #include <linux/sched/stat.h>
#include <linux/flex_array.h>
#include <linux/posix-timers.h> #include <linux/posix-timers.h>
#include <trace/events/oom.h> #include <trace/events/oom.h>
#include "internal.h" #include "internal.h"
...@@ -2142,11 +2142,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2142,11 +2142,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
struct task_struct *task; struct task_struct *task;
struct mm_struct *mm; struct mm_struct *mm;
unsigned long nr_files, pos, i; unsigned long nr_files, pos, i;
struct flex_array *fa = NULL; GENRADIX(struct map_files_info) fa;
struct map_files_info info;
struct map_files_info *p; struct map_files_info *p;
int ret; int ret;
genradix_init(&fa);
ret = -ENOENT; ret = -ENOENT;
task = get_proc_task(file_inode(file)); task = get_proc_task(file_inode(file));
if (!task) if (!task)
...@@ -2178,35 +2179,22 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2178,35 +2179,22 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
*/ */
for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) { for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
if (vma->vm_file && ++pos > ctx->pos) if (!vma->vm_file)
nr_files++; continue;
} if (++pos <= ctx->pos)
continue;
if (nr_files) { p = genradix_ptr_alloc(&fa, nr_files++, GFP_KERNEL);
fa = flex_array_alloc(sizeof(info), nr_files, if (!p) {
GFP_KERNEL);
if (!fa || flex_array_prealloc(fa, 0, nr_files,
GFP_KERNEL)) {
ret = -ENOMEM; ret = -ENOMEM;
if (fa)
flex_array_free(fa);
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
mmput(mm); mmput(mm);
goto out_put_task; goto out_put_task;
} }
for (i = 0, vma = mm->mmap, pos = 2; vma;
vma = vma->vm_next) {
if (!vma->vm_file)
continue;
if (++pos <= ctx->pos)
continue;
info.start = vma->vm_start; p->start = vma->vm_start;
info.end = vma->vm_end; p->end = vma->vm_end;
info.mode = vma->vm_file->f_mode; p->mode = vma->vm_file->f_mode;
if (flex_array_put(fa, i++, &info, GFP_KERNEL))
BUG();
}
} }
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
mmput(mm); mmput(mm);
...@@ -2215,7 +2203,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2215,7 +2203,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */ char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */
unsigned int len; unsigned int len;
p = flex_array_get(fa, i); p = genradix_ptr(&fa, i);
len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end); len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end);
if (!proc_fill_cache(file, ctx, if (!proc_fill_cache(file, ctx,
buf, len, buf, len,
...@@ -2225,12 +2213,11 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) ...@@ -2225,12 +2213,11 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
break; break;
ctx->pos++; ctx->pos++;
} }
if (fa)
flex_array_free(fa);
out_put_task: out_put_task:
put_task_struct(task); put_task_struct(task);
out: out:
genradix_free(&fa);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment