From nobody Thu Apr 2 20:28:05 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 778A9139D0A for ; Fri, 13 Feb 2026 03:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952514; cv=none; b=NxaxMrj+ERwWw8UCod7QRaespbwPxQdR754OPwv2NFPj12vbriXKX9ThDfWg57MFNSG+nllfAgIvVS3L7liL6C+voqcOty9K3xVbAwgaHY5PeCRZWR+caNb1gwn6YxfjF/AAvFPDJ47zjUp8ID0EuXA2cF+hGT3xl6cYsA/FWFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952514; c=relaxed/simple; bh=7gZTYvCYms6JLg4kbg3LMUFIljecloyM93oJfeULTjg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NyTmzwsEFjA3mGRjY2ZX0TV+olrDsI1wEkxglHO1+QcxRLpdv/u3lQk9YFbaBHOFTC36Fg2BPbnmAz2yCz146CvHxFX4SAs+wVLszbNqknV/Iiq1ZptryCB7inXywx688MJsc9sLH7lAsgm9KFOo00HZY2P5ku7DzR2Y/YiPOtU= 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=sOqk3mV9; arc=none smtp.client-ip=91.218.175.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sOqk3mV9" 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=1770952510; 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=YQcMr+CuWLq8RG6gUzwSk4dQyB0LcYdk73WHFDu273k=; b=sOqk3mV9WlQqXdMQwZ6Lco3YMe2/IkNAcjtkmda7mHtyryUjfh5aOEyRHPveorUpvx/7Jf kfepKjdK+ZZJo4opukW0UyDdg43bVeu3rKodGMm6MBjEmMLWV/KmwVrwDIDawKRh3uaKXE qzy0wmMNjBBRpXgf76tDvHCAZ7kd540= From: sunliming@linux.dev To: song@kernel.org, yukuai@fnnas.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, sunliming Subject: [PATCH v3 1/3] lib/raid6: Divide the raid6 algorithm selection process into two parts Date: Fri, 13 Feb 2026 11:14:17 +0800 Message-Id: <20260213031419.125069-2-sunliming@linux.dev> In-Reply-To: <20260213031419.125069-1-sunliming@linux.dev> References: <20260213031419.125069-1-sunliming@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: sunliming Divide the RAID6 algorithm selection process into two parts: fast selection and benchmark selection. To prepare for the asynchronous processing of the benchmark phase. Signed-off-by: sunliming --- lib/raid6/algos.c | 76 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index 799e0e5eac26..c21e3ad99d97 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c @@ -152,8 +152,32 @@ static inline const struct raid6_recov_calls *raid6_ch= oose_recov(void) return best; } =20 -static inline const struct raid6_calls *raid6_choose_gen( - void *(*const dptrs)[RAID6_TEST_DISKS], const int disks) +/* Quick selection: select the highest priority valid algorithm. */ +static inline int raid6_choose_gen_fast(void) +{ + int ret =3D 0; + const struct raid6_calls *const *algo; + const struct raid6_calls *best =3D NULL; + + for (best =3D NULL, algo =3D raid6_algos; *algo; algo++) + if (!best || (*algo)->priority > best->priority) + if (!(*algo)->valid || (*algo)->valid()) + best =3D *algo; + + if (best) { + raid6_call =3D *best; + pr_info("raid6: skipped pq benchmark and selected %s\n", + best->name); + } else { + pr_err("raid6: No valid algorithm found even for fast selection!\n"); + ret =3D -EINVAL; + } + + return ret; +} + +static inline const struct raid6_calls *raid6_gen_benchmark( + void *(*const dptrs)[RAID6_TEST_DISKS], const int disks) { unsigned long perf, bestgenperf, j0, j1; int start =3D (disks>>1)-1, stop =3D disks-3; /* work on the second half = of the disks */ @@ -165,11 +189,6 @@ static inline const struct raid6_calls *raid6_choose_g= en( if ((*algo)->valid && !(*algo)->valid()) continue; =20 - if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) { - best =3D *algo; - break; - } - perf =3D 0; =20 preempt_disable(); @@ -200,12 +219,6 @@ static inline const struct raid6_calls *raid6_choose_g= en( =20 raid6_call =3D *best; =20 - if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) { - pr_info("raid6: skipped pq benchmark and selected %s\n", - best->name); - goto out; - } - pr_info("raid6: using algorithm %s gen() %ld MB/s\n", best->name, (bestgenperf * HZ * (disks - 2)) >> @@ -239,15 +252,13 @@ static inline const struct raid6_calls *raid6_choose_= gen( /* Try to pick the best algorithm */ /* This code uses the gfmul table as convenient data set to abuse */ =20 -int __init raid6_select_algo(void) +static int raid6_choose_gen_benmark(void) { const int disks =3D RAID6_TEST_DISKS; - const struct raid6_calls *gen_best; - const struct raid6_recov_calls *rec_best; char *disk_ptr, *p; void *dptrs[RAID6_TEST_DISKS]; - int i, cycle; + int i, cycle, ret =3D 0; =20 /* prepare the buffer and fill it circularly with gfmul table */ disk_ptr =3D (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER); @@ -269,15 +280,36 @@ int __init raid6_select_algo(void) if ((disks - 2) * PAGE_SIZE % 65536) memcpy(p, raid6_gfmul, (disks - 2) * PAGE_SIZE % 65536); =20 - /* select raid gen_syndrome function */ - gen_best =3D raid6_choose_gen(&dptrs, disks); + gen_best =3D raid6_gen_benchmark(&dptrs, disks); + if (!gen_best) + ret =3D -EINVAL; + + free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER); + + return ret; +} + +int __init raid6_select_algo(void) +{ + int ret =3D 0; + const struct raid6_recov_calls *rec_best =3D NULL; + + /* select raid gen_syndrome functions */ + if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) + ret =3D raid6_choose_gen_fast(); + else + ret =3D raid6_choose_gen_benmark(); + + if (ret < 0) + goto out; =20 /* select raid recover functions */ rec_best =3D raid6_choose_recov(); + if (!rec_best) + ret =3D -EINVAL; =20 - free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER); - - return gen_best && rec_best ? 0 : -EINVAL; +out: + return ret; } =20 static void raid6_exit(void) --=20 2.25.1 From nobody Thu Apr 2 20:28:05 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 F1E331E49F for ; Fri, 13 Feb 2026 03:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952521; cv=none; b=pxoYZX0LazGAg3iYcD8vOyOD+Gerxk2GWFQjqiwQiUjw+DgKazC7u07Otf77Emlpv7jqKS6GkYn1X51s8zRmEEBM86+1PmwZ/6ifkp+9SVYaufATgo+EUN1pEeJEdOQrUqT2UD20CiUW2k48wMJ0V3QVFjb7rGi1FlhSEP4GXh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952521; c=relaxed/simple; bh=tRjI5SXiH5BCcAaQLg7tSNGUURQ24BdhEkmdLr7ZCZA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ldqht+0cnnq7WlL+qCM+YifELvB1QFbwvhpTTwcLrnBX22naVrdTRM4JjyqeYY80BFNMJ2NFn9J6CV754QLpSdpntmREOmZJDQ8KDFZ9Up7mkT8rOabAXY0M2R73WAUK4Z/Wd9dNwFAlhWk/hTHAPQ/2RZoYxlbG2ZQroyDeQjc= 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=qyyMp0O1; arc=none smtp.client-ip=91.218.175.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qyyMp0O1" 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=1770952518; 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=FMLAU+TNwvgizddZfji1MH8+7sBrNmHxaW+imWLM8p4=; b=qyyMp0O1xPP39w8UoSHO3SCFVW9V9IGFVulPWmMM6lzcj2JxtMnzwREzEX54J7MhOHlnpT dYQ69IR3cKGEkPiR2gUUMufmluVIyXe64BLxyWAc9ejU5C/XpFoVRP2AGzBlMROutHR5D0 ydU4bj6ywbmh6oqzaPfT5zmRg/4Enqw= From: sunliming@linux.dev To: song@kernel.org, yukuai@fnnas.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, sunliming Subject: [PATCH v3 2/3] lib/raid6: Optimizing the raid6_select_algo time through asynchronous processing Date: Fri, 13 Feb 2026 11:14:18 +0800 Message-Id: <20260213031419.125069-3-sunliming@linux.dev> In-Reply-To: <20260213031419.125069-1-sunliming@linux.dev> References: <20260213031419.125069-1-sunliming@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: sunliming Optimizing the raid6_select_algo time. In raid6_select_algo(), an raid6 gen algorithm is first selected quickly through synchronous processing, while the time-consuming process of selecting the optimal algorithm via benchmark= ing is handled asynchronously. This approach speeds up the overall startup time and ultimately ensures the selection of an optimal algorithm. Signed-off-by: sunliming --- lib/raid6/algos.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index c21e3ad99d97..b8b5515ac7a6 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c @@ -12,6 +12,7 @@ */ =20 #include +#include #ifndef __KERNEL__ #include #include @@ -166,7 +167,7 @@ static inline int raid6_choose_gen_fast(void) =20 if (best) { raid6_call =3D *best; - pr_info("raid6: skipped pq benchmark and selected %s\n", + pr_info("raid6: raid6: fast selected %s, async benchmark pending\n", best->name); } else { pr_err("raid6: No valid algorithm found even for fast selection!\n"); @@ -213,7 +214,7 @@ static inline const struct raid6_calls *raid6_gen_bench= mark( } =20 if (!best) { - pr_err("raid6: Yikes! No algorithm found!\n"); + pr_warn("raid6: async benchmark failed to find any algorithm\n"); goto out; } =20 @@ -289,24 +290,33 @@ static int raid6_choose_gen_benmark(void) return ret; } =20 +static struct work_struct raid6_benchmark_work; + +static void benchmark_work_func(struct work_struct *work) +{ + raid6_choose_gen_benmark(); +} + int __init raid6_select_algo(void) { int ret =3D 0; const struct raid6_recov_calls *rec_best =3D NULL; =20 - /* select raid gen_syndrome functions */ - if (!IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) - ret =3D raid6_choose_gen_fast(); - else - ret =3D raid6_choose_gen_benmark(); - + /* phase 1: synchronous fast selection generation algorithm */ + ret =3D raid6_choose_gen_fast(); if (ret < 0) goto out; =20 /* select raid recover functions */ rec_best =3D raid6_choose_recov(); - if (!rec_best) + if (!rec_best) { ret =3D -EINVAL; + goto out; + } + + /* phase 2: asynchronous performance benchmarking */ + INIT_WORK(&raid6_benchmark_work, benchmark_work_func); + schedule_work(&raid6_benchmark_work); =20 out: return ret; @@ -314,7 +324,7 @@ int __init raid6_select_algo(void) =20 static void raid6_exit(void) { - do { } while (0); + cancel_work_sync(&raid6_benchmark_work); } =20 subsys_initcall(raid6_select_algo); --=20 2.25.1 From nobody Thu Apr 2 20:28:05 2026 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 03C6929CE9 for ; Fri, 13 Feb 2026 03:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952526; cv=none; b=EMrZ46osSXeyXHcYs3yNwRFRq/tRCMVe4QFFQT291SsRzcUT5p6wdOJFVBzJoyfJ8IT6+bjNgVmQQPFi0AJECqkHgRk13qQgcqxXOwY/qHMOeSBU8N4rh7BlSjr/cEHg1zDwYX2NZpeLOdbADgyh0MvS4Cf910uBULNty0Nl7vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770952526; c=relaxed/simple; bh=n7LgFgkZ88IJ/hMH3zs0Om6GScBtmFY7Jf38aF0UOq4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aZiNfhjBMhNcophD4irINs7lwt/vri+cifUqU00tOureancvIefdM5dU/oIaMWaAndkx1rtHsfiw7l04BjDAfWhh93V6yqQjBErXafH6PTWxCx+7DpbJ8dhtxAQdWK4S8KOdHhuNFq1WhOIjidKKz3aWjkb5U5Ryhr3aBzjr/q0= 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=O2uikVt1; arc=none smtp.client-ip=91.218.175.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="O2uikVt1" 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=1770952523; 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=fXo6H32cr3HG8t0LoC8JWMAyx4PWbzKReGAxpF5HxXc=; b=O2uikVt1d9edc9RJi53G8zIXQfLsGYX11m5f4ogipZLR6gsLoDFhRHVPk2G6ZwC3EGyr5h EVykxWB+TRaQiG29kyCcODMTw1djQuJMkhaYCzZFT/C2bndBM3Bl+94VnNx9qenRkWkKNL YURSiwJJ0cFQL9A13XYOPr7dGg3rNJk= From: sunliming@linux.dev To: song@kernel.org, yukuai@fnnas.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, sunliming Subject: [PATCH v3 3/3] lib/raid6: Delete the RAID6_PQ_BENCHMARK config Date: Fri, 13 Feb 2026 11:14:19 +0800 Message-Id: <20260213031419.125069-4-sunliming@linux.dev> In-Reply-To: <20260213031419.125069-1-sunliming@linux.dev> References: <20260213031419.125069-1-sunliming@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: sunliming Now RAID6 PQ functions is automatically choosed and the RAID6_PQ_BENCHMARK is not needed. Signed-off-by: sunliming --- include/linux/raid/pq.h | 3 --- lib/Kconfig | 8 -------- 2 files changed, 11 deletions(-) diff --git a/include/linux/raid/pq.h b/include/linux/raid/pq.h index 2467b3be15c9..6378ec4ae4ba 100644 --- a/include/linux/raid/pq.h +++ b/include/linux/raid/pq.h @@ -67,9 +67,6 @@ extern const char raid6_empty_zero_page[PAGE_SIZE]; #define MODULE_DESCRIPTION(desc) #define subsys_initcall(x) #define module_exit(x) - -#define IS_ENABLED(x) (x) -#define CONFIG_RAID6_PQ_BENCHMARK 1 #endif /* __KERNEL__ */ =20 /* Routine choices */ diff --git a/lib/Kconfig b/lib/Kconfig index 2923924bea78..841a0245a2c4 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -11,14 +11,6 @@ menu "Library routines" config RAID6_PQ tristate =20 -config RAID6_PQ_BENCHMARK - bool "Automatically choose fastest RAID6 PQ functions" - depends on RAID6_PQ - default y - help - Benchmark all available RAID6 PQ functions on init and choose the - fastest one. - config LINEAR_RANGES tristate =20 --=20 2.25.1