From patchwork Fri Jul 26 21:56:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13743191 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 3746EC3DA49 for ; Fri, 26 Jul 2024 21:57:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCAA46B008A; Fri, 26 Jul 2024 17:57:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7A1E6B0092; Fri, 26 Jul 2024 17:57:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A41D36B0095; Fri, 26 Jul 2024 17:57:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 894586B008A for ; Fri, 26 Jul 2024 17:57:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 00CFE120184 for ; Fri, 26 Jul 2024 21:57:44 +0000 (UTC) X-FDA: 82383266490.21.2E0E5B8 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id BEE94C0006 for ; Fri, 26 Jul 2024 21:57:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jKF0qw8o; spf=pass (imf28.hostedemail.com: domain of frederic@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722031014; 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=cP4RuhNJyr4ZKZ1KAeqILqsev/qbyujBCmDMEijOHM8=; b=onyRcyoGXKZxP1TFESbdbqsr7Sr4VBMGxW7fGO31+fZQZIFWcRlUKKpRq3pQ5mTSxD5u7M pJ+9fy0J5iHiT9FEGyob8o50v/GvHdZNJgQCyIvwzE8kkErQYWWPHQEAqubU49QP5ces/L AdYqqrMxNsXQgM1pnqMiYishUOEn+ZA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722031014; a=rsa-sha256; cv=none; b=tldJpxQet5xZhKi2jXLb+cihXfO2uBzow/vSuA7J7a7KyLWZ1fqiTo8wcMZ5WhsLNJeo3Q n2/0/G4ncV30m6QqPpSrrgaEOw45TsNGBVVCI64iKJZZ/f9vSqFedpI53bfCbAWQ648DcS /u+OU9pTQrm1cRWWjL+Sv3Z57SDfaVw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jKF0qw8o; spf=pass (imf28.hostedemail.com: domain of frederic@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 46ACDCE1951; Fri, 26 Jul 2024 21:57:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFBB2C4AF0E; Fri, 26 Jul 2024 21:57:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722031059; bh=Rndu056GW69+sdbAKM3F/CfIuWiCWMVJcK3IHpS2rDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jKF0qw8oA9DB/ULKFIjWqBbIOivCNKNnP+icJQt71lrPxYLykaWaAGlKghIpOZukx fb58LWldjmjvwQJ8wN4PuM2kjFU9SJrJ0EQAa5gu2Y6Y6vor0u0/bX79kSl5BiQouI izJpmQ21q4aeCG1vc1o7OLlVRd41dYSzwgoq6ZMqQj4V1yb4DnBw3ecF9leZKgYXsx vV6HUhfxUkd+67VNqXhahAUB071lXMNcM8UxLLi/e8aPVCHWvrijo96H21LzJW8fZY zUAm9K9yimYovCNXHgUrc0q0g0ZhyzvyFhcNRS66sqXsaIdUtmQc8VnJ1pN3JpEHYu zVLO0zCMmrnRA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Michal Hocko , Vlastimil Babka , Andrew Morton , linux-mm@kvack.org, Peter Zijlstra , Thomas Gleixner Subject: [RFC PATCH 13/20] mm: Make Kcompactd use kthread's preferred affinity Date: Fri, 26 Jul 2024 23:56:49 +0200 Message-ID: <20240726215701.19459-14-frederic@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240726215701.19459-1-frederic@kernel.org> References: <20240726215701.19459-1-frederic@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BEE94C0006 X-Stat-Signature: fuq63sbza1q3j9xkgfq1xe1b5yokcimg X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722031062-433040 X-HE-Meta: U2FsdGVkX1+qzLv8KP8yYyJYoOtktoNy+sl86gCDc0ZwMxAkOVEGTnYjYDaOyIAXL5dcMCs41E047RjPL8fhZsPWCmAhRWMmmofViWkHmWvEGAT3bSnQzdBG1c4aCZdJaVfvg8D/KhIZwHNDWaml4nn7Zatmx+NI30sJaCWMWVcPXIvDL1r63xbzz7aOIlPr4tCxJwlWIbe3jEUq9gaz9i7CTy/+7HTv8VeJkD6BjH5eALv7JaSF4hWHlqkgTcJLQUJpTLiA5hS+2o/kjtRO0gzWK+ncNQMoJ9+lUpAAIqKwFfn0fhQGII88qny0jAXsXryVLbCD2KAPUS1HMQtW8vtXMYW5Bpd+CGWh48mMrc1i5J5erKD0h0F7z24e2U0J+UjUuDckXbzbvz6fIp+nIKz+CoLx0Io+s2kVvH8Sn4tTYx1JTGMqP091oQy26iSGll1pCflMUxMV9kwN9hOJM0DEmM0QYqEaeCcndCtvZirzALLFYoKbp2L4EDcH74sNFhQW6hxNC7EUQGc8l4gRHfCWed03HIxSt4G9KzCspzv/zKkHBUe0H/EV7hw+FAdWBhxYVzt5yklaPMnF1LBjFQYpbnk6kZ1DMh8AhlJBzHNf95knF5xQ21YH55f1sfLE7civC8qnmvPV1oGies0Kt9c5swsXSuEQAKMv/9sDpF6GGcB6PrMl4uJapEChLF1YU2l2G/9gEqms0jgfzJ1OSUMXkibAING7QMmw30I1Wv/beKhfsSpmBMIsNLy5AqbZJhArnjD47NeFvNoRwJ2+ZieuDtlnNutVWsmrLv77Cu02gWlALfWRVeZ4H0RhuWGGWWofG00yfMkuImoCogKi6jfh0sRfzso5o7ofpwUeW99ed6f91haYwpTCeBds05IatllWB/wcWV4VFueuae2VPkfR+z/LxDc+FHGl4/OrmGtCUHHaMomSqVgVp0Yr2qO1Lu/OSY55MZih+QTbWi+ COfHRaPh qozh6C+wle5oOKVfaae8qTQu4FZkllKHje26GE/uHJrLXMNzsIZFQpH3X+GoA8yTjbXNAK8ok4lGDhPMwWqsS4fCDGsUHTGLvuVJXlzbwYXTNz2m2KtEf5+o7qjW/uwS4mzdCW9+ZVdD/GkaBlElsUcOAy/zkVZxplAsrD6QXsN+V0OsP4WTqKizvDLoyYEzRKy+oU3tfZ+FNjWkzNRrw4cq7XmoZgn2AEI7aQZV62qUgdYM= 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: Now that kthreads have an infrastructure to handle preferred affinity against CPU hotplug and housekeeping cpumask, convert Kcompactd to use it instead of handling halfway all the constraints by itself. Signed-off-by: Frederic Weisbecker Acked-by: Vlastimil Babka --- mm/compaction.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 739b1bf3d637..64a6486f06e1 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,11 +3252,13 @@ void __meminit kcompactd_run(int nid) if (pgdat->kcompactd) return; - pgdat->kcompactd = kthread_run(kcompactd, pgdat, "kcompactd%d", nid); + pgdat->kcompactd = kthread_create(kcompactd, pgdat, "kcompactd%d", nid); if (IS_ERR(pgdat->kcompactd)) { pr_err("Failed to start kcompactd on node %d\n", nid); pgdat->kcompactd = NULL; } + kthread_affine_preferred(pgdat->kcompactd, cpumask_of_node(pgdat->node_id)); + 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(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);