Message ID | 20240204072525.1986626-1-gang.li@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-51490-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp235013dyb; Sat, 3 Feb 2024 23:26:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxF8r6AQonncqExqL+VfhUGKum7sj6JqidRYvqSuwfyx+adCu43jijubKbih3RHW3JUsJt X-Received: by 2002:a17:906:32c8:b0:a37:1e9a:c958 with SMTP id k8-20020a17090632c800b00a371e9ac958mr2739323ejk.22.1707031578385; Sat, 03 Feb 2024 23:26:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707031578; cv=pass; d=google.com; s=arc-20160816; b=gI02WCf8LK1HjfS8jivsHR6PI51G2p6TeWCs0wcOFVFdrbiFVD5WyOppXf73P7wWIP dakWmqwehTjmXZ2A478jTom/OVn6/EGHgZj9b3LLHrQO3WC7gKBGVYusxLN6e7oBijeZ aOWicVvIHiUpRMftY4zA1AoYdsdR1DixSIkVDy5OYukzBnGiir5X9NQhjsTJ5Fypi6fu w5MTBMacaRnv2CgdBTaZ5wZ6aW2zp7TsIRX5WZCxl04RBXuzm+gk20F8GjsVUe2QX8TZ MQfiRziXtTgT35YOsIk6aeCCTTbEsJo0z/TQdVcoKpsPSP6vHyZyB2B/ba9Wj+T+nSte 7xkA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=XjdCCFvLZWXa+p6w0grRH8helkAbuAcZzUNjMEzv69g=; fh=0NI+W2xayLRKrXp2utk6uL3kvnkXR512J4WHZi22HjM=; b=RymSiIHP3DTCxUahqbXL5sIvlr296TOLmhzu/ifhedFCE2uFOHy55EZ24vFyFJHU/7 a9gQ2LVFUsDkSu4xtpZV1AmXo7+qqieGSPKC88RkRJHCTOhsdp87g/+sC8kmt/Y9llRH /ZbXxBZO5FLK+hgvpfqN0lmR6sIWIgWRyD9CqL30FE9QvpjgLKVDIIX/+wCCqLxj1gek DYrBeh6BzAwvBAVPlNaYiSNGU/TvFH9NnRtHzFC/US5QLNR/kVkt6AbzvbTTExZvxccj msQ7s+1CKMd6R4ZxF8FG3cZD8uZmDcvOxfdi0OcA+dfIB5tV6cv37AtmlZeQPqEad9Se KKLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="jTSi/5ss"; 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-51490-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51490-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCWg01qQkWYfdCUCttvQD5g+ZVyO6GuLXmDYurkmD9pg/xsdgAUIwzoKHpkZ0RwAaIh+Xof8pY2yCGa224SHZ90UdbpS4w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id br16-20020a170906d15000b00a372cc4e4afsi1956360ejb.123.2024.02.03.23.26.18 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 23:26:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51490-ouuuleilei=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="jTSi/5ss"; 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-51490-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51490-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EC5071F21BA5 for <ouuuleilei@gmail.com>; Sun, 4 Feb 2024 07:26:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41A27BE65; Sun, 4 Feb 2024 07:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jTSi/5ss" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 28FEE8F72 for <linux-kernel@vger.kernel.org>; Sun, 4 Feb 2024 07:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707031560; cv=none; b=WgrR1LKqf99v6P4WzH/fpuvyDxN/5llubSmnG6YFDKM9Tv+RATF9EGYkMWVDgXAS5psXNc/eNICRE0k7ihqd0mSJQxzMb/Jw4vMvYyUAh7H95J0b6DTLHju4AUD25s7VTcf6MdR0HnpLgDGa+yPkhasu5KQnX6QalPkTAEXDE4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707031560; c=relaxed/simple; bh=XCrF050gBkNnvs/zW5kUe24x6uor+IW7v7gGuky9BFs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=b4MlbeB+/XdFXiX+h+XyPZSig34C2Nfos3S9girNTA1fgpKQgyuZ5sbjDD5hRkEGSGMpUxKn3Gjhr//Qb/nmjiDHTIk/tYeAai4v1YZzCRw5cSxMeZ8FIKiNWOc61B1YZdS5+hQxrcdHxbWL22VdQO7baBgYY16qBl8NkzywPfU= 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=jTSi/5ss; arc=none smtp.client-ip=95.215.58.176 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=1707031555; 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; bh=XjdCCFvLZWXa+p6w0grRH8helkAbuAcZzUNjMEzv69g=; b=jTSi/5ssnW+B2nZEdWTkraj+NF2JCrWuvd7e4JHe7/hl/HGvc17fKTh1a9EEBhUmJ1eZuB IV+7vK5AwGnnzGePtP11nEJeG/oz0XWhA7hfYhzPjMNdi0smuMpmmce88hja0a/2MpU6BR GhRfx1q4MHJCktItjGy6MfTjjsUQkkc= From: Gang Li <gang.li@linux.dev> To: Andrew Morton <akpm@linux-foundation.org>, Muchun Song <muchun.song@linux.dev>, Gang Li <gang.li@linux.dev>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Randy Dunlap <rdunlap@infradead.org>, kernel test robot <lkp@intel.com> Cc: Gang Li <ligang.bdlg@bytedance.com> Subject: [PATCH 1/1] hugetlb: fix CONFIG_PADATA dependency for non-SMP system Date: Sun, 4 Feb 2024 15:25:24 +0800 Message-Id: <20240204072525.1986626-1-gang.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789952344300929380 X-GMAIL-MSGID: 1789952344300929380 |
Series |
[1/1] hugetlb: fix CONFIG_PADATA dependency for non-SMP system
|
|
Commit Message
Gang Li
Feb. 4, 2024, 7:25 a.m. UTC
Randy Dunlap and kernel test robot reported a warning:
```
WARNING: unmet direct dependencies detected for PADATA
Depends on [n]: SMP [=n]
Selected by [y]:
- HUGETLBFS [=y] && (X86 [=y] || SPARC64 || ARCH_SUPPORTS_HUGETLBFS [=n] || BROKEN [=n]) && (SYSFS [=y] || SYSCTL [=n])
```
hugetlb parallelization depends on PADATA, and PADATA depends on SMP, so
when the SMP config is disabled, the dependency of hugetlb on padata
should be downgraded to single thread.
Fixes: f2f635264b98 ("hugetlb: have CONFIG_HUGETLBFS select CONFIG_PADATA")
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Closes: https://lore.kernel.org/lkml/ec5dc528-2c3c-4444-9e88-d2c48395b433@infradead.org/
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202402020454.6EPkP1hi-lkp@intel.com/
Signed-off-by: Gang Li <ligang.bdlg@bytedance.com>
```
Hi Andrew, this fix patch is based on mm/mm-unstable.
Thanks!
```
---
fs/Kconfig | 2 +-
mm/hugetlb.c | 9 ++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
Comments
On 2024/2/4 15:25, Gang Li wrote: > Randy Dunlap and kernel test robot reported a warning: > > ``` > WARNING: unmet direct dependencies detected for PADATA > Depends on [n]: SMP [=n] > Selected by [y]: > - HUGETLBFS [=y] && (X86 [=y] || SPARC64 || ARCH_SUPPORTS_HUGETLBFS [=n] || BROKEN [=n]) && (SYSFS [=y] || SYSCTL [=n]) > ``` > > hugetlb parallelization depends on PADATA, and PADATA depends on SMP, so > when the SMP config is disabled, the dependency of hugetlb on padata > should be downgraded to single thread. > > Fixes: f2f635264b98 ("hugetlb: have CONFIG_HUGETLBFS select CONFIG_PADATA") > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Closes: https://lore.kernel.org/lkml/ec5dc528-2c3c-4444-9e88-d2c48395b433@infradead.org/ > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/oe-kbuild-all/202402020454.6EPkP1hi-lkp@intel.com/ > Signed-off-by: Gang Li <ligang.bdlg@bytedance.com> > ``` > Hi Andrew, this fix patch is based on mm/mm-unstable. > Thanks! > ``` > --- > fs/Kconfig | 2 +- > mm/hugetlb.c | 9 ++++++++- > 2 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/fs/Kconfig b/fs/Kconfig > index 3abc107ab2fbd..f2bc73fc0417e 100644 > --- a/fs/Kconfig > +++ b/fs/Kconfig > @@ -261,7 +261,7 @@ menuconfig HUGETLBFS > depends on X86 || SPARC64 || ARCH_SUPPORTS_HUGETLBFS || BROKEN > depends on (SYSFS || SYSCTL) > select MEMFD_CREATE > - select PADATA > + select PADATA if SMP I don't think it is a clear way to fix this. If someone want to use PADATA in a non-SMP system, he should be carefully to handle the non-SMP case himself. I think the better way is to make PADATA handle the non-SMP case, I think it should be easy for it, which could just call ->thread_fn() many times instead of creating many threads in the non-SMP case. Thanks. > help > hugetlbfs is a filesystem backing for HugeTLB pages, based on > ramfs. For architectures that support it, say Y here and read > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index bf3d5dfb921e6..1b01b244fb50b 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3457,6 +3457,7 @@ static void __init gather_bootmem_prealloc_node(unsigned long start, unsigned lo > > static void __init gather_bootmem_prealloc(void) > { > +#ifdef CONFIG_PADATA > struct padata_mt_job job = { > .thread_fn = gather_bootmem_prealloc_node, > .fn_arg = NULL, > @@ -3469,6 +3470,9 @@ static void __init gather_bootmem_prealloc(void) > }; > > padata_do_multithreaded(&job); > +#else > + gather_bootmem_prealloc_node(0, 0, NULL); > +#endif > } > > static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) > @@ -3568,6 +3572,7 @@ static unsigned long __init hugetlb_gigantic_pages_alloc_boot(struct hstate *h) > > static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) > { > +#ifdef CONFIG_PADATA > struct padata_mt_job job = { > .fn_arg = h, > .align = 1, > @@ -3600,7 +3605,9 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) > job.max_threads = num_node_state(N_MEMORY) * 2; > job.min_chunk = h->max_huge_pages / num_node_state(N_MEMORY) / 2; > padata_do_multithreaded(&job); > - > +#else > + hugetlb_pages_alloc_boot_node(0, h->max_huge_pages, h); > +#endif > return h->nr_huge_pages; > } >
On 2024/2/4 15:44, Muchun Song wrote: > I don't think it is a clear way to fix this. If someone want to > use PADATA in a non-SMP system, he should be carefully to handle > the non-SMP case himself. I think the better way is to make PADATA > handle the non-SMP case, I think it should be easy for it, which > could just call ->thread_fn() many times instead of creating many > threads in the non-SMP case. > > Thanks. > Sounds good, I'll take a look at padata and send a new patch.
On 2024/2/4 15:48, Gang Li wrote: > On 2024/2/4 15:44, Muchun Song wrote: >> I don't think it is a clear way to fix this. If someone want to >> use PADATA in a non-SMP system, he should be carefully to handle >> the non-SMP case himself. I think the better way is to make PADATA >> handle the non-SMP case, I think it should be easy for it, which >> could just call ->thread_fn() many times instead of creating many >> threads in the non-SMP case. >> >> Thanks. >> > > Sounds good, I'll take a look at padata and send a new patch. 1. delete the dependency on SMP PADATA only depends on workqueue and completion. It works well with !SMP currently but has no performance benefits. What we can do is make PADATA handle the non-SMP case more elegantly. PADATA has two parts: "Running Multithreaded Jobs" and "Running Serialized Jobs". "Running Multithreaded Jobs", which hugetlb parallelization relies on can be easily deparallelize through this patch: ``` @@ -495,7 +495,7 @@ void __init padata_do_multithreaded(struct padata_mt_job *job) nworks = max(job->size / max(job->min_chunk, job->align), 1ul); nworks = min(nworks, job->max_threads); - if (nworks == 1) { + if (nworks == 1 || !IS_ENABLED(CONFIG_SMP)) { /* Single thread, no coordination needed, cut to the chase. */ job->thread_fn(job->start, job->start + job->size, job->fn_arg); return; ``` However, "Running Serialized Jobs" is more challenging due to its various workers queuing each other, making it more complex than "Running Multithreaded Jobs." I am currently in the process of deciphering the code. To eliminate kconfig warnings, other methods could be considered: 2. Split hugetlb parallelization into a separate kconfig. 3. Wrap hugetlb parallelization with SMP or PADATA macros (already ruled out). 4. Split PADATA into PADATA_SERIALIZED and PADATA_MULTITHREADED (too heavy). Anyway, this is only FYI. I will continue exploring how to deparallelize "Running Serialized Jobs."
> On Feb 5, 2024, at 14:55, Gang Li <gang.li@linux.dev> wrote: > > > On 2024/2/4 15:48, Gang Li wrote: >> On 2024/2/4 15:44, Muchun Song wrote: >>> I don't think it is a clear way to fix this. If someone want to >>> use PADATA in a non-SMP system, he should be carefully to handle >>> the non-SMP case himself. I think the better way is to make PADATA >>> handle the non-SMP case, I think it should be easy for it, which >>> could just call ->thread_fn() many times instead of creating many >>> threads in the non-SMP case. >>> >>> Thanks. >>> >> Sounds good, I'll take a look at padata and send a new patch. > > 1. delete the dependency on SMP > > PADATA only depends on workqueue and completion. It works well with !SMP > currently but has no performance benefits. What we can do is make PADATA > handle the non-SMP case more elegantly. > > PADATA has two parts: "Running Multithreaded Jobs" and "Running > Serialized Jobs". > > "Running Multithreaded Jobs", which hugetlb parallelization relies on > can be easily deparallelize through this patch: > > ``` > @@ -495,7 +495,7 @@ void __init padata_do_multithreaded(struct padata_mt_job *job) > nworks = max(job->size / max(job->min_chunk, job->align), 1ul); > nworks = min(nworks, job->max_threads); > > - if (nworks == 1) { > + if (nworks == 1 || !IS_ENABLED(CONFIG_SMP)) { > /* Single thread, no coordination needed, cut to the chase. */ > job->thread_fn(job->start, job->start + job->size, job->fn_arg); > return; > ``` > > However, "Running Serialized Jobs" is more challenging due to its > various workers queuing each other, making it more complex than "Running > Multithreaded Jobs." I am currently in the process of deciphering the > code. Actually, I did not get it. Why the above code cannot work? The above code already make it serialized in one call, right? What do I miss here? Thanks. > > To eliminate kconfig warnings, other methods could be considered: > > 2. Split hugetlb parallelization into a separate kconfig. > 3. Wrap hugetlb parallelization with SMP or PADATA macros (already ruled out). > 4. Split PADATA into PADATA_SERIALIZED and PADATA_MULTITHREADED (too heavy). > > Anyway, this is only FYI. I will continue exploring how to deparallelize > "Running Serialized Jobs."
On 2024/2/5 15:37, Muchun Song wrote: > Actually, I did not get it. Why the above code cannot work? The above > code already make it serialized in one call, right? What do I miss here? > > Thanks. > PADATA consists of two distinct functionality: One part is `padata_do_multithreaded`, which disregards order and simply divides tasks into several groups for parallel execution. My patch use `padata_do_multithreaded`. The other part is composed of a set of APIs that, while handling data in an out-of-order parallel manner, can eventually return the data with ordered sequence. Only `crypto/pcrypt.c` use them. I guess these APIs are designed specifically for `crypto/pcrypt.c`. ``` padata_alloc padata_alloc_shell padata_do_parallel padata_do_serial padata_free_shell padata_free ```
diff --git a/fs/Kconfig b/fs/Kconfig index 3abc107ab2fbd..f2bc73fc0417e 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -261,7 +261,7 @@ menuconfig HUGETLBFS depends on X86 || SPARC64 || ARCH_SUPPORTS_HUGETLBFS || BROKEN depends on (SYSFS || SYSCTL) select MEMFD_CREATE - select PADATA + select PADATA if SMP help hugetlbfs is a filesystem backing for HugeTLB pages, based on ramfs. For architectures that support it, say Y here and read diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bf3d5dfb921e6..1b01b244fb50b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3457,6 +3457,7 @@ static void __init gather_bootmem_prealloc_node(unsigned long start, unsigned lo static void __init gather_bootmem_prealloc(void) { +#ifdef CONFIG_PADATA struct padata_mt_job job = { .thread_fn = gather_bootmem_prealloc_node, .fn_arg = NULL, @@ -3469,6 +3470,9 @@ static void __init gather_bootmem_prealloc(void) }; padata_do_multithreaded(&job); +#else + gather_bootmem_prealloc_node(0, 0, NULL); +#endif } static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) @@ -3568,6 +3572,7 @@ static unsigned long __init hugetlb_gigantic_pages_alloc_boot(struct hstate *h) static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) { +#ifdef CONFIG_PADATA struct padata_mt_job job = { .fn_arg = h, .align = 1, @@ -3600,7 +3605,9 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h) job.max_threads = num_node_state(N_MEMORY) * 2; job.min_chunk = h->max_huge_pages / num_node_state(N_MEMORY) / 2; padata_do_multithreaded(&job); - +#else + hugetlb_pages_alloc_boot_node(0, h->max_huge_pages, h); +#endif return h->nr_huge_pages; }