From nobody Sun Dec 14 21:21:49 2025 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 71A5D1DE896 for ; Wed, 11 Dec 2024 15:41:16 +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=1733931676; cv=none; b=QV1Nmcz+jYGxOm/XFIEjapa1Yk4ZzNc7ZJ1k27hFDqs9rhwcEKoYmeTSAL07YKAok7AB7swKkcPNtTBAOM39bmNu6j4AVzunyZh8FbLX2oEI7jHoLW4YeJBnEfNdR/g7uwDgWm4vfKkn+xbus6UR9xfBnfx8QXfk6O8lsohtlNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733931676; c=relaxed/simple; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rmP3omyDmoPme9BAjJuKXDImGBeVyWnbyKvG+OcILT1pqYty/dhAcqoD3fWfOQHJaU7AZDIlXezqb4qD3TjRiDXh0wGqgEp/rCdwQRswKWlEes+Bedvy2wUyAPcfsr/dpyGZx3rsX5ewmGUqQbLJvDgU/gnXKkSJ404f4KE/JjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oeq3o9e2; 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="oeq3o9e2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10F0FC4CEDD; Wed, 11 Dec 2024 15:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733931676; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oeq3o9e2NAUqySEkDCKQkStfvImclCo4E0hGcJqRAGbj2T9C+ll7Pdcz8Laf6EWV/ vxe1zptvJkQR4sEtfJVWkpF/zzUUytTpDonSs/vH0n1eGMp2fuPaW3G4NDw5xJUDSR ArT/hV5/GrlRsYvSno3sTVFPCNF2P7/6dtu9NARfeNTGjNeKmIwCiBpdfA9PpHVrxG fK02SjiY7i2t2uV95xavpTQ064kY9vagR6FnOu21YVfXpUyUZqDxb8nYfmRP1v4KO5 Wcl4MBxrNQuY8p6UXqV1Zz9YvPUpnrau1q2WUb1dODjm2Dq0IosI4rjLfErpjc4sxV 88UdVL2bSSh4g== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Michal Hocko , Vlastimil Babka , Andrew Morton , linux-mm@kvack.org, Peter Zijlstra , Thomas Gleixner , Michal Hocko Subject: [PATCH 13/19] mm: Create/affine kcompactd to its preferred node Date: Wed, 11 Dec 2024 16:40:26 +0100 Message-ID: <20241211154035.75565-14-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241211154035.75565-1-frederic@kernel.org> References: <20241211154035.75565-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Kcompactd is dedicated to a specific node. As such it wants to be preferrably affine to it, memory and CPUs-wise. Use the proper kthread API to achieve that. As a bonus it takes care of CPU-hotplug events and CPU-isolation on its behalf. Acked-by: Vlastimil Babka Acked-by: Michal Hocko Signed-off-by: Frederic Weisbecker --- mm/compaction.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index a2b16b08cbbf..a31c0f5758cf 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -3154,15 +3154,9 @@ void wakeup_kcompactd(pg_data_t *pgdat, int order, i= nt highest_zoneidx) static int kcompactd(void *p) { pg_data_t *pgdat =3D (pg_data_t *)p; - struct task_struct *tsk =3D current; long default_timeout =3D msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC); long timeout =3D default_timeout; =20 - const struct cpumask *cpumask =3D cpumask_of_node(pgdat->node_id); - - if (!cpumask_empty(cpumask)) - set_cpus_allowed_ptr(tsk, cpumask); - set_freezable(); =20 pgdat->kcompactd_max_order =3D 0; @@ -3233,10 +3227,12 @@ void __meminit kcompactd_run(int nid) if (pgdat->kcompactd) return; =20 - pgdat->kcompactd =3D kthread_run(kcompactd, pgdat, "kcompactd%d", nid); + pgdat->kcompactd =3D kthread_create_on_node(kcompactd, pgdat, nid, "kcomp= actd%d", nid); if (IS_ERR(pgdat->kcompactd)) { pr_err("Failed to start kcompactd on node %d\n", nid); pgdat->kcompactd =3D NULL; + } else { + wake_up_process(pgdat->kcompactd); } } =20 @@ -3254,30 +3250,6 @@ void __meminit kcompactd_stop(int nid) } } =20 -/* - * It's optimal to keep kcompactd on the same CPUs as their memory, but - * not required for correctness. So if the last cpu in a node goes - * away, we get changed to run anywhere: as the first one comes back, - * restore their cpu bindings. - */ -static int kcompactd_cpu_online(unsigned int cpu) -{ - int nid; - - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat =3D NODE_DATA(nid); - const struct cpumask *mask; - - mask =3D cpumask_of_node(pgdat->node_id); - - if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) - /* One of our CPUs online: restore mask */ - if (pgdat->kcompactd) - set_cpus_allowed_ptr(pgdat->kcompactd, mask); - } - return 0; -} - static int proc_dointvec_minmax_warn_RT_change(const struct ctl_table *tab= le, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -3337,15 +3309,6 @@ static struct ctl_table vm_compaction[] =3D { static int __init kcompactd_init(void) { int nid; - int ret; - - ret =3D cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, - "mm/compaction:online", - kcompactd_cpu_online, NULL); - if (ret < 0) { - pr_err("kcompactd: failed to register hotplug callbacks.\n"); - return ret; - } =20 for_each_node_state(nid, N_MEMORY) kcompactd_run(nid); --=20 2.46.0