Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2126875rdd; Thu, 11 Jan 2024 23:10:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiKpkXXyyXYovH9qKt+CyoBHkXLeQWanw4NiKfqTOFHmojPDaT5ycFF9m2P8I1m7RI6/0o X-Received: by 2002:a05:6512:690:b0:50e:435b:76c4 with SMTP id t16-20020a056512069000b0050e435b76c4mr483307lfe.78.1705043400981; Thu, 11 Jan 2024 23:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705043400; cv=none; d=google.com; s=arc-20160816; b=v2h1fqKvxFrzEJL98vzFJZ3g3AeiZkScoGws8IYNq/opboJe6KsymbGaQb1XAYhWYN RAebSZzBTLJ3+r80+FQsi3HbtVUeGqEwq6NHjuUhHindKl23qea9ZmJPTVwyetAohJ9k Hb1L7okGt7ss2i8fPDhBk/PVEIY34wvhJh7AVQTM835MEEdS5ULb84/veSWVKiax5hz4 /0uHuY5RdY96oSSRFWg1wBqc60WLebNI8VpLDyJjsOpAuKN9HNyZu7THyYeqEhwOMdhS Khjyr/xVQKRQgXhIZe/e8M3KrueuYx1Q0GrxS4tXs1Ot2JGmWnxRPdW2i0FY83NupFNv 5BqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=x1/E36ja6hSjXcFMnhf7nMX3AJMPWbXzIlOegBOBTgw=; fh=Vc6KCepME1OFFaaeCeRtNITb8jCs48pV4Nr9z4ZHg/k=; b=lYCrBc84ho3WthvgYa5f5DBoUwiWdqWGNwyvQEGI5OpO4Gd0GlhTBCTMnFf7kQ3/oZ 15FX5dKkrUM3YVSIpZBRiAv6F8i7JD8IeGo3o78tks0UJ1G4WykHCmgu4o/ZSr4i7qNe UOltXFv8aRwmFxcNUDd3ANFfpxOIG7K+v6ke0NzVxrvTmo01qVuzb7YV2XxRoSD1YhJG XtpRTCQa+lhJ33Qm/MJtZ7POjoSljJ7WcnTjtVtsFV9bC7OsErd4dLyGDWku3TjgJtq5 MENERSL1TyYYy6hQnk9Ept53kb+BCBiUaf0wJCT0sa/e8D1q/DnR4o5OgUBbod/C+XOI Pdfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="rl6/mhHP"; spf=pass (google.com: domain of linux-kernel+bounces-24354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b4-20020a1709062b4400b00a28db64c218si1149724ejg.169.2024.01.11.23.10.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 23:10:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="rl6/mhHP"; spf=pass (google.com: domain of linux-kernel+bounces-24354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24354-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id B5D811F25F53 for ; Fri, 12 Jan 2024 07:10:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 814D35C905; Fri, 12 Jan 2024 07:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rl6/mhHP" Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 E02015C8FB for ; Fri, 12 Jan 2024 07:09:49 +0000 (UTC) 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 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705043387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x1/E36ja6hSjXcFMnhf7nMX3AJMPWbXzIlOegBOBTgw=; b=rl6/mhHP8qss1zJkt8tAb+O2UQRGEreguRM5ECbwehucdUCmiM3gdzMM1AvxJ6bX7sZ25K tKZs7xxGHKIplmLH6QebIJt7P/KRkt3ckrFNsgOC+P31/Re+W92p+KVm7w3R9j9bpYCWaL Zx12flbfZLdvnRGUe7PLpX4I8UkNgSs= Date: Fri, 12 Jan 2024 15:09:18 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3 3/7] padata: dispatch works on different nodes Content-Language: en-US To: Tim Chen Cc: linux-mm@kvack.org, Andrew Morton , Mike Kravetz , David Rientjes , linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, David Hildenbrand , Muchun Song References: <20240102131249.76622-1-gang.li@linux.dev> <20240102131249.76622-4-gang.li@linux.dev> <1d9074955618ea0b4b155701f7c1b8b18a43fa8d.camel@linux.intel.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Gang Li In-Reply-To: <1d9074955618ea0b4b155701f7c1b8b18a43fa8d.camel@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/1/12 01:50, Tim Chen wrote: > On Tue, 2024-01-02 at 21:12 +0800, Gang Li wrote: >> 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 >> --- >> include/linux/padata.h | 3 +++ >> kernel/padata.c | 8 ++++++-- >> mm/mm_init.c | 1 + >> 3 files changed, 10 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/padata.h b/include/linux/padata.h >> index 495b16b6b4d72..f79ccd50e7f40 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 179fb1518070c..1c2b3a337479e 100644 >> --- a/kernel/padata.c >> +++ b/kernel/padata.c >> @@ -485,7 +485,7 @@ 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 = 0; > > If we always start from 0, we may be biased towards the low numbered node, > and not use high numbered nodes at all. Suggest you do > static nid = 0; > When we use `static`, if there are multiple parallel calls to `padata_do_multithreaded`, it may result in an uneven distribution of tasks for each padata_do_multithreaded. We can make the following modifications to address this issue. ``` diff --git a/kernel/padata.c b/kernel/padata.c index 1c2b3a337479e..925e48df6dd8d 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, nid = 0; + int nworks, nid; + static volatile int global_nid = 0; if (job->size == 0) return; @@ -516,12 +517,15 @@ void __init padata_do_multithreaded(struct padata_mt_job *job) ps.chunk_size = max(ps.chunk_size, job->min_chunk); ps.chunk_size = roundup(ps.chunk_size, job->align); + nid = global_nid; list_for_each_entry(pw, &works, pw_list) - if (job->numa_aware) - queue_work_node((++nid % num_node_state(N_MEMORY)), - system_unbound_wq, &pw->pw_work); - else + if (job->numa_aware) { + queue_work_node(nid, system_unbound_wq, &pw->pw_work); + nid = next_node(nid, node_states[N_CPU]); + } else queue_work(system_unbound_wq, &pw->pw_work); + if (job->numa_aware) + global_nid = nid; /* Use the current thread, which saves starting a workqueue worker. */ padata_work_init(&my_work, padata_mt_helper, &ps, PADATA_WORK_ONSTACK); ``` >> >> if (job->size == 0) >> return; >> @@ -517,7 +517,11 @@ 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) >> + queue_work_node((++nid % num_node_state(N_MEMORY)), >> + system_unbound_wq, &pw->pw_work); > > I think we should use nid = next_node(nid, node_states[N_CPU]) instead of > ++nid % num_node_state(N_MEMORY). You are picking the next node with CPU > to handle the job. > > Tim > I agree.