pid: replace pid bitmap implementation with IDR API
Subsystems (5)
PATCH 73/94 pid: replace pid bitmap implementation with IDR API
From: Gargi Sharma <[email protected]>
Subject: pid: replace pid bitmap implementation with IDR API
Patch series "Replacing PID bitmap implementation with IDR API", v4.
This series replaces kernel bitmap implementation of PID allocation with IDR API. These patches are written to simplify the kernel by replacing custom code with calls to generic code.
The following are the stats for pid and pid_namespace object files before and after the replacement. There is a noteworthy change between the IDR and bitmap implementation.
Before
text data bss dec hex filename
8447 3894 64 12405 3075 kernel/pid.o
After
text data bss dec hex filename
3397 304 0 3701 e75 kernel/pid.o
Before
text data bss dec hex filename
5692 1842 192 7726 1e2e kernel/pid_namespace.o
After
text data bss dec hex filename
2854 216 16 3086 c0e kernel/pid_namespace.o
The following are the stats for ps, pstree and calling readdir on /proc for 10,000 processes.
ps:
With IDR API With bitmap real 0m1.479s 0m2.319s user 0m0.070s 0m0.060s sys 0m0.289s 0m0.516s
pstree:
With IDR API With bitmap real 0m1.024s 0m1.794s user 0m0.348s 0m0.612s sys 0m0.184s 0m0.264s
proc:
With IDR API With bitmap real 0m0.059s 0m0.074s user 0m0.000s 0m0.004s sys 0m0.016s 0m0.016s
This patch (of 2):
Replace the current bitmap implementation for Process ID allocation. Functions that are no longer required, for example, free_pidmap(), alloc_pidmap(), etc. are removed. The rest of the functions are modified to use the IDR API. The change was made to make the PID allocation less complex by replacing custom code with calls to generic API.
---
arch/powerpc/platforms/cell/spufs/sched.c | 2 fs/proc/loadavg.c | 2 include/linux/pid_namespace.h | 14 - init/main.c | 2 kernel/pid.c | 201 +++----------------- kernel/pid_namespace.c | 53 ++--- 6 files changed, 65 insertions(+), 209 deletions(-)
arch/powerpc/platforms/cell/spufs/sched.c renamed from arch/powerpc/platforms/cell/spufs/sched.c~pid-replace-pid-bitmap-implementation-with-idr-api +1 -1
@@ -1093,7 +1093,7 @@ static int show_spu_loadavg(struct seq_fLOAD_INT (c),LOAD_FRAC (c),count_active_contexts (),atomic_read (&nr_spu_contexts), - task_active_pid_ns(current)->last_pid); + idr_get_cursor(&task_active_pid_ns(current)->idr));return 0 ; }
fs/proc/loadavg.c renamed from fs/proc/loadavg.c~pid-replace-pid-bitmap-implementation-with-idr-api +1 -1
@@ -24,7 +24,7 @@ static int loadavg_proc_show(struct seq_LOAD_INT (avnrun[1 ]),LOAD_FRAC (avnrun[1 ]),LOAD_INT (avnrun[2 ]),LOAD_FRAC (avnrun[2 ]),nr_running (), nr_threads, - task_active_pid_ns(current)->last_pid); + idr_get_cursor(&task_active_pid_ns(current)->idr));return 0 ; }
include/linux/pid_namespace.h renamed from include/linux/pid_namespace.h~pid-replace-pid-bitmap-implementation-with-idr-api +3 -11
@@ -10,15 +10,8 @@#include <linux/nsproxy.h> #include <linux/kref.h> #include <linux/ns_common.h> +#include <linux/idr.h> -struct pidmap { -atomic_t nr_free; -void *page; -}; - -#define BITS_PER_PAGE (PAGE_SIZE * 8) -#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) -#define PIDMAP_ENTRIES ((PID_MAX_LIMIT+BITS_PER_PAGE-1)/BITS_PER_PAGE)struct fs_pin ;
@@ -30,9 +23,8 @@ enum { /* definitions for pid_namespace'struct pid_namespace {struct kref kref; -struct pidmap pidmap[PIDMAP_ENTRIES ]; +struct idr idr;struct rcu_head rcu; -int last_pid;unsigned int nr_hashed;struct task_struct *child_reaper;struct kmem_cache *pid_cachep;
@@ -106,6 +98,6 @@ static inline int reboot_pid_ns(struct pextern struct pid_namespace *task_active_pid_ns (struct task_struct *tsk);void pidhash_init (void ); -void pidmap_init (void ); +void pid_idr_init (void );#endif /* _LINUX_PID_NS_H */
init/main.c renamed from init/main.c~pid-replace-pid-bitmap-implementation-with-idr-api +1 -1
@@ -669,7 +669,7 @@ asmlinkage __visible void __init start_kif (late_time_init)late_time_init ();calibrate_delay (); -pidmap_init (); +pid_idr_init ();anon_vma_init ();#ifdef CONFIG_X86 if (efi_enabled (EFI_RUNTIME_SERVICES ))
kernel/pid.c renamed from kernel/pid.c~pid-replace-pid-bitmap-implementation-with-idr-api +36 -165
278 lines not on this page · raw message
kernel/pid_namespace.c renamed from kernel/pid_namespace.c~pid-replace-pid-bitmap-implementation-with-idr-api +23 -30
121 lines not on this page · raw message
_