From patchwork Mon Sep 16 22:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13805808 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 E5C9EC3ABB2 for ; Mon, 16 Sep 2024 22:50:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5266E6B0092; Mon, 16 Sep 2024 18:50:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5636B0093; Mon, 16 Sep 2024 18:50:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 377F76B0095; Mon, 16 Sep 2024 18:50:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 051356B0092 for ; Mon, 16 Sep 2024 18:50:11 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6C74A120174 for ; Mon, 16 Sep 2024 22:50:11 +0000 (UTC) X-FDA: 82572096222.03.458087F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id CAB8B12000E for ; Mon, 16 Sep 2024 22:50:09 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qhfUIBhA; spf=pass (imf29.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726526863; 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=UzduBpPmXurbjlrAIk3Lx0eqYn5j9Yi9P1SWpv6RXpA=; b=Bh2Nza7toxstH622BrZ2iYovDQGGTHq1O/L1ONFznzqY9vHUQGnmRsubdzUFqe6GU2s4+N avpJ1OXca1CKZQa7S9tOdWczL9jnGkBrEGS/hDBvm1UH5RDMf8i4Sl5Z4PBqzwL8e/ZoXg tKlYALnXfkvcK/wKQgcDUcIvv6qiS/k= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qhfUIBhA; spf=pass (imf29.hostedemail.com: domain of frederic@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726526863; a=rsa-sha256; cv=none; b=wJXPLemohxAzd/YI05G4rfsQ/eanj8ZMEBW4q9a20EFXTwPBmGFX5yP8px2q7rByFz9miC j55ItArqnzTtV9aTbeGbhO0MAGACqHVbxGok9E6vn7lncOqzGm2R6VqEE5LIY6A3RUWvo+ Yqgo0MOt2ggkPSsR0we2LGnfp719zQA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6D6285C021F; Mon, 16 Sep 2024 22:50:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD651C4CEC5; Mon, 16 Sep 2024 22:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726527008; bh=1dQPDIVHNJsgLLnrV38mW03au9nJKUebQ1/0avtuUj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qhfUIBhAeAVryTWFiKasVSqw5MFlegVH7koZBy6i2ei3w5rs8Wnm9dgPRZQY4GDBn 4fl51kEz1frYX0j0VM2HioDgBcg+TJ0VbJNqf7v5DAUecT62MfuIu1iQ9MOXCqtyhz kurDRtRmFVva0mvmG1HVc1GfZrty3Rw+4o7YdbDB/Z0BIzlxsgDu8eBec0XdMRcH8J 7I4B2oDHu940+26pUyy3x2sRof5wlBHNnu1AsPJqoY+hGfQRBpns2jzyH/9Z+OM1yl M60rhPxS4I0t6UkNl5fbahTaUUHYUzC+ZRrQ2o6O7IKYV/JkFERinmCYez1pOlXFAE jeMI4sONDWy7w== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Michal Hocko , Vlastimil Babka , Andrew Morton , linux-mm@kvack.org, Peter Zijlstra , Thomas Gleixner Subject: [PATCH 13/19] mm: Create/affine kcompactd to its preferred node Date: Tue, 17 Sep 2024 00:49:17 +0200 Message-ID: <20240916224925.20540-14-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240916224925.20540-1-frederic@kernel.org> References: <20240916224925.20540-1-frederic@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CAB8B12000E X-Stat-Signature: 5tsg9y9spprtgjtyskdfdshnfk7dhp5y X-Rspam-User: X-HE-Tag: 1726527009-798975 X-HE-Meta: U2FsdGVkX1/JWxW6tI+CpUWpstyZVpr6FevjvqOHf4K2fKh9Yk63EV4XXCR7qL8/ERG3a9GXcM71Y9tOKqffci0c4z8jsV6MjVRh+4n9bMR1ECZH3rK71g10fBmnS0WA/p+1AsxCkTQYjcfTYIscWypZzMDsNApBaFB/ytKWkC1JLu15G3Weqrb2KJ8kCXvPWy+0N93FED5qUeon1BCmaOnXvxRD+pMg2Iu7uron7de3xUBHLbkILz3kZ+G+w796VsYICR5vNXTbopYLPTHRIonWrZCbXmQZ902ykcMmtWOwDuRuYpzdU1MNHA5287Oq11UTJiCdyvvUlvkzAGtfq7OM88/52q4q37WQW6lve0WDrF4cMHBnfp8hrnjEb7+XvzEFign5yKIJxq1w3MLEmPPtgdvpgBig41QsmLNakB5YL2IZppmPY4gHfaxVC4Tf03/rRN1HWSYXxcTBETTZHeBfV3yr5R5Sh2Xg2ZCB8rSOMgWccztAH59pj+Nui1Wurzd2oAa6Rivs592mSsYScbZvzqfNIrHnmw+BUajzsD4rq5sUZm5h3l+pD11ipXzR+rLmNB5mdv0LJ4M/53CNrH2wzvC874ov1Wet0w+eU+koF3quX28bPlarwcj7rA65y4WSuCN8YVLBQy0Xwn0XKGh4ZGZDW8n98CTnKxVmOoMwsOfCTto/77UOeoynqVPAAiI9t6oUbx8GZOe7f9vyHO79nCPD9oSUwet/h03aazvrM3hIy4/vd9S+9zL60sw1Ysn7+RIandBFcgtjV+hYGu+MaGdDFfwX+TVQB74H4Kq0kkg0xH85uXYrgy3SFNynQUnWukj+r4sOHOK6+shlxb/mP5S1R1oWrbHWrH1L7gvNEfJJNJuXaM/uFozsTITyaRl/hGIx8+02jeYYwYdY8/A7bSFttANGNUlQr+kaawc7IGVkSMS5Nts7jXDtdbuBUoRQ1HfCFN8XzJWxd8j xO/ifYuK KsBTsKE5bn7wbztKa/D92qzfw2IA6+hN5A0V4i1wQJkZPMy9lJ1ALzQQDhib2Fd+1ZYmifzMk/t/Vj3hZ3P87FfuCJBmc5j7WOQMDEQvyBWs/q1jp1k//Tu0hZ2ky1lNb3WJzzWy5X/qe3iSupMkC8BJDFhZED+3J6JFhAtGEqx6yHW4b+mkA3+i94Jn+Sl/DglNIOdxgEUWoyyPCqrf6fXIjV5T3tG3eMifEAmIk3rouvp4= 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 Signed-off-by: Frederic Weisbecker Acked-by: Michal Hocko --- mm/compaction.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index eb95e9b435d0..69742555f2e5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -3179,15 +3179,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; @@ -3258,10 +3252,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); } } @@ -3279,30 +3275,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) { @@ -3362,15 +3334,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);