Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6076011rwb; Sun, 11 Dec 2022 18:36:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Wv8A0jL8D3PiLVhuN+r2xNV0rEGi9722i6PlIh4BlrPnhYS3Uk1Fks4Ld+XG7USNYiKS/ X-Received: by 2002:a05:6a20:d492:b0:a5:df86:f2c3 with SMTP id im18-20020a056a20d49200b000a5df86f2c3mr17545016pzb.32.1670812583576; Sun, 11 Dec 2022 18:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670812583; cv=none; d=google.com; s=arc-20160816; b=mjISVq0R/9fJEkdGbbY62iAyBiLESjmTev4VzgB29deIDSofwyYUvF09kkqx/GSmSK alAnFXpjfiQJONVLEEoEEhJ2bF2DDBXr7Zp7jNjnwKuEJU36NQzeu2yZ+h+RSG9Awa7H 8HAUUH22fCL3e0Z9jPMSOHo9QEnjSDi7XE/CyZPk3LeVufWZLemTe9FsKB0iI02gYBZW dRfod6o5KGTtEgjumT2/nlxqUwZ7tb6JE+5CuG7xMsCTqJuNY5QS+2Ea+LDvYhrzAHXQ jqpRLGfdZk/F7+X1rssuuW06i2S5bQgbwhXVgNRcQOTIBphvGZ5jD2sltKzurRUzUlDG DBww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=hZR9z6VBNznO4iAg8I+edvN08p/s9GeIUmTOh/2RVqg=; b=Ep7T4+MzI6YuPMybeCN+rddCmmDZm1/8oUyY1KqRPU7CpeX4jGGcmjy/fi1Kr2eohH F1YEuvuarWqS7QBYq2VZDbHVJjbeOaYv+6/MISSVPJDWcw1u5jgndN1dlvAxYh5u3d3V JuKgqIltwQX7YYgYaXd1D7F1KSIRr5bWSGNOeq5+wdQBFXeHPeRGawPkUOv1NyKKu/bu R7bVSylq214hDUrln8HiByJYCsheZ7N4PjBKVdAHBX/xkjxZYNcL3ti8OwHmJ2Gqgta3 UT2rT5lNGv0WYNEHWnWrwBo7EpyjsuL6DiuhDaRJpXflZkz5KEyOJa5bYBQmy3wd//pD nGxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PwV3fJJe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z24-20020a63d018000000b004779bfce4ccsi7805201pgf.452.2022.12.11.18.36.14; Sun, 11 Dec 2022 18:36:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PwV3fJJe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbiLLBqr (ORCPT + 75 others); Sun, 11 Dec 2022 20:46:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiLLBqp (ORCPT ); Sun, 11 Dec 2022 20:46:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69D6D2D4 for ; Sun, 11 Dec 2022 17:45:51 -0800 (PST) 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-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-264-SB8zBHw0NqGsFH7LVXLvag-1; Sun, 11 Dec 2022 20:45:49 -0500 X-MC-Unique: SB8zBHw0NqGsFH7LVXLvag-1 Received: by mail-pl1-f199.google.com with SMTP id z10-20020a170902ccca00b001898329db72so9286966ple.21 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=fGukJIB/Va1z1QY9yJP01AD7WAWAfJedmc8Rei52A94AdQN6XIFWj7JoNUZNJ4sVjN NWdkoaejsXD7k3H6za0JsTN4rSIGSzCsqTZRO60WOI7E/5t8CRGvCXGJidFV1zHY6O6m jvo0XpBGrMBYbLxZ1CZr+Hzjl5JwOLpnIUnglcmOVdaQc1am93IjsRl0lF+HofsMmieb JIhtrSFTslxSMQgoGKoPuMa6Fb566ycKNhTlEBWlrPrqztinED5et150cIH8F+Q+v9qO sNWezBLRU1W1YSF5WXbc8/MY60rf2aidOEa9HKRPHhL2mch4pC3pwdn9y8uv4CcM73tC BO8w== X-Gm-Message-State: ANoB5pliIppaR/yb6ZwZLyLET35f/82avhOee6VRcNBWVrKqSvT3hVfD PYe7qAsR5FR5/VsyfStXwoeBJWQLNoFh+FTEYs5m0TrperUdrCZ0NrGppw61dlDjizziAvowuPY IK9SCoTVnmWHZ70yZQ1nizeLy X-Received: by 2002:a17:90b:4f47:b0:20d:bd60:c30f with SMTP id pj7-20020a17090b4f4700b0020dbd60c30fmr14546074pjb.12.1670809548165; Sun, 11 Dec 2022 17:45:48 -0800 (PST) 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 Content-Language: en-US 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> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > }