diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-12 02:31:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 13:04:02 -0400 |
commit | 94f8f3b02e1ee0418b5cc9352626cdc2b6bd4299 (patch) | |
tree | 7d0556ee2042ca66d989d2147bf9c8bb3b38e6f8 /fs/proc | |
parent | ba20ba2e3743bac786dff777954c11930256075e (diff) |
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.com
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Reviewed-by: Alexey 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/base.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 1b548d060d28..f5ebdd87afb2 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <linux/capability.h> | 59 | #include <linux/capability.h> |
60 | #include <linux/file.h> | 60 | #include <linux/file.h> |
61 | #include <linux/fdtable.h> | 61 | #include <linux/fdtable.h> |
62 | #include <linux/generic-radix-tree.h> | ||
62 | #include <linux/string.h> | 63 | #include <linux/string.h> |
63 | #include <linux/seq_file.h> | 64 | #include <linux/seq_file.h> |
64 | #include <linux/namei.h> | 65 | #include <linux/namei.h> |
@@ -92,7 +93,6 @@ | |||
92 | #include <linux/sched/coredump.h> | 93 | #include <linux/sched/coredump.h> |
93 | #include <linux/sched/debug.h> | 94 | #include <linux/sched/debug.h> |
94 | #include <linux/sched/stat.h> | 95 | #include <linux/sched/stat.h> |
95 | #include <linux/flex_array.h> | ||
96 | #include <linux/posix-timers.h> | 96 | #include <linux/posix-timers.h> |
97 | #include <trace/events/oom.h> | 97 | #include <trace/events/oom.h> |
98 | #include "internal.h" | 98 | #include "internal.h" |
@@ -2142,11 +2142,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) | |||
2142 | struct task_struct *task; | 2142 | struct task_struct *task; |
2143 | struct mm_struct *mm; | 2143 | struct mm_struct *mm; |
2144 | unsigned long nr_files, pos, i; | 2144 | unsigned long nr_files, pos, i; |
2145 | struct flex_array *fa = NULL; | 2145 | GENRADIX(struct map_files_info) fa; |
2146 | struct map_files_info info; | ||
2147 | struct map_files_info *p; | 2146 | struct map_files_info *p; |
2148 | int ret; | 2147 | int ret; |
2149 | 2148 | ||
2149 | genradix_init(&fa); | ||
2150 | |||
2150 | ret = -ENOENT; | 2151 | ret = -ENOENT; |
2151 | task = get_proc_task(file_inode(file)); | 2152 | task = get_proc_task(file_inode(file)); |
2152 | if (!task) | 2153 | if (!task) |
@@ -2178,35 +2179,22 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) | |||
2178 | */ | 2179 | */ |
2179 | 2180 | ||
2180 | for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) { | 2181 | for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) { |
2181 | if (vma->vm_file && ++pos > ctx->pos) | 2182 | if (!vma->vm_file) |
2182 | nr_files++; | 2183 | continue; |
2183 | } | 2184 | if (++pos <= ctx->pos) |
2185 | continue; | ||
2184 | 2186 | ||
2185 | if (nr_files) { | 2187 | p = genradix_ptr_alloc(&fa, nr_files++, GFP_KERNEL); |
2186 | fa = flex_array_alloc(sizeof(info), nr_files, | 2188 | if (!p) { |
2187 | GFP_KERNEL); | ||
2188 | if (!fa || flex_array_prealloc(fa, 0, nr_files, | ||
2189 | GFP_KERNEL)) { | ||
2190 | ret = -ENOMEM; | 2189 | ret = -ENOMEM; |
2191 | if (fa) | ||
2192 | flex_array_free(fa); | ||
2193 | up_read(&mm->mmap_sem); | 2190 | up_read(&mm->mmap_sem); |
2194 | mmput(mm); | 2191 | mmput(mm); |
2195 | goto out_put_task; | 2192 | goto out_put_task; |
2196 | } | 2193 | } |
2197 | for (i = 0, vma = mm->mmap, pos = 2; vma; | ||
2198 | vma = vma->vm_next) { | ||
2199 | if (!vma->vm_file) | ||
2200 | continue; | ||
2201 | if (++pos <= ctx->pos) | ||
2202 | continue; | ||
2203 | 2194 | ||
2204 | info.start = vma->vm_start; | 2195 | p->start = vma->vm_start; |
2205 | info.end = vma->vm_end; | 2196 | p->end = vma->vm_end; |
2206 | info.mode = vma->vm_file->f_mode; | 2197 | p->mode = vma->vm_file->f_mode; |
2207 | if (flex_array_put(fa, i++, &info, GFP_KERNEL)) | ||
2208 | BUG(); | ||
2209 | } | ||
2210 | } | 2198 | } |
2211 | up_read(&mm->mmap_sem); | 2199 | up_read(&mm->mmap_sem); |
2212 | mmput(mm); | 2200 | mmput(mm); |
@@ -2215,7 +2203,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) | |||
2215 | char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */ | 2203 | char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */ |
2216 | unsigned int len; | 2204 | unsigned int len; |
2217 | 2205 | ||
2218 | p = flex_array_get(fa, i); | 2206 | p = genradix_ptr(&fa, i); |
2219 | len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end); | 2207 | len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end); |
2220 | if (!proc_fill_cache(file, ctx, | 2208 | if (!proc_fill_cache(file, ctx, |
2221 | buf, len, | 2209 | buf, len, |
@@ -2225,12 +2213,11 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) | |||
2225 | break; | 2213 | break; |
2226 | ctx->pos++; | 2214 | ctx->pos++; |
2227 | } | 2215 | } |
2228 | if (fa) | ||
2229 | flex_array_free(fa); | ||
2230 | 2216 | ||
2231 | out_put_task: | 2217 | out_put_task: |
2232 | put_task_struct(task); | 2218 | put_task_struct(task); |
2233 | out: | 2219 | out: |
2220 | genradix_free(&fa); | ||
2234 | return ret; | 2221 | return ret; |
2235 | } | 2222 | } |
2236 | 2223 | ||