From patchwork Fri Jan 26 15:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 192669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:106:343:edcb with SMTP id ju23csp18951dyc; Fri, 26 Jan 2024 07:44:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuH4I/Y1tzJpQagRBoej/E7wA5P7iIW1Slo2SUaAfVqPKr3Y//hlwvDPDzD4szp2eahqJZ X-Received: by 2002:a05:6870:a452:b0:214:2a08:897d with SMTP id n18-20020a056870a45200b002142a08897dmr1965538oal.46.1706283871973; Fri, 26 Jan 2024 07:44:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706283871; cv=pass; d=google.com; s=arc-20160816; b=RwT1I3bcsv9OWMWNTOGldLIl4KM1vun+0X4NBV6KzXMBlnri3u5l3P4KvF1q7DhuN9 3nWtjMfIrAcI3yW+9EFqlabpI0qwDpy7uc6oY0PUcHqmk5jQpprLuAyOYEKbsoQfEEo0 Twa+zQxyWv8lM0SXuUYT6vB0QXaEdUDPmBmWGQQYBCo+6mMU5kOFgeLUvVvVRVo2c4d7 8lbCh1zvywP5F/tnTtHugbmYYdV8HdU9iRvQkWBCgZQT+dJq6HUj7ckb9FKdAIvKAh86 sYkmqRgFgNVs9z35OiCact/ECyIU6cUHvmQmo2tepXLsLLfMvmWA49N0eDL9yM2rtvO5 gvlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RmrMLc6E2IVqKhV8ZhRU9VeFjN80rDuhVxh0u6+eJMA=; fh=5n5b5+XOwLgGNDePhvfXysty56rnkWOs9jaHEODdVeE=; b=nSlHuzqGrNWIRAa2boveggY1zk0u3jUG2uQ0qyQXRjGwh7D199/fXbfPXTD6UoKS8Q 0vqfxXBzjno6DjV+3/ygdrp0vj8hvtxLUyhVrw3h8UT4DcRJvW4M9/GotAwnpzItIvfA 627mkofPYWPUdtv9CTVUxwxOpJMLRbRyotgT/E+GKKojKoH2h0v0HoidSc4T3bBEMkOn yjKj4ODBadDVjoIc72f8MVAb1TOpzIZH63Lgs4jDGigXaQdvlYpkmJ6MeFRWHP2c87UO LIXQyE29RgSzUf+MF817wCXawTkg7nipurI1W59iopHX/2fUsDuLzXmV09bXUDhCjiQ9 +47w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wyYlzc34; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-40271-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40271-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 7-20020a630d47000000b005cfbf651e25si1260310pgn.111.2024.01.26.07.44.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 07:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40271-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wyYlzc34; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-40271-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40271-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 41262B2783D for ; Fri, 26 Jan 2024 15:26:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B1321D54C; Fri, 26 Jan 2024 15:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wyYlzc34" Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 162791DFE1 for ; Fri, 26 Jan 2024 15:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706282718; cv=none; b=uKyOHJuQF5R6Zb8yvZIOwS5Ct1h5LPl+mmtP5CHczLemnpAv4Li8pLjZSglDan6qnoMKKkODvImBFH0mxZxtO9WF3+gJiOhNBVa9pgoA417rd0K6DjjrfnA6LAtSMdZFSl/N42/aPlG3eCXOh5VG0MOuMwYWw+NNffJQpv0Jgx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706282718; c=relaxed/simple; bh=A7DeycgaAylfyaGHNXPeWa+Y5alq9KqCBr3DPXdOYWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kCeFITXaapkNiwwNqgJxqwXW1fzVogXfo4jlWK+oVR475/z5/thytWCMOefS9q3V0MqCONERFGtf2ib0/FotJ8o646K1ARMimk+VfokEvmL7a5FjI1F5Jtel2XzVdhhBZv9N7fkNry8yuNgdh0TzJMYRU8tRk6UxIxuCotpNrtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wyYlzc34; arc=none smtp.client-ip=95.215.58.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706282715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmrMLc6E2IVqKhV8ZhRU9VeFjN80rDuhVxh0u6+eJMA=; b=wyYlzc34oaBoDa42QsBypygqXrsoGKHAfb+deg3SuOPDAmbhiv09g6PCqoW3PG4AJbHsVA hz3+64qyLRhxOGW5ACJiiomiu2sHCxRKxpEOC4gAbDn/H6YePZadVNJJ/H4FtQXG7IOOjG 0L+u9CTOwvqS2DBzIXlE1TKDr+2kLOc= From: Gang Li To: David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v5 3/7] padata: dispatch works on different nodes Date: Fri, 26 Jan 2024 23:24:07 +0800 Message-Id: <20240126152411.1238072-4-gang.li@linux.dev> In-Reply-To: <20240126152411.1238072-1-gang.li@linux.dev> References: <20240126152411.1238072-1-gang.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789168317610303558 X-GMAIL-MSGID: 1789168317610303558 When a group of tasks that access different nodes are scheduled on the same node, they may encounter bandwidth bottlenecks and access latency. Thus, numa_aware flag is introduced here, allowing tasks to be distributed across different nodes to fully utilize the advantage of multi-node systems. Signed-off-by: Gang Li Tested-by: David Rientjes Reviewed-by: Muchun Song Reviewed-by: Tim Chen --- include/linux/padata.h | 2 ++ kernel/padata.c | 14 ++++++++++++-- mm/mm_init.c | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/linux/padata.h b/include/linux/padata.h index 495b16b6b4d72..8f418711351bc 100644 --- a/include/linux/padata.h +++ b/include/linux/padata.h @@ -137,6 +137,7 @@ struct padata_shell { * appropriate for one worker thread to do at once. * @max_threads: Max threads to use for the job, actual number may be less * depending on task size and minimum chunk size. + * @numa_aware: Distribute jobs to different nodes with CPU in a round robin fashion. */ struct padata_mt_job { void (*thread_fn)(unsigned long start, unsigned long end, void *arg); @@ -146,6 +147,7 @@ struct padata_mt_job { unsigned long align; unsigned long min_chunk; int max_threads; + bool numa_aware; }; /** diff --git a/kernel/padata.c b/kernel/padata.c index 179fb1518070c..e3f639ff16707 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -485,7 +485,8 @@ void __init padata_do_multithreaded(struct padata_mt_job *job) struct padata_work my_work, *pw; struct padata_mt_job_state ps; LIST_HEAD(works); - int nworks; + int nworks, nid; + static atomic_t last_used_nid __initdata; if (job->size == 0) return; @@ -517,7 +518,16 @@ void __init padata_do_multithreaded(struct padata_mt_job *job) ps.chunk_size = roundup(ps.chunk_size, job->align); list_for_each_entry(pw, &works, pw_list) - queue_work(system_unbound_wq, &pw->pw_work); + if (job->numa_aware) { + int old_node = atomic_read(&last_used_nid); + + do { + nid = next_node_in(old_node, node_states[N_CPU]); + } while (!atomic_try_cmpxchg(&last_used_nid, &old_node, nid)); + queue_work_node(nid, system_unbound_wq, &pw->pw_work); + } else { + queue_work(system_unbound_wq, &pw->pw_work); + } /* Use the current thread, which saves starting a workqueue worker. */ padata_work_init(&my_work, padata_mt_helper, &ps, PADATA_WORK_ONSTACK); diff --git a/mm/mm_init.c b/mm/mm_init.c index 2c19f5515e36c..549e76af8f82a 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2231,6 +2231,7 @@ static int __init deferred_init_memmap(void *data) .align = PAGES_PER_SECTION, .min_chunk = PAGES_PER_SECTION, .max_threads = max_threads, + .numa_aware = false, }; padata_do_multithreaded(&job);