From patchwork Wed Dec 11 15:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13903664 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 832CCE7717D for ; Wed, 11 Dec 2024 15:41:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F97A6B0099; Wed, 11 Dec 2024 10:41:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A7F86B009A; Wed, 11 Dec 2024 10:41:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8BAE6B009B; Wed, 11 Dec 2024 10:41:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C2AD86B0099 for ; Wed, 11 Dec 2024 10:41:19 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2ADCF140EDD for ; Wed, 11 Dec 2024 15:41:19 +0000 (UTC) X-FDA: 82883091984.28.BFEF461 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id CEEE0100013 for ; Wed, 11 Dec 2024 15:40:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oeq3o9e2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733931655; a=rsa-sha256; cv=none; b=h6F7+O8fsfQrGrzj3I6Ou6JRjqiwgE8DYihtNjB4n4AZErxF/Qz85tuxm6Zjjg7pDxlSjh dzvx/coQHEa1h7D0VmAf0Y+M80WY0tiwKfCkSvD2VvgFw8T6xT/crQ8UUP6nUGcwIvzVsi ArjGinqq9KjXCLnHaoULMEX+reMHXqI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oeq3o9e2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733931655; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QMfzeDE6TO0jUOHFKLhVcYsWmCqJHbXGFSX6Ot+8q1Q=; b=fh8eYqttayga1woYNwxXMsg5tOrtbo28ca/v1H5C91bUYOWHrVSgPrx4m++uFb8v13mJR8 Fmw5BTSveEbmf/ACX9dODaUzme4Kcwj9tXnyMushFWyz/51u/HXgasnV9nR2Tap1NUu1yW UzUCSGrvLAIuIwXfaXm+dzFx4vDCn0M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2D9045C62D8; Wed, 11 Dec 2024 15:40:34 +0000 (UTC) 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> MIME-Version: 1.0 X-Stat-Signature: ux334kspgxhm958jpfbbzmc8crxygxtw X-Rspam-User: X-Rspamd-Queue-Id: CEEE0100013 X-Rspamd-Server: rspam08 X-HE-Tag: 1733931651-822108 X-HE-Meta: U2FsdGVkX19zvcaebzAa+LhL1xweLxSjqKJ9WJO9Ah/86PLa+kXQsSpnE6duhCTY/UHPPFCPfe21+hem1PY9VVSoHonzXaONa+hQeJdHZmXCr9Xz4Wn3ODz6wmwRHedo2DE0gR2+vJEcPlGx6hU+ta43O6Ov3OlErAkxscNkxs7UdHL1gAK06OxcVa73di6Pq2RLvkJkpENolNKqo/hhABLTbInngLWI+BGaCuuxBA352e9jp34K/NlZoPPTpCOGkwdmidaUG5A08T70Kat0KzRXSCkoAqQrcnGG76ii8QGTiGNbLGohGVB3XDuGoDnrCQEeq10/8ZjzKUZ102JkWbaniw+dqlw3ry5wsmnYAM+SkFVet61ERan7RDACXCWtOI7W4vyyUdhnrZtZMfUqKU0Pux51eHVIbYZeJIF6bHaqxKJNuCWm0ORE5FzJck/bLNIHco1fC7wzAGdk1HSqho37TMukQ5MGprXCxVtyGxiTZwTO8MXvirRlk9k/PJlWaGj3JjCu+LcG4oAOS/TvI/CXuPPNEjBCgBtDuoRMXJtZWkMVjQ5bv4cN/Fdu+hxXaQsnMJZnZGTb3ZDcRBC8Kp5wP14QUB26U8JYnnNuf1MeFal5vYYRZhBG/uQVrMKugJKCIeEG06wISy0xB/oGfb1cqeJCahE1w2V6eWUXKCTJogAgN4BxQI+41mGCEjPdEBZ4BL+e1+thXQxwE71TsTS50cAs+6eiZaGex6MKsmmiT+hZNLLxNc34uUHpZZFsMvLE98yaplxJFXCyQ8UZ6sDtmw5ZVGJpEoPyfSlsPmlQENeuDFPgcyKesrvtBZQSRUkOCNZgrXXt9O0Ctd/aEdC/1chMhN+pte70tUNwUeITLiMgNWNWmjZFZ8whHMPSrDeSJkRx9J/tR0esDEia+8Xz1/adHUHT95R7AsBRsy6Ra60eB4VzOGjAwLxH1amQaGyTB7nUth+qS/BKyT4 pD8xFJZT JRCwqqAwph/Hs2s6vxBWBbyxZ4phJv6MJ/FlXGj11Em8AEQ8tOAEFzFLAsmAQa/XKuNGCBi5ZOOneLV5udJXeWh4FO6Qk3XnJA/iyBvlveZqeSFF2ipQX8GZYdysMGbWfQVqRnEs62DA97CAzdsYMrlEQ46iCeXPv7zpkBYlZk1ZWwwSkkfDD136WP1D8NcC4+vwKO8pA/l0Z/UqY3KYl5Y+UVu6SdOIZCfflPjRY/pPwhy9lx+jEDgB22h+fIkquklwYkTx/QcWcQlbaVRUQTPKS7NQePQInqN4Q X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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, int highest_zoneidx) static int kcompactd(void *p) { pg_data_t *pgdat = (pg_data_t *)p; - struct task_struct *tsk = current; long default_timeout = msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC); long timeout = default_timeout; - const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id); - - if (!cpumask_empty(cpumask)) - set_cpus_allowed_ptr(tsk, cpumask); - set_freezable(); pgdat->kcompactd_max_order = 0; @@ -3233,10 +3227,12 @@ void __meminit kcompactd_run(int nid) if (pgdat->kcompactd) return; - pgdat->kcompactd = kthread_run(kcompactd, pgdat, "kcompactd%d", nid); + pgdat->kcompactd = kthread_create_on_node(kcompactd, pgdat, nid, "kcompactd%d", nid); if (IS_ERR(pgdat->kcompactd)) { pr_err("Failed to start kcompactd on node %d\n", nid); pgdat->kcompactd = NULL; + } else { + wake_up_process(pgdat->kcompactd); } } @@ -3254,30 +3250,6 @@ void __meminit kcompactd_stop(int nid) } } -/* - * 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 = NODE_DATA(nid); - const struct cpumask *mask; - - mask = 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 *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -3337,15 +3309,6 @@ static struct ctl_table vm_compaction[] = { static int __init kcompactd_init(void) { int nid; - int ret; - - ret = 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; - } for_each_node_state(nid, N_MEMORY) kcompactd_run(nid);