From patchwork Thu Sep 26 22:49:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13813709 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 6E9A0CDE03E for ; Thu, 26 Sep 2024 22:49:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB82B6B009C; Thu, 26 Sep 2024 18:49:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1A8C6B009D; Thu, 26 Sep 2024 18:49:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6DBE6B009E; Thu, 26 Sep 2024 18:49:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A410E6B009C for ; Thu, 26 Sep 2024 18:49:54 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 32A3DA0681 for ; Thu, 26 Sep 2024 22:49:54 +0000 (UTC) X-FDA: 82608383508.06.F3311C0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 7C34B16000B for ; Thu, 26 Sep 2024 22:49:52 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=psM8YQFN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.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=1727390956; a=rsa-sha256; cv=none; b=tx3Si5/SinhQxHCePkp9xj/KLDPsD9E2fXjSEdTn7d9XtzEN58iRhlqhAzUsPjnloc+GoN Mm0YUXSt6egZQitWE0SaCIPJq69KLlpEWSnl6fnRuas4W4rKsk8rWgqvGiO1sqcSBPvC7g H5zwy3ZOPiBaDLBj5KnJft+gfi1yywM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=psM8YQFN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.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=1727390956; 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=q6jqDyfO08755Jv9zwpU/yTPCka3YMPmfzWOcL16ONvhe4IoTfvUTxn0Kjz100Y+PsLvrR Ny+ft4816KLFjxaURM8UmIABGVtDQU/LkOQUg7H1P0Qiobsgg/JHVcQmDpXoI22jTJ/Jqu ZTnAD0ZzXoDajRk+gOrJtb1xv0yTrbg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C52C05C58A0; Thu, 26 Sep 2024 22:49:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F665C4CED0; Thu, 26 Sep 2024 22:49:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390991; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psM8YQFN5mZ3FzBukGKWEToWhZzCosyMS0j5KLWvaT8kWVGcT5tEVHkD15uycwmmo tJ1LttkAxj4ZweWz/08s7Kgrwh2kGdoUVn4gLfJeqPwS+NB/xmOBSSQswp/UECwOIh ImitrWdjMszxOjTusfjUOiF5fXo5SsImb1ftjw8izmEPoA7IYlRPXVL1aPmEFgkVha uz9CHu3SywKw1F3hqctu0GEWLSFVSBAT7sCkOes64A/1ubJODn4AmG897NX7CnsoNf 6WWjkBU5HcTp5GdJ+RK/iH5GUuE618/1yJujZ9W5ZMCLOA21ySARoJat1rQNAlhCN2 tJrXoHP8jA27g== 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 14/20] mm: Create/affine kcompactd to its preferred node Date: Fri, 27 Sep 2024 00:49:02 +0200 Message-ID: <20240926224910.11106-15-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 7C34B16000B X-Rspamd-Server: rspam01 X-Stat-Signature: kitbj9t7pjfkn9mqtkren7tyubzbd8nh X-HE-Tag: 1727390992-374205 X-HE-Meta: U2FsdGVkX1/VjTiYvWgKyjKZ/XPOqvV3K2781nd4f/AT1A74vfdGTIbpkx867onuSZwH02Fesh74/EGeTYBPLqRflY5Pu3rb1bQQZRUBW5EfCOhXzV13NusV88raKdID3iWhI8k0y4+ckf4Q8DWXpkAsOagWI8eSPKws7wqC6dvGqiXeUbHHm2UKCCgeNyL6EFxvtT1oEjyaQl1QfBzMuEbRknwNRLAZDlEg+QpgouJEkg5REnXVRBZtgvhr+QvNAPjK6s7yLmQQe4IYAfP+oX8HZSm23/It4y947kfhO+bssR0xDeDstKANahRRCNEgUFmu4IWT11IUqFwQWf1yK9MQXsvyddowsHBO3z6Eveu8HEuxvX1G1K6s2gx011x1JJGwodfmVHCjpYhicgVV8Jx6csqpLQ4RNDznTNvNacH3LA+RlBT8ROz6//XHGs90wCO/8CV2Kv6SFjnU74FLTocM5kY5uVzJtCGTfq5FCJ67wDdc+YPCkmtEyyelZ7ZTwX/6nD901k+CYiiiyfT0FMIE1ZtEUThWyPo0gXM7utkzuHQJ3krdSR18CvMHK55e7Qj9debpOnAVBt1um6peWYD9DVXsRjASpQOeJPs3KqWF4+jbCAx3waJPH+5YySxhnWIGLqa3HvgDwUxWEGAgsxuYmXHKZ39r+jyRgssivu5S5AvLytGir48AXHSrcJdZMCpQ5dDbuqxqd8MviftEngwsu/Zq6+S+Oyf+igL+JkhB450FQlQ82QjGpgLT3iBpHcD88OXiwDW2JA0BXDEVGzaagY+Xfne21EMMqyM3H8iKYHqreqwtIFrmMz6QPL67F0oOvvMmv1JrKSaTD9ew/CPVOFAD/qVWI6sqGqprkXEndL4IFuwceGEi6ue0HGqs2Ard86OKdk4nZFrj7Ncjv84jkpEupRbp7h03yQfLm6nB/2FbTzeNS89nwcA7IkLlBjP3tYTaWcTXJGTOGHE 7VziXbE3 DemPnqgKGq6nO+NSWnGKQMDWfd/Lsif2xVq1p2DJXwNQSh4SgMS1aaW9hKzqUhM5H+sU0fuT4bIHqxMbhjr7ZxE7NcNP/prqcKFgpuhp6mOuJ1tai2cy5us+jFquQq63bgOu2oECFdLBnKUjw9mUQSRfZGBCsGVeg1eHJQQniiYBRQwf3Eq1WSbAnwGfxNKW1LoTpZ4DZoDkVEzf5oULCAQbYKpka0+gdQa3rqOnmWLbD4nGb60gQs8ESoQhOXmebUJiasLZqBRfvkKKc4ERAF7KeYaMW7wWKNc3y 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);