Skip to content

Commit 7be6d99

Browse files
andre-rosatorvalds
authored andcommitted
pid: tighten pidmap spinlock critical section by removing kfree()
Avoid calling kfree() under pidmap spinlock, calling it afterwards. Normally kfree() is fast, but sometimes it can be slow, so avoid calling it under the spinlock if we can do it. Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 698ba7b commit 7be6d99

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎kernel/pid.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
141141
* installing it:
142142
*/
143143
spin_lock_irq(&pidmap_lock);
144-
if (map->page)
145-
kfree(page);
146-
else
144+
if (!map->page) {
147145
map->page = page;
146+
page = NULL;
147+
}
148148
spin_unlock_irq(&pidmap_lock);
149+
kfree(page);
149150
if (unlikely(!map->page))
150151
break;
151152
}

0 commit comments

Comments
 (0)