Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kent Overstreet and committed by
Linus Torvalds
94f8f3b0 ba20ba2e

+15 -28
+15 -28
fs/proc/base.c
··· 59 59 #include <linux/capability.h> 60 60 #include <linux/file.h> 61 61 #include <linux/fdtable.h> 62 + #include <linux/generic-radix-tree.h> 62 63 #include <linux/string.h> 63 64 #include <linux/seq_file.h> 64 65 #include <linux/namei.h> ··· 93 92 #include <linux/sched/coredump.h> 94 93 #include <linux/sched/debug.h> 95 94 #include <linux/sched/stat.h> 96 - #include <linux/flex_array.h> 97 95 #include <linux/posix-timers.h> 98 96 #include <trace/events/oom.h> 99 97 #include "internal.h" ··· 2142 2142 struct task_struct *task; 2143 2143 struct mm_struct *mm; 2144 2144 unsigned long nr_files, pos, i; 2145 - struct flex_array *fa = NULL; 2146 - struct map_files_info info; 2145 + GENRADIX(struct map_files_info) fa; 2147 2146 struct map_files_info *p; 2148 2147 int ret; 2148 + 2149 + genradix_init(&fa); 2149 2150 2150 2151 ret = -ENOENT; 2151 2152 task = get_proc_task(file_inode(file)); ··· 2179 2178 */ 2180 2179 2181 2180 for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) { 2182 - if (vma->vm_file && ++pos > ctx->pos) 2183 - nr_files++; 2184 - } 2181 + if (!vma->vm_file) 2182 + continue; 2183 + if (++pos <= ctx->pos) 2184 + continue; 2185 2185 2186 - if (nr_files) { 2187 - fa = flex_array_alloc(sizeof(info), nr_files, 2188 - GFP_KERNEL); 2189 - if (!fa || flex_array_prealloc(fa, 0, nr_files, 2190 - GFP_KERNEL)) { 2186 + p = genradix_ptr_alloc(&fa, nr_files++, GFP_KERNEL); 2187 + if (!p) { 2191 2188 ret = -ENOMEM; 2192 - if (fa) 2193 - flex_array_free(fa); 2194 2189 up_read(&mm->mmap_sem); 2195 2190 mmput(mm); 2196 2191 goto out_put_task; 2197 2192 } 2198 - for (i = 0, vma = mm->mmap, pos = 2; vma; 2199 - vma = vma->vm_next) { 2200 - if (!vma->vm_file) 2201 - continue; 2202 - if (++pos <= ctx->pos) 2203 - continue; 2204 2193 2205 - info.start = vma->vm_start; 2206 - info.end = vma->vm_end; 2207 - info.mode = vma->vm_file->f_mode; 2208 - if (flex_array_put(fa, i++, &info, GFP_KERNEL)) 2209 - BUG(); 2210 - } 2194 + p->start = vma->vm_start; 2195 + p->end = vma->vm_end; 2196 + p->mode = vma->vm_file->f_mode; 2211 2197 } 2212 2198 up_read(&mm->mmap_sem); 2213 2199 mmput(mm); ··· 2203 2215 char buf[4 * sizeof(long) + 2]; /* max: %lx-%lx\0 */ 2204 2216 unsigned int len; 2205 2217 2206 - p = flex_array_get(fa, i); 2218 + p = genradix_ptr(&fa, i); 2207 2219 len = snprintf(buf, sizeof(buf), "%lx-%lx", p->start, p->end); 2208 2220 if (!proc_fill_cache(file, ctx, 2209 2221 buf, len, ··· 2213 2225 break; 2214 2226 ctx->pos++; 2215 2227 } 2216 - if (fa) 2217 - flex_array_free(fa); 2218 2228 2219 2229 out_put_task: 2220 2230 put_task_struct(task); 2221 2231 out: 2232 + genradix_free(&fa); 2222 2233 return ret; 2223 2234 } 2224 2235