Message ID | 20230704113049.1019118-1-linmiaohe@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1165900vqx; Tue, 4 Jul 2023 05:03:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6RSxY0cR1cQML0Wpvli14xQZ3Bmc8OSzNYnMKx6IJ+uAmaQ6qnzeK0AYIaTMdOGRrLNpE X-Received: by 2002:a17:903:190:b0:1b8:9551:a705 with SMTP id z16-20020a170903019000b001b89551a705mr5081218plg.55.1688472198798; Tue, 04 Jul 2023 05:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688472198; cv=none; d=google.com; s=arc-20160816; b=H/cMXJRnX7/lwcwjx65BRhvB6bsdGdpgCvYPl6LRHg0VtiwM+ujmGHAN74QDPNw/OZ yTo166gDw3vU8VR0Z+krir8M1K/gxRlFTBiEZEUYchtuxGuvT4f7pU+Hb+VU2mFavxaQ jet2ZfvL0bv540z+mGbGlVdm6toYOwtosJWvOpjjIcUNXIxRw0WnpqipolWcUmjf2e8y Nh++QjatU+61DD4Mf3nA64tIhsiX3JLC9rPqBTxBzLutGV+3d/L31muWxodqGKARDCK0 FE5bhhVwzvxJO+UgAbl9KyNj42tDj1citUfa9NIxvOMeWkuSMlw1w18nV/kRB4AGmU2r dK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=DF/MEraCiriF2LWhe9I6HZq/LqcmAkRYd6ae06SPk1M=; fh=xm61FqaKFbVtJj3DZjMBwIjT3viqbFfn4Ws5hFHxOsg=; b=RSgWCTRorgWesiEEeQacYhhcnFix4mvuWaOHQN2KMrkTZlNao3EZ7Kk7tDtf5by8yW 282x9Xn8Wpx8pYb4BOATQ3k+MCqjGPLFMoJ9zszwWqmc/HZPE29rhvtS+FlxQTnXCiCb mU0+xwS3ko6iP/ke7yp8VZ3OBcU6emR6DLeZ0Rw8HXqgRifR4ksTkgQN+XBCCxBflWux iNV7f0LEpI8pcEhzK3BI0VQNDQB3+dC0Ltk0wm9Q5L7OWagwZpFVNXwkbd/FuPNMrqiK UMRgyaMzbqI7ZWdkUhRUwy+CoLgo6fFTZqUocrL4x46tD42iDWBMUXygTmIBj26TEGqC n1PA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a170902aa8d00b001b80dbd3913si15754023plr.625.2023.07.04.05.03.05; Tue, 04 Jul 2023 05:03:18 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbjGDLag (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Tue, 4 Jul 2023 07:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbjGDLae (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 4 Jul 2023 07:30:34 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930E4FB; Tue, 4 Jul 2023 04:30:33 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QwLDt12Xxz1HCsN; Tue, 4 Jul 2023 19:30:06 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 4 Jul 2023 19:30:29 +0800 From: Miaohe Lin <linmiaohe@huawei.com> To: <longman@redhat.com>, <tj@kernel.org>, <hannes@cmpxchg.org>, <lizefan.x@bytedance.com> CC: <cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linmiaohe@huawei.com> Subject: [PATCH] cgroup/cpuset: simplify the percpu kthreads check in update_tasks_cpumask() Date: Tue, 4 Jul 2023 19:30:49 +0800 Message-ID: <20230704113049.1019118-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770491424337109669?= X-GMAIL-MSGID: =?utf-8?q?1770491424337109669?= |
Series |
cgroup/cpuset: simplify the percpu kthreads check in update_tasks_cpumask()
|
|
Commit Message
Miaohe Lin
July 4, 2023, 11:30 a.m. UTC
kthread_is_per_cpu() can be called directly without checking whether
PF_KTHREAD is set in task->flags. So remove PF_KTHREAD check to make
code more concise.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
kernel/cgroup/cpuset.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 7/4/23 07:30, Miaohe Lin wrote: > kthread_is_per_cpu() can be called directly without checking whether > PF_KTHREAD is set in task->flags. So remove PF_KTHREAD check to make > code more concise. > > Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> > --- > kernel/cgroup/cpuset.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index 58e6f18f01c1..601c40da8e03 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -1230,7 +1230,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus) > /* > * Percpu kthreads in top_cpuset are ignored > */ > - if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) > + if (kthread_is_per_cpu(task)) > continue; > cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); > } else { The initial intention was to ignore only percpu kthreads. The current code likely ignore all the kthreads. Removing the PF_KTHREAD flag, however, may introduce unexpected regression at this point. I would like to hold off for now until more investigation are done. Thanks, Longman
On 2023/7/5 11:14, Waiman Long wrote: > On 7/4/23 07:30, Miaohe Lin wrote: >> kthread_is_per_cpu() can be called directly without checking whether >> PF_KTHREAD is set in task->flags. So remove PF_KTHREAD check to make >> code more concise. >> >> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> >> --- >> kernel/cgroup/cpuset.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c >> index 58e6f18f01c1..601c40da8e03 100644 >> --- a/kernel/cgroup/cpuset.c >> +++ b/kernel/cgroup/cpuset.c >> @@ -1230,7 +1230,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus) >> /* >> * Percpu kthreads in top_cpuset are ignored >> */ >> - if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) >> + if (kthread_is_per_cpu(task)) >> continue; >> cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); >> } else { > > The initial intention was to ignore only percpu kthreads. The current code likely ignore all the kthreads. Removing the PF_KTHREAD flag, however, may introduce unexpected regression at this point. I would like to hold off for now until more investigation are done. IMHO, the current code will ignore only percpu kthreads: 1.If PF_KTHREAD is set in task->flags, this patch doesn't make any difference. 2.If PF_KTHREAD is not set in task->flags, kthread_is_per_cpu will *always return false*. So this patch doesn't make any functional change. bool kthread_is_per_cpu(struct task_struct *p) { struct kthread *kthread = __to_kthread(p); if (!kthread) return false; .... } static inline struct kthread *__to_kthread(struct task_struct *p) { void *kthread = p->worker_private; if (kthread && !(p->flags & PF_KTHREAD)) ^^^^^^^^^^^^^^^^^^^^^^ PF_KTHREAD is not set, so kthread = NULL. kthread = NULL; return kthread; } Or am I miss something? Thanks for comment and review.
On 7/5/23 01:56, Miaohe Lin wrote: > On 2023/7/5 11:14, Waiman Long wrote: >> On 7/4/23 07:30, Miaohe Lin wrote: >>> kthread_is_per_cpu() can be called directly without checking whether >>> PF_KTHREAD is set in task->flags. So remove PF_KTHREAD check to make >>> code more concise. >>> >>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> >>> --- >>> kernel/cgroup/cpuset.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c >>> index 58e6f18f01c1..601c40da8e03 100644 >>> --- a/kernel/cgroup/cpuset.c >>> +++ b/kernel/cgroup/cpuset.c >>> @@ -1230,7 +1230,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus) >>> /* >>> * Percpu kthreads in top_cpuset are ignored >>> */ >>> - if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) >>> + if (kthread_is_per_cpu(task)) >>> continue; >>> cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); >>> } else { >> The initial intention was to ignore only percpu kthreads. The current code likely ignore all the kthreads. Removing the PF_KTHREAD flag, however, may introduce unexpected regression at this point. I would like to hold off for now until more investigation are done. > IMHO, the current code will ignore only percpu kthreads: > 1.If PF_KTHREAD is set in task->flags, this patch doesn't make any difference. > 2.If PF_KTHREAD is not set in task->flags, kthread_is_per_cpu will *always return false*. So this patch doesn't make any functional change. > > bool kthread_is_per_cpu(struct task_struct *p) > { > struct kthread *kthread = __to_kthread(p); > if (!kthread) > return false; > .... > } > > static inline struct kthread *__to_kthread(struct task_struct *p) > { > void *kthread = p->worker_private; > if (kthread && !(p->flags & PF_KTHREAD)) > ^^^^^^^^^^^^^^^^^^^^^^ > PF_KTHREAD is not set, so kthread = NULL. > kthread = NULL; > return kthread; > } > > Or am I miss something? Thanks for comment and review. Yes, you are right. I was that conscious when I reviewed the patch last night :-) Reviewed-by: Waiman Long <longman@redhat.com>
On Tue, Jul 04, 2023 at 07:30:49PM +0800, Miaohe Lin wrote: > kthread_is_per_cpu() can be called directly without checking whether > PF_KTHREAD is set in task->flags. So remove PF_KTHREAD check to make > code more concise. > > Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Applied to cgroup/for-6.6. Thanks.
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 58e6f18f01c1..601c40da8e03 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1230,7 +1230,7 @@ static void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus) /* * Percpu kthreads in top_cpuset are ignored */ - if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) + if (kthread_is_per_cpu(task)) continue; cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); } else {