Skip to contentSkip to conversation

Replacing PID bitmap implementation with IDR API

PATCH Superseded Gargi Sharma 6 participants 14 messages Oct 9, 2017 – Oct 11, 2017

Subsystems (8)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Replacing PID bitmap implementation with IDR API

This patch 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

---
Changes in v4:
- Make comments for alloc_pid clearer.
Changes in v3:
- Replace idr_next with idr_get_cursor().
- Correct pid_alloc so that find_pid_ns can't find not completely allocated pids.
Changes in v2:
- Removed redundant IDR function that was introduced in the previous patchset.
- Renamed PIDNS_HASH_ADDING
- Used idr_for_each_entry_continue()
- Used idr_find() to lookup pids

Gargi Sharma (2):
pid: Replace pid bitmap implementation with IDR API
pid: Remove pidhash

 arch/powerpc/platforms/cell/spufs/sched.c |   2 +-
 fs/proc/loadavg.c                         |   2 +-
 include/linux/init_task.h                 |   1 -
 include/linux/pid.h                       |   2 -
 include/linux/pid_namespace.h             |  18 +--
 init/main.c                               |   3 +-
 kernel/fork.c                             |   2 +-
 kernel/pid.c                              | 245 ++++++------------------------
 kernel/pid_namespace.c                    |  48 ++----
 9 files changed, 68 insertions(+), 255 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/2 pid: Replace pid bitmap implementation with IDR API

This patch replaces the current bitmap implemetation 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                              | 197 +++++-------------------------
 kernel/pid_namespace.c                    |  42 ++-----
 6 files changed, 52 insertions(+), 207 deletions(-)
arch/powerpc/platforms/cell/spufs/sched.c +1 -1
index 1fbb5da..e47761c 100644
@@ -1093,7 +1093,7 @@ static int show_spu_loadavg(struct seq_file *s, void *private)
 		LOAD_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 +1 -1
index 983fce5..ba3d0e2 100644
@@ -23,7 +23,7 @@ static int loadavg_proc_show(struct seq_file *m, void *v)
 		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 +3 -11
index b09136f..f4db4a7 100644
@@ -9,15 +9,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;
 
@@ -29,9 +22,8 @@ enum { /* definitions for pid_namespace's hide_pid field */
 
 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;
@@ -105,6 +97,6 @@ static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
 
 extern 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 +1 -1
index 0ee9c686..9f4db20 100644
@@ -667,7 +667,7 @@ asmlinkage __visible void __init start_kernel(void)
 	if (late_time_init)
 		late_time_init();
 	calibrate_delay();
-	pidmap_init();
+	pid_idr_init();
 	anon_vma_init();
 	acpi_early_init();
 #ifdef CONFIG_X86
kernel/pid.c +33 -164

268 lines not on this page · raw message

kernel/pid_namespace.c +13 -29

101 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 7 lines · On Mon, 9 Oct 2017 17:13:43 -0400 Gargi Sharma <[email protected]> wrote:

This patch replaces the current bitmap implemetation 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.

I can't say I really understand the locking here.

Quoted 13 lines

...

kernel/pid_namespace.c +1 -5
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 	 *
 	 */
 	read_lock(&tasklist_lock);
-	nr = next_pidmap(pid_ns, 1);
-	while (nr > 0) {
-		rcu_read_lock();
-
-		task = pid_task(find_vpid(nr), PIDTYPE_PID);
+	nr = 2;

kernel/pid_namespace.c void zap_pid_ns_processes(struct pid_namespace *pid_ns) · line 239

Quoted 10 lines
kernel/pid_namespace.c +2 -4
+	idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+		task = pid_task(pid, PIDTYPE_PID);
 		if (task && !__fatal_signal_pending(task))
 			send_sig_info(SIGKILL, SEND_SIG_FORCED, task);
-
-		rcu_read_unlock();
-
-		nr = next_pidmap(pid_ns, nr);
 	}
 	read_unlock(&tasklist_lock);

Especially here. I don't think pidmap_lock is held. Is that IDR iteration safe?

#3 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 16 lines · Andrew Morton
Quoted 16 lines
kernel/pid_namespace.c +3 -6
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 	 *
 	 */
 	read_lock(&tasklist_lock);
-	nr = next_pidmap(pid_ns, 1);
-	while (nr > 0) {
-		rcu_read_lock();
-
-		task = pid_task(find_vpid(nr), PIDTYPE_PID);
+	nr = 2;
+	idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+		task = pid_task(pid, PIDTYPE_PID);
 		if (task && !__fatal_signal_pending(task))
 			send_sig_info(SIGKILL, SEND_SIG_FORCED, task);
-
Quoted 8 lines

kernel/pid_namespace.c void zap_pid_ns_processes(struct pid_namespace *pid_ns) · line 239

Quoted 5 lines
kernel/pid_namespace.c +0 -3
-		rcu_read_unlock();
-
-		nr = next_pidmap(pid_ns, nr);
 	}
 	read_unlock(&tasklist_lock);

Especially here. I don't think pidmap_lock is held. Is that IDR iteration safe?

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering if we should use idr_for_each() instead. IIUC this would be a bit faster? Not that I think this is really important...

Oleg.

#4 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 26 lines · Oleg Nesterov
Quoted 16 lines · Andrew Morton
Quoted 16 lines
kernel/pid_namespace.c +3 -6
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
     *
     */
    read_lock(&tasklist_lock);
-   nr = next_pidmap(pid_ns, 1);
-   while (nr > 0) {
-           rcu_read_lock();
-
-           task = pid_task(find_vpid(nr), PIDTYPE_PID);
+   nr = 2;
+   idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+           task = pid_task(pid, PIDTYPE_PID);
            if (task && !__fatal_signal_pending(task))
                    send_sig_info(SIGKILL, SEND_SIG_FORCED, task);
-
Quoted 8 lines

kernel/pid_namespace.c void zap_pid_ns_processes(struct pid_namespace *pid_ns) · line 239

Quoted 5 lines
kernel/pid_namespace.c +0 -3
-           rcu_read_unlock();
-
-           nr = next_pidmap(pid_ns, nr);
    }
    read_unlock(&tasklist_lock);

Especially here. I don't think pidmap_lock is held. Is that IDR iteration safe?

Quoted 3 lines

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

Ah, I missed this. From what I understood idr_for_each_entry_continue should be safe because calls idr_get_next which in turn calls radix_tree_iter_find to find the next populated entry in the idr. If the pid that you are looking up the task for is deleted, task will get a NULL from pid_task and no signal to kill will be sent.

Quoted 4 lines

Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering if we should use idr_for_each() instead. IIUC this would be a bit faster? Not that I think this is really important...

I can run benchmarks with idr_for_each to see how much speed up is achieved and then we can go with whatever we think is better. How does that sounds?

Thanks!
Gargi

Quoted 3 lines

Oleg.

#5 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 7 lines · Gargi Sharma
Quoted 5 lines · Oleg Nesterov
Quoted 3 lines · Andrew Morton

Especially here. I don't think pidmap_lock is held. Is that IDR iteration safe?

Quoted 6 lines
Quoted 3 lines

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

Ah, I missed this. From what I understood idr_for_each_entry_continue should be safe

Without rcu? Why?

Quoted 2 lines

because calls idr_get_next which in turn calls radix_tree_iter_find to find the next populated entry in the idr.

and then it does rcu_dereference_raw(*slot). Without rcu or pidmap this slot can got away if we race with free_pid().

Quoted 3 lines

If
the pid that you are looking up the task for is deleted, task will get a NULL from pid_task and no signal to kill will be sent.

pid->tasks is protected by tasklist_lock, but the pid itself can go away without rcu lock.

So I think you need to take rcu_read_lock() right after tasklist_lock.

Quoted 7 lines
Quoted 3 lines

Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering if we should use idr_for_each() instead. IIUC this would be a bit faster? Not that I think this is really important...

I can run benchmarks with idr_for_each to see how much speed up is achieved and then we can go with whatever we think is better. How does that sounds?

Up to you ;) I am fine either way.

Oleg.

#6 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

In reply to Gargi Sharma
Quoted 49 lines · Gargi Sharma
Quoted 28 lines · Oleg Nesterov
Quoted 18 lines · Andrew Morton
Quoted 18 lines
kernel/pid_namespace.c +3 -6
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct
 pid_namespace *pid_ns)
      *
      */
     read_lock(&tasklist_lock);
-   nr = next_pidmap(pid_ns, 1);
-   while (nr > 0) {
-           rcu_read_lock();
-
-           task = pid_task(find_vpid(nr), PIDTYPE_PID);
+   nr = 2;
+   idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+           task = pid_task(pid, PIDTYPE_PID);
             if (task && !__fatal_signal_pending(task))
                     send_sig_info(SIGKILL, SEND_SIG_FORCED,
 task);
-
Quoted 8 lines
Quoted 5 lines
kernel/pid_namespace.c +0 -3
-           rcu_read_unlock();
-
-           nr = next_pidmap(pid_ns, nr);
     }

    read_unlock(&tasklist_lock);

Especially here.  I don't think pidmap_lock is held.  Is that IDR iteration safe?

Quoted 5 lines

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

Ah, I missed this. From what I understood idr_for_each_entry_continue should be safe because calls idr_get_next which in turn calls radix_tree_iter_find to find the next populated entry in the idr. If the pid that you are looking up the task for is deleted, task will get
a NULL from pid_task and no signal to kill will be sent.

Quoted 6 lines

Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering
if we should use idr_for_each() instead. IIUC this would be a bit faster? Not
that I think this is really important...

Quoted 4 lines

I can run benchmarks with idr_for_each to see how much speed up is achieved and then we can go with whatever we think is better. How does
that sounds?

I suspect this code will not be a hot path in any conceivable "kill off hundreds of containers" benchmark, since the overhead of having all of the tasks in those containers exit will dwarf any changes in this code.

Simply making it safe for fully preemptible kernels by adding rcu_read_lock() around the section is what matters the most.

The choice between idr_for_each_entry_continue() and idr_for_each() is dictated more by which of the two results in easier to read code.

Signature · 1 line
All rights reversed
#7 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 61 lines · Rik van Riel
Quoted 49 lines · Gargi Sharma
Quoted 28 lines · Oleg Nesterov
Quoted 18 lines · Andrew Morton
Quoted 18 lines
kernel/pid_namespace.c +3 -6
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct
 pid_namespace *pid_ns)
     *
     */
    read_lock(&tasklist_lock);
-   nr = next_pidmap(pid_ns, 1);
-   while (nr > 0) {
-           rcu_read_lock();
-
-           task = pid_task(find_vpid(nr), PIDTYPE_PID);
+   nr = 2;
+   idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+           task = pid_task(pid, PIDTYPE_PID);
            if (task && !__fatal_signal_pending(task))
                    send_sig_info(SIGKILL, SEND_SIG_FORCED,
 task);
-
Quoted 8 lines
Quoted 5 lines
kernel/pid_namespace.c +0 -3
-           rcu_read_unlock();
-
-           nr = next_pidmap(pid_ns, nr);
    }
    read_unlock(&tasklist_lock);

Especially here. I don't think pidmap_lock is held. Is that IDR iteration safe?

Quoted 5 lines

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

Ah, I missed this. From what I understood idr_for_each_entry_continue should be safe because calls idr_get_next which in turn calls radix_tree_iter_find to find the next populated entry in the idr. If the pid that you are looking up the task for is deleted, task will get
a NULL from pid_task and no signal to kill will be sent.

Quoted 6 lines

Gargi, I suggested to use idr_for_each_entry_continue(), but now I am wondering
if we should use idr_for_each() instead. IIUC this would be a bit faster? Not
that I think this is really important...

Quoted 4 lines

I can run benchmarks with idr_for_each to see how much speed up is achieved and then we can go with whatever we think is better. How does
that sounds?

I suspect this code will not be a hot path in any conceivable "kill off hundreds of containers" benchmark, since the overhead of having all of the tasks in those containers exit will dwarf any changes in this code.

Quoted 7 lines

Simply making it safe for fully preemptible kernels by adding rcu_read_lock() around the section is what matters the most.

The choice between idr_for_each_entry_continue() and idr_for_each() is dictated more by which of the two results in easier to read code.

I have listed down the code for both idr_for_each and idr_for_each_entry. IMHO idr_for_each_entry is easier to read, but YMMV. :)

void kill_task(int id, void *ptr, void *data)

{
    struct *pid = ptr;
    struct task_struct *task = pid_task(pid, PIDTYPE_PID);
    if (task && !__fatal_signal_pending(task))
         send_sig_info(SIGKILL, SEND_SIG_FORCED, task);
}

rcu_read_unlock();
idr_for_each(&pid_ns->idr, &kill_task, NULL);
rcu_read_unlock();

VS

idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
          task = pid_task(pid, PIDTYPE_PID);
          if (task && !__fatal_signal_pending(task))
              send_sig_info(SIGKILL, SEND_SIG_FORCED, task);
}

Thanks!
Gargi

Quoted 3 lines

--
All rights reversed

#8 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

Quoted 13 lines · Gargi Sharma

I have listed down the code for both idr_for_each and idr_for_each_entry.
IMHO idr_for_each_entry is easier to read, but YMMV. :)

void kill_task(int id, void *ptr, void *data)
{
    struct *pid = ptr;
    struct task_struct *task = pid_task(pid, PIDTYPE_PID); if (task && !__fatal_signal_pending(task)) send_sig_info(SIGKILL, SEND_SIG_FORCED, task); }

Quoted 3 lines

rcu_read_unlock();
idr_for_each(&pid_ns->idr, &kill_task, NULL);
rcu_read_unlock();

It also looks like idr_for_each has no easy
way to skip over PID 1, like you can do with
idr_for_each_entry_continue().

I agree with you, the code below is easier to
read than the code above.

Quoted 13 lines

idr_for_each_entry_continue(&pid_ns->idr, pid, nr) { task = pid_task(pid, PIDTYPE_PID);
          if (task && !__fatal_signal_pending(task)) send_sig_info(SIGKILL, SEND_SIG_FORCED, task); }

Thanks!
Gargi

Quoted 3 lines

--
All rights reversed

Signature · 1 line
All rights reversed
#9 lore raw

Re: [PATCH v4 1/2] pid: Replace pid bitmap implementation with IDR API

In reply to Oleg Nesterov
Quoted 28 lines · Oleg Nesterov
Quoted 18 lines · Andrew Morton
Quoted 18 lines
kernel/pid_namespace.c +3 -6
@@ -240,17 +230,11 @@ void zap_pid_ns_processes(struct
 pid_namespace *pid_ns)
  	 *
  	 */
  	read_lock(&tasklist_lock);
-	nr = next_pidmap(pid_ns, 1);
-	while (nr > 0) {
-		rcu_read_lock();
-
-		task = pid_task(find_vpid(nr), PIDTYPE_PID);
+	nr = 2;
+	idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
+		task = pid_task(pid, PIDTYPE_PID);
  		if (task && !__fatal_signal_pending(task))
  			send_sig_info(SIGKILL, SEND_SIG_FORCED,
 task);
-
Quoted 8 lines
Quoted 5 lines
kernel/pid_namespace.c +0 -3
-		rcu_read_unlock();
-
-		nr = next_pidmap(pid_ns, nr);
  	}

  read_unlock(&tasklist_lock);

Especially here.  I don't think pidmap_lock is held.  Is that IDR iteration safe?

Quoted 4 lines

Yes, this doesn't look right, we need rcu_read_lock() or pidmap_lock.

And, we also need rcu_read_lock() for another reason, to protect "struct pid".

I think rcu_read_lock alone should do the trick, for both.

The IDR code specifically says that lookups are safe under just the rcu_read_lock, and that only insertions and deletions need a separate lock for synchronization.

Good catch.

Signature · 1 line
All Rights Reversed.
#10 lore raw

PATCH v4 2/2 pid: Remove pidhash

In reply to Gargi Sharma

pidhash is no longer required as all the information can be looked up from idr tree. nr_hashed represented the number of pids that had been hashed. Since, nr_hashed and PIDNS_HASH_ADDING are no longer relevant, it has been renamed to pid_allocated and PIDNS_ADDING respectively.

---
 include/linux/init_task.h     |  1 -
 include/linux/pid.h           |  2 --
 include/linux/pid_namespace.h |  4 ++--
 init/main.c                   |  1 -
 kernel/fork.c                 |  2 +-
 kernel/pid.c                  | 48 +++++++++----------------------------------
 kernel/pid_namespace.c        |  6 +++---
 7 files changed, 16 insertions(+), 48 deletions(-)
include/linux/init_task.h +0 -1
index 3c07ace..cc45798 100644
@@ -104,7 +104,6 @@ extern struct group_info init_groups;
 	.numbers	= { {						\
 		.nr		= 0,					\
 		.ns		= &init_pid_ns,				\
-		.pid_chain	= { .next = NULL, .pprev = NULL },	\
 	}, }								\
 }
 
include/linux/pid.h +0 -2
index 7195827..3915664 100644
@@ -50,10 +50,8 @@ enum pid_type
  */
 
 struct upid {
-	/* Try to keep pid_chain in the same cacheline as nr for find_vpid */
 	int nr;
 	struct pid_namespace *ns;
-	struct hlist_node pid_chain;
 };
 
 struct pid
include/linux/pid_namespace.h +2 -2
index f4db4a7..7911b58 100644
@@ -24,7 +24,7 @@ struct pid_namespace {
 	struct kref kref;
 	struct idr idr;
 	struct rcu_head rcu;
-	unsigned int nr_hashed;
+	unsigned int pid_allocated;
 	struct task_struct *child_reaper;
 	struct kmem_cache *pid_cachep;
 	unsigned int level;
@@ -48,7 +48,7 @@ struct pid_namespace {
 
 extern struct pid_namespace init_pid_ns;
 
-#define PIDNS_HASH_ADDING (1U << 31)
+#define PIDNS_ADDING (1U << 31)
 
 #ifdef CONFIG_PID_NS
 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
init/main.c +0 -1
index 9f4db20..c17a21b 100644
@@ -562,7 +562,6 @@ asmlinkage __visible void __init start_kernel(void)
 	 * kmem_cache_init()
 	 */
 	setup_log_buf(0);
-	pidhash_init();
 	vfs_caches_init_early();
 	sort_main_extable();
 	trap_init();
kernel/fork.c +1 -1
index 1064618..c3518b8 100644
@@ -1853,7 +1853,7 @@ static __latent_entropy struct task_struct *copy_process(
 		retval = -ERESTARTNOINTR;
 		goto bad_fork_cancel_cgroup;
 	}
-	if (unlikely(!(ns_of_pid(pid)->nr_hashed & PIDNS_HASH_ADDING))) {
+	if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) {
 		retval = -ENOMEM;
 		goto bad_fork_cancel_cgroup;
 	}
kernel/pid.c +10 -38

116 lines not on this page · raw message

kernel/pid_namespace.c +3 -3
index 596f90a..14844e8 100644
@@ -133,7 +133,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
 	ns->parent = get_pid_ns(parent_pid_ns);
 	ns->user_ns = get_user_ns(user_ns);
 	ns->ucounts = ucounts;
-	ns->nr_hashed = PIDNS_HASH_ADDING;
+	ns->pid_allocated = PIDNS_ADDING;
 	INIT_WORK(&ns->proc_work, proc_cleanup_work);
 
 	return ns;
@@ -252,7 +252,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 	 * sys_wait4() above can't reap the EXIT_DEAD children but we do not
 	 * really care, we could reparent them to the global init. We could
 	 * exit and reap ->child_reaper even if it is not the last thread in
-	 * this pid_ns, free_pid(nr_hashed == 0) calls proc_cleanup_work(),
+	 * this pid_ns, free_pid(pid_allocated == 0) calls proc_cleanup_work(),
 	 * pid_ns can not go away until proc_kill_sb() drops the reference.
 	 *
 	 * But this ns can also have other tasks injected by setns()+fork().
@@ -266,7 +266,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 	 */
 	for (;;) {
 		set_current_state(TASK_INTERRUPTIBLE);
-		if (pid_ns->nr_hashed == init_pids)
+		if (pid_ns->pid_allocated == init_pids)
 			break;
 		schedule();
 	}
Signature · 1 line
2.7.4
#11 lore raw

Re: [PATCH v4 2/2] pid: Remove pidhash

url: https://github.com/0day-ci/linux/commits/Gargi-Sharma/pid-Replace-pid-bitmap-implementation-with-IDR-API/20171011-165615 config: ia64-allyesconfig (attached as .config) compiler: ia64-linux-gcc…

Hi Gargi,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.14-rc4]
[cannot apply to next-20171009]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Gargi-Sharma/pid-Replace-pid-bitmap-implementation-with-IDR-API/20171011-165615
config: ia64-allyesconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64

All error/warnings (new ones prefixed by >>):

warning: (INTEL_SOC_PMIC && INTEL_SOC_PMIC_CHTWC && MFD_TPS68470) selects I2C_DESIGNWARE_PLATFORM which has unmet direct dependencies (I2C && HAS_IOMEM && (ACPI && COMMON_CLK || !ACPI))
warning: (DW_APB_TIMER_OF && ROCKCHIP_TIMER && ARMADA_370_XP_TIMER && ORION_TIMER && CLKSRC_TI_32K && CLKSRC_NPS && CLKSRC_MPS2 && ARM_ARCH_TIMER && ARM_GLOBAL_TIMER && ARM_TIMER_SP804 && ARMV7M_SYSTICK && ATMEL_PIT && CLKSRC_QCOM && CLKSRC_VERSATILE && CLKSRC_MIPS_GIC && CLKSRC_TANGO_XTAL && CLKSRC_ST_LPC) selects TIMER_OF which has unmet direct dependencies (!ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS)
warning: (FAULT_INJECTION_STACKTRACE_FILTER && LATENCYTOP && KMEMCHECK && LOCKDEP) selects FRAME_POINTER which has unmet direct dependencies (DEBUG_KERNEL && (CRIS || M68K || FRV || UML || SUPERH || BLACKFIN || MN10300 || METAG) || ARCH_WANT_FRAME_POINTERS)
warning: (INTEL_SOC_PMIC && INTEL_SOC_PMIC_CHTWC && MFD_TPS68470) selects I2C_DESIGNWARE_PLATFORM which has unmet direct dependencies (I2C && HAS_IOMEM && (ACPI && COMMON_CLK || !ACPI))
warning: (DW_APB_TIMER_OF && ROCKCHIP_TIMER && ARMADA_370_XP_TIMER && ORION_TIMER && CLKSRC_TI_32K && CLKSRC_NPS && CLKSRC_MPS2 && ARM_ARCH_TIMER && ARM_GLOBAL_TIMER && ARM_TIMER_SP804 && ARMV7M_SYSTICK && ATMEL_PIT && CLKSRC_QCOM && CLKSRC_VERSATILE && CLKSRC_MIPS_GIC && CLKSRC_TANGO_XTAL && CLKSRC_ST_LPC) selects TIMER_OF which has unmet direct dependencies (!ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS)
warning: (FAULT_INJECTION_STACKTRACE_FILTER && LATENCYTOP && KMEMCHECK && LOCKDEP) selects FRAME_POINTER which has unmet direct dependencies (DEBUG_KERNEL && (CRIS || M68K || FRV || UML || SUPERH || BLACKFIN || MN10300 || METAG) || ARCH_WANT_FRAME_POINTERS)
In file included from include/uapi/linux/stddef.h:1:0,

                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/rculist.h:9,
                    from include/linux/sched/signal.h:4,
                    from arch/ia64/kernel/asm-offsets.c:9:
   arch/ia64/kernel/asm-offsets.c: In function 'foo':
>> include/linux/compiler.h:576:38: error: call to '__compiletime_assert_33' declared with attribute error: BUILD_BUG_ON failed: sizeof(struct upid) != 32
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                         ^
   include/linux/compiler.h:556:4: note: in definition of macro '__compiletime_assert'
       prefix ## suffix();    \
       ^~~~~~
   include/linux/compiler.h:576:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:46:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:70:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^~~~~~~~~~~~~~~~
>> arch/ia64/kernel/asm-offsets.c:33:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(struct upid) != 32);
     ^~~~~~~~~~~~

make[2]: *** [arch/ia64/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [sub-make] Error 2

vim +/__compiletime_assert_33 +576 include/linux/compiler.h

9a8ab1c3 Daniel Santos 2013-02-21  562  
9a8ab1c3 Daniel Santos 2013-02-21  563  #define _compiletime_assert(condition, msg, prefix, suffix) \
9a8ab1c3 Daniel Santos 2013-02-21  564  	__compiletime_assert(condition, msg, prefix, suffix)
9a8ab1c3 Daniel Santos 2013-02-21  565  
9a8ab1c3 Daniel Santos 2013-02-21  566  /**
9a8ab1c3 Daniel Santos 2013-02-21  567   * compiletime_assert - break build and emit msg if condition is false
9a8ab1c3 Daniel Santos 2013-02-21  568   * @condition: a compile-time constant condition to check
9a8ab1c3 Daniel Santos 2013-02-21  569   * @msg:       a message to emit if condition is false
9a8ab1c3 Daniel Santos 2013-02-21  570   *
9a8ab1c3 Daniel Santos 2013-02-21  571   * In tradition of POSIX assert, this macro will break the build if the
9a8ab1c3 Daniel Santos 2013-02-21  572   * supplied condition is *false*, emitting the supplied error message if the
9a8ab1c3 Daniel Santos 2013-02-21  573   * compiler has support to do so.
9a8ab1c3 Daniel Santos 2013-02-21  574   */
9a8ab1c3 Daniel Santos 2013-02-21  575  #define compiletime_assert(condition, msg) \

9a8ab1c3 Daniel Santos 2013-02-21 @576 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
9a8ab1c3 Daniel Santos 2013-02-21 577

:::::: The code at line 576 was first introduced by commit
:::::: 9a8ab1c39970a4938a72d94e6fd13be88a797590 bug.h, compiler.h: introduce compiletime_assert & BUILD_BUG_ON_MSG

:::::: TO: Daniel Santos <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#12 lore raw

Re: [PATCH v4 2/2] pid: Remove pidhash

Quoted 24 lines · kbuild test robot
Quoted 2 lines
Quoted 2 lines

'__compiletime_assert_33' declared with attribute error:
BUILD_BUG_ON failed: sizeof(struct upid) != 32

     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                         ^ include/linux/compiler.h:556:4: note: in definition of macro '__compiletime_assert'
       prefix ## suffix();    \
       ^~~~~~
   include/linux/compiler.h:576:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:46:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:70:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^~~~~~~~~~~~~~~~

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

arch/ia64/kernel/asm-offsets.c:33:2: note: in expansion of macro 'BUILD_BUG_ON'

     BUILD_BUG_ON(sizeof(struct upid) != 32);
     ^~~~~~~~~~~~

Looks like arch/ia64/kernel/asm-offsets.c throws a BUILD_BUG if sizeof(struct upid) != 32.

Your patch reduced the size of struct upid, which is a nice thing, but now IA64 no longer builds.

Lets see what IA64 was doing with the size of struct upid in the first place:

in arch/ia64/kernel/asm-offsets.c:

        BUILD_BUG_ON(sizeof(struct upid) != 32);
        DEFINE(IA64_UPID_SHIFT, 5);

Grepping for IA64_UPID_SHIFT leads us to some assembly code implementing fsys_getpid (why is that in assembly?!):

        add r8=IA64_PID_LEVEL_OFFSET,r17
        ;;
        ld4 r8=[r8]                             // r8 = pid->level
        add r17=IA64_PID_UPID_OFFSET,r17        // r17 = &pid->numbers[0]
        ;;
        shl r8=r8,IA64_UPID_SHIFT
        ;;
        add r17=r17,r8                          // r17 = &pid->numbers[pid->level]
        ;;
        ld4 r8=[r17]                            // r8 = pid->numbers[pid->level].nr
        ;;
        mov r17=0

Luckily it looks like this is only referencing the first members of struct upid, and you are removing the last member, so I suspect you will be fine changing the IA64 to this:

        BUILD_BUG_ON(sizeof(struct upid) != 16);
        DEFINE(IA64_UPID_SHIFT, 4);

Tony, does that look ok to you?

Signature · 1 line
All Rights Reversed.
#13 lore raw

RE: [PATCH v4 2/2] pid: Remove pidhash

PsKgwqDCoMKgwqDCoMKgwqBERUZJTkUoSUE2NF9VUElEX1NISUZULCA1KTsNCj4NCj4gR3JlcHBp bmcgZm9yIElBNjRfVVBJRF9TSElGVCBsZWFkcyB1cyB0byBzb21lIGFzc2VtYmx5DQo+IGNvZGUg aW1wbGVtZW50aW5nIGZzeXNfZ2V0cGlkICh3aHkgaXMgdGhhdCBpbiBhc3NlbWJseT8hKToNCg0K VGhlIGZhc3Qgc3lzdGVtIGNhbGwgcGF0aCBoYXMgYSB3aG9sZSBob3N0IG9mIHNlcmlvdXMgcmVz dHJpY3Rpb25zIG9uIHdoYXQgaXQgY2FuDQp0b3VjaC4gU2VlIERvY3VtZW50YXRpb24vaWE2NC9m c3lzLnR4dC4gIFdoeSBpcyBnZXRwaWQoKSBhIGZhc3Qgc3lzdGVtIGNhbGw/IEkgdGhpbmsNCnRo ZXJlIHdhcyBzb21lIGFwcGxpY2F0aW9uIChvciBwZXJoYXBzIGJlbmNobWFyaykgdGhhdCB1c2Vk IGl0IGEgbG90Lg0KDQo+ICAgICAgICBhZGQgcjg9SUE2NF9QSURfTEVWRUxfT0ZGU0VULHIxNw0K PiAgICAgICAgOzsNCj4gICAgICAgIGxkNCByOD1bcjhdICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAvLyByOCA9IHBpZC0+bGV2ZWwNCj4gICAgICAgIGFkZCByMTc9SUE2NF9QSURfVVBJRF9P RkZTRVQscjE3ICAgICAgICAvLyByMTcgPSAmcGlkLT5udW1iZXJzWzBdDQo+ICAgICAgICA7Ow0K PiAgICAgICAgc2hsIHI4PXI4LElBNjRfVVBJRF9TSElGVA0KPiAgICAgICAgOzsNCj4gICAgICAg IGFkZCByMTc9cjE3LHI4ICAgICAgICAgICAgICAgICAgICAgICAgICAvLyByMTcgPSAmcGlkLT5u dW1iZXJzW3BpZC0+bGV2ZWxdDQo+ICAgICAgICA7Ow0KPiAgICAgICAgbGQ0IHI4PVtyMTddICAg ICAgICAgICAgICAgICAgICAgICAgICAgIC8vIHI4ID0gcGlkLT5udW1iZXJzW3BpZC0+bGV2ZWxd Lm5yDQo+ICAgICAgICA7Ow0KPiAgICAgICAgbW92IHIxNz0wDQo+DQo+IEx1Y2tpbHkgaXQgbG9v a3MgbGlrZSB0aGlzIGlzIG9ubHkgcmVmZXJlbmNpbmcgdGhlIGZpcnN0IG1lbWJlcnMgb2Ygc3Ry dWN0IHVwaWQsDQo+IGFuZCB5b3UgYXJlIHJlbW92aW5nIHRoZSBsYXN0IG1lbWJlciwgc28gSSBz dXNwZWN0IHlvdSB3aWxsIGJlIGZpbmUgY2hhbmdpbmcgdGhlIElBNjQNCj4gdG8gdGhpczoNCj4N Cj7CoMKgwqDCoMKgwqDCoMKgQlVJTERfQlVHX09OKHNpemVvZihzdHJ1Y3QgdXBpZCkgIT0gMTYp Ow0KPsKgwqDCoMKgwqDCoMKgwqBERUZJTkUoSUE2NF9VUElEX1NISUZULCA0KTsNCj4NCj4gVG9u eSwgZG9lcyB0aGF0IGxvb2sgb2sgdG8geW91Pw0KDQpJIHRoaW5rIHNvLiAgUmVzcGluIGFuZCBD YzogbWUgb24gYm90aCBwYXRjaGVzIGluIHRoZSBzZXJpZXMgYW5kIEknbGwgdGFrZSBpdCBmb3Ig YSBzcGluDQpvbiBoL3cgdG8gbWFrZSBzdXJlLg0KDQotVG9ueQ0K