From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55D07309F13; Mon, 13 Oct 2025 20:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760387742; cv=none; b=CQikmQ3RxCo7Eg1OX3dRWvVhD8UusM1eQ+ICdXiUStcUE7z8QN8BWkMryqXUDvZRg6jcri6HBpQbLPuWfR48iLIgWaWlWPC0Vu1bL/bO4fAt8zQjmyVwwdGTGbLzx8BCU+C3g1gJt5K4VHAENRUs3jVWhWTebTrTMD8mbFjqZn4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760387742; c=relaxed/simple; bh=n52cAu7bEMYLK1x1CARbNE9gVHxK/1DrMBlj3TyiG6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I5mKQKtemJk9mZLWvgaJzakt1jFhrPciPrTIVuD5KgKZIHClMhm4PVxYKlKlxs3gFmL6Vngu1Sqjo5MG7PFPcO0qk8NtxrNZwsV6kMHz2eCGMDJHnHC6ZqFgiD0ivJYvhPjP4d814o6gRfSQiLsBhpsSoe0uv4pwGmW3erga7pI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hwx+RCh+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Hwx+RCh+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 858D8C4CEE7; Mon, 13 Oct 2025 20:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760387741; bh=n52cAu7bEMYLK1x1CARbNE9gVHxK/1DrMBlj3TyiG6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hwx+RCh+ZncRTZW4J3H101zxwGK2eXC7I/AqUiWKIv2Duuwwy39jB7rQi4ZnPKStV AbZRbdrU5REoIKByt/LVOaIEFYsTkgcDK/rQsCPMoITkhkdZg7ALJytPyN7MOI1vc+ RT2iSlPvYNcvFM6/vFKmR2bKzL+SNzPQURqdZYp7huxAcjMbS59DbwOQUz7/bpVVj0 HlKhsXGjIBcqreM/spUfVwgtUf7zzM7ao5qVaRVLlRlbKWfKCo1/4m/YIzCT1UeKOQ h3AAzzYPrXCd+VjamYW07Z5gyLAAw3SuDh1Wkx20np8piV10n7YbOohjL426Rqpvuk +nJqSOrG0UW6A== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , =?UTF-8?q?Michal=20Koutn=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 , Waiman Long , 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 Subject: [PATCH 29/33] kthread: Comment on the purpose and placement of kthread_affine_node() call Date: Mon, 13 Oct 2025 22:31:42 +0200 Message-ID: <20251013203146.10162-30-frederic@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251013203146.10162-1-frederic@kernel.org> References: <20251013203146.10162-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit It may not appear obvious why kthread_affine_node() is not called before the kthread creation completion instead of after the first wake-up. The reason is that kthread_affine_node() applies a default affinity behaviour that only takes place if no affinity preference have already been passed by the kthread creation call site. Add a comment to clarify that. Reported-by: Peter Zijlstra Signed-off-by: Frederic Weisbecker --- kernel/kthread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/kthread.c b/kernel/kthread.c index 4d3cc04e5e8b..d36bdfbd004e 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -453,6 +453,10 @@ static int kthread(void *_create) self->started = 1; + /* + * Apply default node affinity if no call to kthread_bind[_mask]() nor + * kthread_affine_preferred() was issued before the first wake-up. + */ if (!(current->flags & PF_NO_SETAFFINITY) && !self->preferred_affinity) kthread_affine_node(); -- 2.51.0