From patchwork Thu Jan 18 12:39: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: 189191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp308906dyb; Thu, 18 Jan 2024 04:40:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8whqOgoYF0GOjXkMGD0ocd9feoinwanaY+59HkSJOF8HM8deu1AKHBCxbLEStJ3wsA7OI X-Received: by 2002:a17:903:2290:b0:1d4:9225:9165 with SMTP id b16-20020a170903229000b001d492259165mr886904plh.23.1705581621929; Thu, 18 Jan 2024 04:40:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705581621; cv=pass; d=google.com; s=arc-20160816; b=AtStG5BTWISceZHau9foTBOAEQNrfg9Oc37hE3sQfJa2+QZigG+0tBOQfoYDXGRKko D7CGtx0gTJQG6MvL7mzkiHJDVHaypq50li8LQnkG7esUqUjVneivO6YsfYfrhFZDBEne L6ZLTfU8Du3R26pkoORSmlR4qEPqjq0YNvqlyYLZN9QvkOFz5fCfWHHyH5/B6FaiST5p jB8YpPZhdVQmOb1vnZxUw8cOf1R44EtU83QYSglL4ueW5QUcYeBrekQ/DvKwIwWmPpes 4nzW75WueP8+ehBZwC7ywJb/rQk2kgyYqaPGsHw3PMAvY5SPDYMrGM5MqyxuDum/b/Md x/QQ== 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=TzFCclyqcCZ/DPTkdiqBlpFX5oAyD0zr6O7wxsAo568=; fh=5n5b5+XOwLgGNDePhvfXysty56rnkWOs9jaHEODdVeE=; b=AbgDv/defJ9OO9fvXFB1HtKclSBrNDS1sGaQQkta6ZwD0YdqlIu2DOv4QDX9+g6IIa JMyGe5jdZutJfwkqPOay8jMy0lniDS1Q82GDXUJ5nMHn4GrxvBZjnjRjOIXpE61NytKq UgrP+HEfArwDNb8DL79Zdv9o9QaPABmUzDvI64kyrcXRn02iUYWvElObzxDy6ROgiQJs nWK3f03RvTQ5PlFJia7VqG1ycxvlG4G1+hvvnQwE3XQJ85G9ltk2d2GrZpjJYq/hl20k H7N9Yd1dmvfexc3QZrz6CfHpbZEvuhMlbQ53Wp5NRtCxiAyCOh924ENwZUoTPxwVP7bM r0PA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="CBfV/dbd"; 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-30106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u6-20020a170902e5c600b001d3e11cf5ebsi1498556plf.34.2024.01.18.04.40.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:40:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="CBfV/dbd"; 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-30106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30106-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AEEF5283D1D for ; Thu, 18 Jan 2024 12:40:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86D392577C; Thu, 18 Jan 2024 12:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="CBfV/dbd" Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 549C525579 for ; Thu, 18 Jan 2024 12:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705581571; cv=none; b=DRZ7hdUOlIOvQ/STKl+Gk5SCgGm9T1DMHCiYS/uqvJjaYFhTc/5VLl6yMAQry1A1nDuPjbBBp//lpfSaX0VAHrpoBNJ5JSlBdsyPlZJuq/+Ri2ELwFQESfPrwyzuSt311cF6bYXVzw7J7AnMgrXEMdkhaeXqam6/2eg1+huvllQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705581571; c=relaxed/simple; bh=hOV1vAKEslMDXnSKKyUL4RMeDVj1M1oqk023PSsPXZ8=; h=X-Report-Abuse:DKIM-Signature:From:To:Cc:Subject:Date:Message-Id: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-Migadu-Flow; b=Cgu1JJDLzWXym5qhRF87pBIEsjx0gKNBioeaA2xnc16LcH+b4R+E9pn/vgnePwaB9LoWaVLgY1CeWCwBbbRIVLBHZ7PcZlkBHH5lYjwK+OGWwtS4bo5Aui5f7B3u4OcVvy1gaNk1IU9dzhJlxUePbZ1jUbvg0MiAuXjkUtkKCj8= 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=CBfV/dbd; arc=none smtp.client-ip=95.215.58.175 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=1705581568; 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=TzFCclyqcCZ/DPTkdiqBlpFX5oAyD0zr6O7wxsAo568=; b=CBfV/dbd2xHdE+F7YOmZ8GE2oRxwpthKTYpZaNj00rjrNcG/Z6lT98VVTzGw5xvY9Iwof6 dbCeWyIuDNqzO2dQE9ps3z2Qxk/A0VvAR8HDZp233bxQeP3YxsFW41WeXH4eB6WEwKUxc2 jA2LqaFNCxUtLsV24/vypYmZim4cKdU= 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 v4 3/7] padata: dispatch works on different nodes Date: Thu, 18 Jan 2024 20:39:07 +0800 Message-Id: <20240118123911.88833-4-gang.li@linux.dev> In-Reply-To: <20240118123911.88833-1-gang.li@linux.dev> References: <20240118123911.88833-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: 1788431955125649007 X-GMAIL-MSGID: 1788431955125649007 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 --- include/linux/padata.h | 3 +++ kernel/padata.c | 14 ++++++++++++-- mm/mm_init.c | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/padata.h b/include/linux/padata.h index 495b16b6b4d7..f79ccd50e7f4 100644 --- a/include/linux/padata.h +++ b/include/linux/padata.h @@ -137,6 +137,8 @@ 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: Dispatch jobs to different nodes. If a node only has memory but + * no CPU, dispatch its jobs to a random CPU. */ struct padata_mt_job { void (*thread_fn)(unsigned long start, unsigned long end, void *arg); @@ -146,6 +148,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 179fb1518070..10eae3f59203 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 = ATOMIC_INIT(0); 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 2c19f5515e36..549e76af8f82 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);