From: Oleg Nesterov <oleg@redhat.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: brauner@kernel.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH 3/3] pid: only take pidmap_lock once on alloc
Date: Sun, 23 Nov 2025 21:09:55 +0100 [thread overview]
Message-ID: <aSNp-TDtv0ZoILJ3@redhat.com> (raw)
In-Reply-To: <20251123063054.3502938-4-mjguzik@gmail.com>
On 11/23, Mateusz Guzik wrote:
>
> This reduces contention on the lock during parallel clone/exit.
>
> It remains the primary bottleneck in such a case.
>
> While here tidy up the code.
Not sure I can review... But FWIW this patch looks good to me after the
very quick glance. I'll try to actually read it tomorrow.
But please find a couple of minor "can't resist" nits below.
> + for (tmp = ns, i = ns->level; i >= 0; i--) {
> + int tid = set_tid[ns->level - i];
>
> if (tid) {
> nr = idr_alloc(&tmp->idr, NULL, tid,
> @@ -235,10 +261,8 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
> * a partially initialized PID (see below).
> */
> nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min,
> - pid_max, GFP_ATOMIC);
> + pid_max[ns->level - i], GFP_ATOMIC);
> }
> - spin_unlock(&pidmap_lock);
> - idr_preload_end();
>
> if (nr < 0) {
> retval = (nr == -ENOSPC) ? -EAGAIN : nr;
So. With or without this patch we have
if (tid) {
nr = idr_alloc(...);
if (nr == -ENOSPC)
nr = -EEXIST;
} else {
nr = idr_alloc_cyclic(...);
}
if (nr < 0) {
retval = (nr == -ENOSPC) ? -EAGAIN : nr;
goto out_free;
}
and somehow this looks annoying to me... Perhaps it makes sense to make this
code more symmetric (and imo more readable) ?
if (tid) {
nr = idr_alloc(...);
if (nr == -ENOSPC)
nr = -EEXIST;
} else {
nr = idr_alloc_cyclic(...);
if (nr == -ENOSPC)
nr = -EAGAIN;
}
if (nr < 0)
retval = nr;
goto out_free;
}
> - idr_preload(GFP_KERNEL);
> - spin_lock(&pidmap_lock);
> - if (!(ns->pid_allocated & PIDNS_ADDING))
> - goto out_unlock;
> + if (unlikely(!(ns->pid_allocated & PIDNS_ADDING)))
> + goto out_free;
> pidfs_add_pid(pid);
> - for ( ; upid >= pid->numbers; --upid) {
> + for (upid = pid->numbers + ns->level; upid >= pid->numbers; --upid) {
> /* Make the PID visible to find_pid_ns. */
> idr_replace(&upid->ns->idr, pid, upid->nr);
> upid->ns->pid_allocated++;
So.. unless I am totally confused the current code has another
idr_preload + idr_preload_end around pidfs_add_pid().
AFAICS, this makes no sense, and your patch removes it. But perhaps this
deserves a note in the changelog or even a separate patch?
And another stupid question... I don't understand fs/pidfs.c, but it looks
a bit strange to me that pidfs_add_pid() is called before the
for (...)
idr_replace(...);
loop. I don't see any problem, but to me it would look a bit better to do
pidfs_add_pid(pid) when this pid is fully initialized...
Oleg.
next prev parent reply other threads:[~2025-11-23 20:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-23 6:30 [PATCH 0/3] further damage-control lack of clone scalability Mateusz Guzik
2025-11-23 6:30 ` [PATCH 1/3] idr: add idr_prealloc_many Mateusz Guzik
2025-11-23 6:30 ` [PATCH 2/3] ns: pad refcount Mateusz Guzik
2025-11-23 18:58 ` Oleg Nesterov
2025-11-23 19:47 ` Mateusz Guzik
2025-11-24 18:25 ` Oleg Nesterov
2025-11-23 6:30 ` [PATCH 3/3] pid: only take pidmap_lock once on alloc Mateusz Guzik
2025-11-23 20:09 ` Oleg Nesterov [this message]
2025-11-23 22:48 ` Mateusz Guzik
2025-11-23 15:00 ` [PATCH 0/3] further damage-control lack of clone scalability Matthew Wilcox
2025-11-23 16:39 ` Mateusz Guzik
2025-11-23 21:45 ` Matthew Wilcox
2025-11-23 22:33 ` Mateusz Guzik
2025-11-24 4:03 ` Mateusz Guzik
2025-12-03 8:37 ` Mateusz Guzik
2025-12-03 9:18 ` Mateusz Guzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSNp-TDtv0ZoILJ3@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mjguzik@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox