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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76128CCD1A5 for ; Tue, 21 Oct 2025 22:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:References:Cc:To:Subject:MIME-Version:Date: Message-ID:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=J1ufi8hzAWdR5ZvtubHPkIBiveTzx8KWYjOx6TAX45A=; b=uBZAqR8ruVuYQB5iz0jWoV0J43 0liw487iD9KnndhUFg0DLkfdgajlnr3kcnxq7uKLBqduEH15p2zhn7j/Ohwwaf8zuK+M37BY0LUwa /W7rNs8MVCtGuoGnOmHfi7rVAbR0C9tXAP6iKYqFGdE5EekTUekAowz3YmIoWril/9YzVZnG3IFHs PvsU3TqSy7sraMqA9k65hueaJM7c3XN0WR5KvsPAnxOL4IOaiSzPuPgdIP25kvo3jl+PSPBq96I9f Mw9QJYEmHu+EwbNFfWOAJBVKL2Y/d3RNgUUz/577BX8GLIwVcOXzI3vW2h8eRuWzjnlR8hr/o4kTW gOQh6xWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vBL4T-00000000pEp-1kmx; Tue, 21 Oct 2025 22:43:13 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vBL4P-00000000pBB-3U9Z for linux-arm-kernel@lists.infradead.org; Tue, 21 Oct 2025 22:43:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761086587; 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=J1ufi8hzAWdR5ZvtubHPkIBiveTzx8KWYjOx6TAX45A=; b=DKEiOlVc1L9iYUu4dx6LNuIQjc3KlCr1jeKhOO1wyccVH9QXieVfwD51HScDdb7SrV4LLx IxdgDJZ4jy4WgN+IZ9+hDOqlP+xgFhMyM6pXahotAy/v6jyMcIdqAnvz5Nbuw1ma90ksqD G1w5+y0NEde18zrzsOg0YjOhahdLcCU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-NjhalCM0NDyc9mlg3EIazw-1; Tue, 21 Oct 2025 18:43:05 -0400 X-MC-Unique: NjhalCM0NDyc9mlg3EIazw-1 X-Mimecast-MFC-AGG-ID: NjhalCM0NDyc9mlg3EIazw_1761086585 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-892637a3736so1790099885a.1 for ; Tue, 21 Oct 2025 15:43:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761086585; x=1761691385; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J1ufi8hzAWdR5ZvtubHPkIBiveTzx8KWYjOx6TAX45A=; b=EezMlGyvkkcoBqwty3pu2y6CbUmTHt5ntbp6L+yz5bxvJTNYA/ED39SxhZRvLb6fO4 MiJm9OEFT158emtzN/BQ7hJldGvT+mkkekPTUux4pYATDn5Ix1K45xfNZH/iCiWwBseo NeUsugQQFKy0swaDXJLaV1A6Tf+fgWMvPKszW5Sm2QjvT5BLC5MJOttuoxw9TZpbK1yO yT632LdC+jnUaXKJ12NQ8b3ykwXsjdP7jWPP1ZubhfYwHNlLl5zmSmeq067d3p+fdsPt mqs4YB+/+u6iYnyOauCrLg2d4B8LrGrzyceJ6hHPT1oWrRBoMbIzVfbIqQarHGxSHCXq vyWw== X-Forwarded-Encrypted: i=1; AJvYcCUBD+1Ogz0ml6H02Eqm/V9Zlpg1kb3TkkcRMPAaIZiHOuZt5GLnP7YNw3XKQz2VKi0JJDZnTlMFmJLeAGrrZtP9@lists.infradead.org X-Gm-Message-State: AOJu0YzyRS/t2wjP87vdd+XBKbo/is30rOuYa+Zs587gyB7cr3iV/CBO Fm/ADNR+5z/HiMSqVNN6Tct8ShkSaljzkhZUoYofE6LM/1TitkWKVLOAojOE8sD7sJIa66K+tDv mmhOHw8qjOIVxJNl+TGD11tZVfuhOSi09IRNctQ0g3plZC9kry7IA9uP5tGFyE1VsIPnzy2kRg+ ST X-Gm-Gg: ASbGncv24qs1DiN3f5fSb6ZVeMnyTgMS/6xcLmDlzvnr0BZgVXgJrJAw0GHEi3XNSD+ v0qHBJnQCWtCyllfVCANmXiZQRoTxf8G7PsfCkbmu/hNlLL8KbNMTfuRX7uNTOD1RK8V9KFtfIB UPzX1i9ghi0rAmK1/re85saC30hM6uvkBYcdG5qMM261ifQTdhTSMCIAKl/kDK74mTOJ6cIS613 +gn1LrLzJ6aezYUrwf708jkVvpZuUhj9/3MGmku+N2Pgv65wJoFrzSBM10tvadteLLfi9sL4mVs H0lW5B+U3/gRnz9ac3hB3rjzRgsyl5bEHID4ilVJwtn56eJm8Z3aqDTmTxG5uxLXJsqMlxwQ10V 2lUOgimgu6VHPim59w6nBHO87TvM0U/B8YKzl6RURuu+1CQ== X-Received: by 2002:a05:620a:2892:b0:886:ea5d:9273 with SMTP id af79cd13be357-8906e6ba4b1mr2387617685a.28.1761086585026; Tue, 21 Oct 2025 15:43:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKKo/21Swm4z17XlE0/ydMbQxCAbbChu7Z8fNIxB6CZQJ6hcePBsIiw2WUviotKsZ3CeiiMA== X-Received: by 2002:a05:620a:2892:b0:886:ea5d:9273 with SMTP id af79cd13be357-8906e6ba4b1mr2387614585a.28.1761086584536; Tue, 21 Oct 2025 15:43:04 -0700 (PDT) Received: from ?IPV6:2601:600:947f:f020:85dc:d2b2:c5ee:e3c4? ([2601:600:947f:f020:85dc:d2b2:c5ee:e3c4]) by smtp.gmail.com with ESMTPSA id af79cd13be357-891cefba728sm848019085a.38.2025.10.21.15.43.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Oct 2025 15:43:03 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: Date: Tue, 21 Oct 2025 18:42:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 22/33] kthread: Include unbound kthreads in the managed affinity list To: Frederic Weisbecker , LKML Cc: =?UTF-8?Q?Michal_Koutn=C3=BD?= , Andrew Morton , Bjorn Helgaas , Catalin Marinas , Danilo Krummrich , "David S . Miller" , Eric Dumazet , Gabriele Monaco , Greg Kroah-Hartman , Ingo Molnar , Jakub Kicinski , Jens Axboe , Johannes Weiner , Lai Jiangshan , Marco Crivellari , Michal Hocko , Muchun Song , Paolo Abeni , Peter Zijlstra , Phil Auld , "Rafael J . Wysocki" , Roman Gushchin , Shakeel Butt , Simon Horman , Tejun Heo , Thomas Gleixner , Vlastimil Babka , Will Deacon , cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, netdev@vger.kernel.org References: <20251013203146.10162-1-frederic@kernel.org> <20251013203146.10162-23-frederic@kernel.org> In-Reply-To: <20251013203146.10162-23-frederic@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xxkNBfYgQc2wq8CCcNygCTZfrChaevtsM8W_U4lWpD0_1761086585 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251021_154309_953095_7DC1B5D1 X-CRM114-Status: GOOD ( 30.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/13/25 4:31 PM, Frederic Weisbecker wrote: > The managed affinity list currently contains only unbound kthreads that > have affinity preferences. Unbound kthreads globally affine by default > are outside of the list because their affinity is automatically managed > by the scheduler (through the fallback housekeeping mask) and by cpuset. > > However in order to preserve the preferred affinity of kthreads, cpuset > will delegate the isolated partition update propagation to the > housekeeping and kthread code. > > Prepare for that with including all unbound kthreads in the managed > affinity list. > > Signed-off-by: Frederic Weisbecker > --- > kernel/kthread.c | 59 ++++++++++++++++++++++++------------------------ > 1 file changed, 30 insertions(+), 29 deletions(-) > > diff --git a/kernel/kthread.c b/kernel/kthread.c > index c4dd967e9e9c..cba3d297f267 100644 > --- a/kernel/kthread.c > +++ b/kernel/kthread.c > @@ -365,9 +365,10 @@ static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum > if (kthread->preferred_affinity) { > pref = kthread->preferred_affinity; > } else { > - if (WARN_ON_ONCE(kthread->node == NUMA_NO_NODE)) > - return; > - pref = cpumask_of_node(kthread->node); > + if (kthread->node == NUMA_NO_NODE) > + pref = housekeeping_cpumask(HK_TYPE_KTHREAD); > + else > + pref = cpumask_of_node(kthread->node); > } > > cpumask_and(cpumask, pref, housekeeping_cpumask(HK_TYPE_KTHREAD)); > @@ -380,32 +381,29 @@ static void kthread_affine_node(void) > struct kthread *kthread = to_kthread(current); > cpumask_var_t affinity; > > - WARN_ON_ONCE(kthread_is_per_cpu(current)); > + if (WARN_ON_ONCE(kthread_is_per_cpu(current))) > + return; > > - if (kthread->node == NUMA_NO_NODE) { > - housekeeping_affine(current, HK_TYPE_KTHREAD); > - } else { > - if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) { > - WARN_ON_ONCE(1); > - return; > - } > - > - mutex_lock(&kthread_affinity_lock); > - WARN_ON_ONCE(!list_empty(&kthread->affinity_node)); > - list_add_tail(&kthread->affinity_node, &kthread_affinity_list); > - /* > - * The node cpumask is racy when read from kthread() but: > - * - a racing CPU going down will either fail on the subsequent > - * call to set_cpus_allowed_ptr() or be migrated to housekeepers > - * afterwards by the scheduler. > - * - a racing CPU going up will be handled by kthreads_online_cpu() > - */ > - kthread_fetch_affinity(kthread, affinity); > - set_cpus_allowed_ptr(current, affinity); > - mutex_unlock(&kthread_affinity_lock); > - > - free_cpumask_var(affinity); > + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) { > + WARN_ON_ONCE(1); > + return; > } > + > + mutex_lock(&kthread_affinity_lock); > + WARN_ON_ONCE(!list_empty(&kthread->affinity_node)); > + list_add_tail(&kthread->affinity_node, &kthread_affinity_list); > + /* > + * The node cpumask is racy when read from kthread() but: > + * - a racing CPU going down will either fail on the subsequent > + * call to set_cpus_allowed_ptr() or be migrated to housekeepers > + * afterwards by the scheduler. > + * - a racing CPU going up will be handled by kthreads_online_cpu() > + */ > + kthread_fetch_affinity(kthread, affinity); > + set_cpus_allowed_ptr(current, affinity); > + mutex_unlock(&kthread_affinity_lock); > + > + free_cpumask_var(affinity); > } > > static int kthread(void *_create) > @@ -924,8 +922,11 @@ static int kthreads_online_cpu(unsigned int cpu) > ret = -EINVAL; > continue; > } > - kthread_fetch_affinity(k, affinity); > - set_cpus_allowed_ptr(k->task, affinity); > + > + if (k->preferred_affinity || k->node != NUMA_NO_NODE) { > + kthread_fetch_affinity(k, affinity); > + set_cpus_allowed_ptr(k->task, affinity); > + } > } My understanding of kthreads_online_cpu() is that hotplug won't affect the affinity returned from kthread_fetch_affinity(). However, set_cpus_allowed_ptr() will mask out all the offline CPUs. So if the given "cpu" to be brought online is in the returned affinity, we should call set_cpus_allowed_ptr() to add this cpu into its affinity mask though the current code will call it even it is not strictly necessary. This change will not do this update to NUMA_NO_NODE kthread with no preferred_affinity, is this a problem? Cheers, Longman