From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A60BC4332F for ; Mon, 12 Dec 2022 01:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4C8B8E0003; Sun, 11 Dec 2022 20:45:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CFB018E0002; Sun, 11 Dec 2022 20:45:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9BC08E0003; Sun, 11 Dec 2022 20:45:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AA48C8E0002 for ; Sun, 11 Dec 2022 20:45:53 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7856980890 for ; Mon, 12 Dec 2022 01:45:53 +0000 (UTC) X-FDA: 80231962986.19.C2EBDB5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 73F9D140003 for ; Mon, 12 Dec 2022 01:45:51 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PwV3fJJe; spf=pass (imf23.hostedemail.com: domain of ikent@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=ikent@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670809551; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hZR9z6VBNznO4iAg8I+edvN08p/s9GeIUmTOh/2RVqg=; b=auxXzJvjbkBz37CT0CddN6dXpBOQia4F1RbGILtcGwh8DhOk6WDfE9sA9u+ELRlfg+iwto OGqgsnp5VROISTLem+uG58J20+bmMWFmfNPC0DMdmIo9r2O1kpcO0vsnUDnSpWeEE7C9CC AzIfdedeqyahwnok2Tr1NQD2Rl+1YaE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PwV3fJJe; spf=pass (imf23.hostedemail.com: domain of ikent@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=ikent@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670809551; a=rsa-sha256; cv=none; b=Yzfiw+E+yuKUZcIRu5qZsBs2gTSKc9AudVmQ3qH31e1hlGJujbioJkYN4GzdsfBmnddBD+ hznfotiQDGKVrvtaX5v8Gmi8eZkbtUm0Hzc/z450rLWvt5PIVXXKuuzaZjEaYbe7C+2NFG tcEKooWgiMAcz8W39V0/LkrnjyXudV0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670809550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hZR9z6VBNznO4iAg8I+edvN08p/s9GeIUmTOh/2RVqg=; b=PwV3fJJemWNlnduYozwn3A8r593mtYbAM9eMNbvmS//hcKZyQoilkXOj1+AtKTW5WRRcUn TbuwdkrM94zSRmuzEn0sMEFCh46npnfztefGii01EbBBfrJxDn85U83ehbBX2aDJ3AoKjZ TV5PVFCUCFm4AQIsamPPB7u/aZLt7rQ= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-259-bj9IR2lPMuW83SsAnF81Ww-1; Sun, 11 Dec 2022 20:45:49 -0500 X-MC-Unique: bj9IR2lPMuW83SsAnF81Ww-1 Received: by mail-pl1-f198.google.com with SMTP id m16-20020a170902db1000b0018fa0de6aa6so217989plx.18 for ; Sun, 11 Dec 2022 17:45:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hZR9z6VBNznO4iAg8I+edvN08p/s9GeIUmTOh/2RVqg=; b=kxUIyKMSxKLKuQbL367GfICbA4z94qfBfXYC3FR0ZzrHM5pbv7r+X9iSc7QhbNPvfm n1qpZQy7Vf9o5NLwxd8Hsb3rBuBNMnow4VGUkolaOCDaTd9xg4mQiNktime/9j9r9Xf5 ApzU/Sy4iVkNhotToVIQX/NwqlYhYfsfyahRWQmwmJUczjtH/6TF7M3E/3HVE+ZSmdHL rce6fsDuaU12Try6k1J86NUBIJ07GUv2Oymj90FdTH8BqITqZOa4DRnCKS6sbd6bFHvc S6LsrPRrnfHwQXZhFc5+1mW1qQq6n+nzgsJIY1jbiPs40ID/X3ZQ9xN/I0JSdwn49VKA Dp8w== X-Gm-Message-State: ANoB5pk6J8dY5QTrxIXyGa//ulqspQ6ruRCMWKHDF1tFogqvZvnjMN/Q 6iVZD4lZpmcYfwdBRmPSLZMyHn7o1/EySnd5kazDu9eBu/1CnJzYjUrfKw1AoyGGFVgrufBK55K JNiTeWy4rVlY= X-Received: by 2002:a17:90b:4f47:b0:20d:bd60:c30f with SMTP id pj7-20020a17090b4f4700b0020dbd60c30fmr14546072pjb.12.1670809548164; Sun, 11 Dec 2022 17:45:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf69qw7rDQjgSoktCuOZ5HSA8jydQE9FOHmvd4604m+oC/JUHA9qmWlUHQlS6SclkYD+4niwkA== X-Received: by 2002:a17:90b:4f47:b0:20d:bd60:c30f with SMTP id pj7-20020a17090b4f4700b0020dbd60c30fmr14546049pjb.12.1670809547832; Sun, 11 Dec 2022 17:45:47 -0800 (PST) Received: from ?IPV6:2403:580e:4b40:0:7968:2232:4db8:a45e? (2403-580e-4b40--7968-2232-4db8-a45e.ip6.aussiebb.net. [2403:580e:4b40:0:7968:2232:4db8:a45e]) by smtp.gmail.com with ESMTPSA id 73-20020a63064c000000b0047915d582ccsm4033891pgg.20.2022.12.11.17.45.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Dec 2022 17:45:47 -0800 (PST) Message-ID: <39fb293c-cb9d-0a57-e2d7-2b2776247c94@redhat.com> Date: Mon, 12 Dec 2022 09:45:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v3 2/5] pid: split cyclic id allocation cursor from idr To: Brian Foster , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: onestero@redhat.com, willy@infradead.org, ebiederm@redhat.com References: <20221202171620.509140-1-bfoster@redhat.com> <20221202171620.509140-3-bfoster@redhat.com> From: Ian Kent In-Reply-To: <20221202171620.509140-3-bfoster@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 73F9D140003 X-Stat-Signature: br7d61t15gkikue53ewz4nrzgyta41pw X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1670809551-213217 X-HE-Meta: U2FsdGVkX18V0yWeWmRI/QjJAgWRgeOHD9VXcTK9xxgkec4F2/nv029ExZWpzZ044DZRPyiYx43LHFUVOlM6h6KTTKVemwlQlksEylBYtzVBQoel1NYbXFYCsZL0I6M9VNlakMlfWGLe7yj8kKxhcRej29jO7liLVw8NYzwE58sBDrerDYV9v8TTetDkL/+AFnnuPy1ZPsKX6ViHto5zuV5cmznBAR43C+qucMiZCDEjmvEPNXFEqmba8aLygUC2BrXMxLhO0wGWkIu390KhFyafV3Hot/aNFYgOtQHzcuasIYuBkGRN8LZEvRwl1dXPPyeejhcyKlFxz4V+gRO7jqFvQClEraSCrZMwIldOKltEyHs+gnoyfMfF2V33r5qzUj2xGg/mRpK1FBLQohnOXy569F8J7HBvX0KnljL6QCCoUMfUtFaQMOpj5TsfQ/gSXt/V4Ro++b+lPdCEreDw9Mtbm62NlL08g3uWWuzePcoFfmsrub3pJpLeFOHxVEKO0uoZiZ/QgZFITDbdj6t0c234Ys8cxH3Nf8Sb6yY0BeUnZDuSdslQx5NXqhdotJcMJ6FUhF0Fab7t77ThA4rG+qEWtByPyNhXTUfSQ36LmUX3hlq+a+jYFAP4Ao2CkXEkvuETGCn1MTrSRAXo99ZWaOcuyToLHHvr1e3jSewViTPrieyafJ/nEup/TAVSvT8hlC+gy0gBVl7M0kJbyoxduBSi17JRjUrw/Vk/NKnDGS2fgKtBO3XmXM1laK9hBxFcmJ5+4EhZUzAmmMYJxoWQpwYTopuNxM8lypozzPqX1FrupPeB+s7c5jubXpNE/SpN0nBlNSZSNSAk8XHb22lJ55BbG84TpYRZhGhGHUrN74kPZvO0HWtIjG42pNbev6DxOUfAUymvAzUOL9YcXDlFxRnJxjJQyGw490mH0AxVCgnfc+QyTvBB0X6JLSyBBD5lK969aKQOecJGkgkyrPK QBlJEn6z ZHcbzoRI6wl8BubAft1Z5qfyntgV76GCPX2vDWNO1EvxUbz2em9ZG4KWShq2UAmqb1HzTVxx6D3O4GcyJKkSW58552FQwztOJ2EztMv2U2OnQNQI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > Signed-off-by: Brian Foster Reviewed-by: Ian Kent > --- > 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; > }