Skip to contentSkip to conversation

pid: remove unnecessary idr_preload()

PATCH In review Tycho Andersen 3 participants 6 messages Dec 15, 2025 – Dec 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pid: remove unnecessary idr_preload()

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

I boot tested this and built a kernel on a $large core system, so hopefully that would have caught any errors.

---
 kernel/pid.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/pid.c +0 -3
index a31771bc89c1..b0fefeb0a1ec 100644
@@ -270,7 +270,6 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 	INIT_HLIST_HEAD(&pid->inodes);
 
 	upid = pid->numbers + ns->level;
-	idr_preload(GFP_KERNEL);
 	spin_lock(&pidmap_lock);
 	if (!(ns->pid_allocated & PIDNS_ADDING))
 		goto out_unlock;
@@ -281,14 +280,12 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 		upid->ns->pid_allocated++;
 	}
 	spin_unlock(&pidmap_lock);
-	idr_preload_end();
 	ns_ref_active_get(ns);
 
 	return pid;
 
 out_unlock:
 	spin_unlock(&pidmap_lock);
-	idr_preload_end();
 	put_pid_ns(ns);
 
 out_free:

base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8

Signature · 1 line
2.52.0
#1 lore raw
Quoted 6 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

Yes. The extra idr_preload() was needed for pidfs_add_pid() after the commit 9698d5a483654 ("pidfs: rework inode number allocation").

But please see
[PATCH v3 2/2] pid: only take pidmap_lock once on alloc
https://lore.kernel.org/all/[email protected]/

This patch removes the unnecessary idr_preload() too.

Oleg.

#2 lore raw
Quoted 8 lines · Oleg Nesterov
Quoted 6 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

Quoted 6 lines

Yes. The extra idr_preload() was needed for pidfs_add_pid() after the commit 9698d5a483654 ("pidfs: rework inode number allocation").

But please see
[PATCH v3 2/2] pid: only take pidmap_lock once on alloc
https://lore.kernel.org/all/[email protected]/

Oh, nice. I was looking at doing this too. I'll head over to that thread...

Tycho

#3 lore raw
In reply to Tycho Andersen
Quoted 6 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

Yes. The extra idr_preload() was needed for pidfs_add_pid() after the commit 9698d5a483654 ("pidfs: rework inode number allocation").

But please see
[PATCH v3 2/2] pid: only take pidmap_lock once on alloc
https://lore.kernel.org/all/[email protected]/

This patch removes the unnecessary idr_preload() too.

Oleg.

#4 lore raw
Quoted 9 lines · Oleg Nesterov
Quoted 6 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

Quoted 9 lines

Yes. The extra idr_preload() was needed for pidfs_add_pid() after the commit 9698d5a483654 ("pidfs: rework inode number allocation").

But please see
[PATCH v3 2/2] pid: only take pidmap_lock once on alloc
https://lore.kernel.org/all/[email protected]/

This patch removes the unnecessary idr_preload() too.

The patch can be trivially rebased on top of this one (actual rebase would be cumbersome; instead one can cp kernel/fork.c kernel/fork.c-tmp, apply this patch on top of stock file, mv kernel/fork.c-tmp kernel/fork.c and commit resulting diff).

However, unless someone is looking to put this into stable branches or similar, I think the dance can be skipped at no loss for future generations.

#5 lore raw
Quoted 20 lines · Mateusz Guzik
Quoted 9 lines · Oleg Nesterov
Quoted 6 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

As near as I can tell, nothing in the second pidmap_lock critical section actually allocates an id, so there is no need to do idr_preload(). idr_replace() does not, nor does pidfs_add_pid().

Quoted 9 lines

Yes. The extra idr_preload() was needed for pidfs_add_pid() after the commit 9698d5a483654 ("pidfs: rework inode number allocation").

But please see
[PATCH v3 2/2] pid: only take pidmap_lock once on alloc
https://lore.kernel.org/all/[email protected]/

This patch removes the unnecessary idr_preload() too.

Quoted 8 lines

The patch can be trivially rebased on top of this one (actual rebase would be cumbersome; instead one can cp kernel/fork.c kernel/fork.c-tmp, apply this patch on top of stock file, mv kernel/fork.c-tmp kernel/fork.c and commit resulting diff).

However, unless someone is looking to put this into stable branches or similar, I think the dance can be skipped at no loss for future generations.

Yeah, agreed. I think let's just take yours. I'll test it now.

Tycho