From patchwork Tue Nov 12 14:22:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13872298 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 19CC0D42B88 for ; Tue, 12 Nov 2024 14:23:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C90F8D0003; Tue, 12 Nov 2024 09:23:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 978178D0001; Tue, 12 Nov 2024 09:23:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 818A68D0003; Tue, 12 Nov 2024 09:23:39 -0500 (EST) 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 587AD8D0001 for ; Tue, 12 Nov 2024 09:23:39 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1F7091C4A94 for ; Tue, 12 Nov 2024 14:23:39 +0000 (UTC) X-FDA: 82777659216.01.AB3D43C Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 539DD20004 for ; Tue, 12 Nov 2024 14:23:18 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Nwym0DBh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of frederic@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=frederic@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731421355; a=rsa-sha256; cv=none; b=uXefqbnPHveet6KjC2cJeVmsYVJ4H6CWH93QUpeOCaS5pVD1byjx17gPi2JOefRxTc74Qr tM/bIbkKCsaF+yJNBeoPDHe8Q8WT6kS8DKfT6nfurfwTyPns0oluJBmTicsDEJ1rZvQMJE qA3Uh2PjAgMO/GrVwyF6W6c5N9cyZ+g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Nwym0DBh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of frederic@kernel.org designates 147.75.193.91 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=1731421355; 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=eOkxcvtuoCfzglRWt52qWMyJYLxY5uJFCk2f5EcwF/i9XKRL7+8DBgmYZO2Gitt9XC2zfp Tik9HmclUjwPxQz45DGwrtyzK35gwaZ88OBUshMowOw7eFw2r/vIk85pMRcyUsHhPy/PLW 3tq7DZVG8Cr/oQX1hTQwJxqMuZYB8n8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6C41BA41C11; Tue, 12 Nov 2024 14:21:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42AD8C4CECD; Tue, 12 Nov 2024 14:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731421416; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nwym0DBhhcTIwnkBrtiXN0Zp9WMkosF7kKibRx7BQA2VpqG9VTmW7/kNN32GigUWh eGEyA7c0DhVnewNn5JsR7G4Y/OS87vA3OTF+26Cyk9BPin48X3G26F0212UQzRdxs5 2fF4KMleehk7g1LT102UKvgu3K+Kgb+CRtd8OYe5N8PsO8gmkRaDdYTQOHPDuYoLnH uUCMVkYtOmeqfNL3fXTDdopjA1jGPL9L7PaS1xyiXrP/Maw2ThvyAqaxbOsjspiRgA QaWbRGasHp2OEqfAng5Ky7fOBZL8hRp0+PYYsUFsd6A984tK0DIanGey074Rcajr58 AE9BAL0WVPomQ== 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 15/21] mm: Create/affine kcompactd to its preferred node Date: Tue, 12 Nov 2024 15:22:39 +0100 Message-ID: <20241112142248.20503-16-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241112142248.20503-1-frederic@kernel.org> References: <20241112142248.20503-1-frederic@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 539DD20004 X-Rspamd-Server: rspam11 X-Stat-Signature: kk5ytagb1zne9srcpj3zfqqrj1hsync7 X-HE-Tag: 1731421398-560149 X-HE-Meta: U2FsdGVkX18FdgRF21FmVjmdwI+3xB6WI6ZBn41C7ukz8fqSu99WNiDzhpUsRuinzmNecE0PIcsqrusoyO4X/HnsXdixSCrbE8YbzbEBJkzL4oUXue9fBOIidpOJcO+wPpf0HB8ssI1HmjspwkNtU7z3BinOLj0zAfFB8ZcibLwC9tv3EkLzPfq5C7O6YYhJHLPoccgeBC3EGdHFVb2qf1NeaYC9UQjZmVo1z5DUBAKvUik/cb/f909S/jOvYE/6/rdedTRR99GPvmiCaf9Mdy8wHI3XWu2oMWPOl2lAvdlfHZSOT+PY3xLHwDvDqtkEn5yhcOka5tu25TnfV504iKSYICQeQOJt6kG1uNJUQ3as/Y41WIwShcsHvlzIICBeQm5Pb22IzeO2x2KZU1+grSlJgm5SG0W7BgCLd12eYX7Saw/NfSoWGJW+gG9Id8NpA1eohThoYPSOckixNPwNuBqJpvdLz7EQsjjNH6ufvnp1PYNSsDYd8KAFpeGRppKqmnYqRWQkJoPpRW3f9jtvXSWFM0CNut7gLaTl0PL/yUaTjeVaYZD+7e7sguWXnjfHTUeIAEImFH3IX2SUyxiwZf2JjYFQ2iyfdT5s20FQK8VbrSrDfH/OxxXAGsK2jpzJDS/EaPwvd4G3gM/t9tC+gOLZHMmizEEyauNkFN80sxlf2dbxhBs93SWVsvCQK8IpXaQzr0+t9vbZNgj+0ET3P6m3fWIkHjvO5RY36zV7B85zEHMldmkT9F/dKHteTxMdtjTVtzewtzVxUlnD71Sak6zFSUHPp/b2cXUa7XSNusPpLh86AeKS5cQNhNOPZxnxWPY+bfs+JuJ1e9LTp4r7+4SuM6cu8/33fOHcyO+rbYprXVfE8fMuHZBhOv7dP6JjiwyQ1eKzibF2ZWbeaSttDpRCwu4Ppwi1sCiq5vVCb4AfhENlDo7ys1OvTE1iL+tqS0Lue7Daut+KPydxBPR eq8SYqiB bD5C5YDvRfp3Qrghvvk253pTf5ksYGFyxOkEmWqSqFuBKA9QkHZk6QG8ZglW9hrq38pU7DehcxY1jz2VIemEbRO0q8sgSMfw2sV46eghejtx3s+9g3Z9T8vohAoHD6PoUWkdwivibotsqw5d4w1n3j+I/2LIc8Nhua47sXZdf4zuBsUo34NHo1nHyv2ygdo3jbDX8ryphULyDbI8iy68KUGeLj4L7OvCN6sphULu25hulw+oxAt5ySsy4CxjVYWRahf4JICNXq37YjyZQH3XyYLYP27CEIgGul/ai 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);