From: Ian Kent <ikent@redhat.com>
To: Brian Foster <bfoster@redhat.com>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: onestero@redhat.com, willy@infradead.org, ebiederm@redhat.com
Subject: Re: [PATCH v3 2/5] pid: split cyclic id allocation cursor from idr
Date: Mon, 12 Dec 2022 09:45:41 +0800 [thread overview]
Message-ID: <39fb293c-cb9d-0a57-e2d7-2b2776247c94@redhat.com> (raw)
In-Reply-To: <20221202171620.509140-3-bfoster@redhat.com>
On 3/12/22 01:16, Brian Foster wrote:
> As a next step in separating pid allocation from the idr, split off
> the cyclic pid allocation cursor from the idr. Lift the cursor value
> into the struct pid_namespace. Note that this involves temporarily
> open-coding the cursor increment on allocation, but this is cleaned
> up in the subsequent patch.
>
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Ian Kent <raven@themaw.net>
> ---
> arch/powerpc/platforms/cell/spufs/sched.c | 2 +-
> fs/proc/loadavg.c | 2 +-
> include/linux/pid_namespace.h | 1 +
> kernel/pid.c | 6 ++++--
> kernel/pid_namespace.c | 4 ++--
> 5 files changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
> index 99bd027a7f7c..a2ed928d7658 100644
> --- a/arch/powerpc/platforms/cell/spufs/sched.c
> +++ b/arch/powerpc/platforms/cell/spufs/sched.c
> @@ -1072,7 +1072,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),
> - idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
> + READ_ONCE(task_active_pid_ns(current)->pid_next) - 1);
> return 0;
> }
> #endif
> diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c
> index 817981e57223..2740b31b6461 100644
> --- a/fs/proc/loadavg.c
> +++ b/fs/proc/loadavg.c
> @@ -22,7 +22,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,
> - idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
> + READ_ONCE(task_active_pid_ns(current)->pid_next) - 1);
> return 0;
> }
>
> diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
> index 07481bb87d4e..82c72482019d 100644
> --- a/include/linux/pid_namespace.h
> +++ b/include/linux/pid_namespace.h
> @@ -18,6 +18,7 @@ struct fs_pin;
>
> struct pid_namespace {
> struct idr idr;
> + unsigned int pid_next;
> struct rcu_head rcu;
> unsigned int pid_allocated;
> struct task_struct *child_reaper;
> diff --git a/kernel/pid.c b/kernel/pid.c
> index 3622f8b13143..2e2d33273c8e 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -75,6 +75,7 @@ int pid_max_max = PID_MAX_LIMIT;
> struct pid_namespace init_pid_ns = {
> .ns.count = REFCOUNT_INIT(2),
> .idr = IDR_INIT(init_pid_ns.idr),
> + .pid_next = 0,
> .pid_allocated = PIDNS_ADDING,
> .level = 0,
> .child_reaper = &init_task,
> @@ -208,7 +209,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
> * init really needs pid 1, but after reaching the
> * maximum wrap back to RESERVED_PIDS
> */
> - if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS)
> + if (tmp->pid_next > RESERVED_PIDS)
> pid_min = RESERVED_PIDS;
>
> /*
> @@ -217,6 +218,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
> */
> nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min,
> pid_max, GFP_ATOMIC);
> + tmp->pid_next = nr + 1;
> }
> xa_unlock_irq(&tmp->idr.idr_rt);
> idr_preload_end();
> @@ -278,7 +280,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
>
> /* On failure to allocate the first pid, reset the state */
> if (tmp == ns && tmp->pid_allocated == PIDNS_ADDING)
> - idr_set_cursor(&ns->idr, 0);
> + ns->pid_next = 0;
>
> idr_remove(&tmp->idr, upid->nr);
> xa_unlock_irq(&tmp->idr.idr_rt);
> diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
> index f4f8cb0435b4..a53d20c5c85e 100644
> --- a/kernel/pid_namespace.c
> +++ b/kernel/pid_namespace.c
> @@ -272,12 +272,12 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
> * it should synchronize its usage with external means.
> */
>
> - next = idr_get_cursor(&pid_ns->idr) - 1;
> + next = READ_ONCE(pid_ns->pid_next) - 1;
>
> tmp.data = &next;
> ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
> if (!ret && write)
> - idr_set_cursor(&pid_ns->idr, next + 1);
> + WRITE_ONCE(pid_ns->pid_next, next + 1);
>
> return ret;
> }
next prev parent reply other threads:[~2022-12-12 1:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 17:16 [PATCH v3 0/5] proc: improve root readdir latency with many threads Brian Foster
2022-12-02 17:16 ` [PATCH v3 1/5] pid: replace pidmap_lock with xarray lock Brian Foster
2022-12-12 1:44 ` Ian Kent
2022-12-02 17:16 ` [PATCH v3 2/5] pid: split cyclic id allocation cursor from idr Brian Foster
2022-12-12 1:45 ` Ian Kent [this message]
2022-12-02 17:16 ` [PATCH v3 3/5] pid: switch pid_namespace from idr to xarray Brian Foster
2022-12-12 1:47 ` Ian Kent
2022-12-02 17:16 ` [PATCH v3 4/5] pid: mark pids associated with group leader tasks Brian Foster
2022-12-12 1:51 ` Ian Kent
2022-12-13 2:00 ` kernel test robot
2022-12-02 17:16 ` [PATCH v3 5/5] procfs: use efficient tgid pid search on root readdir Brian Foster
2022-12-12 1:58 ` Ian Kent
2022-12-12 2:05 ` [PATCH v3 0/5] proc: improve root readdir latency with many threads Ian Kent
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=39fb293c-cb9d-0a57-e2d7-2b2776247c94@redhat.com \
--to=ikent@redhat.com \
--cc=bfoster@redhat.com \
--cc=ebiederm@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=onestero@redhat.com \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).