From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99D27432BD6 for ; Fri, 10 Jul 2026 13:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689834; cv=none; b=od2qqLWCNGVXvowpJ6Ow/0G3lCwJX75KBXiX+hnOZnJnwD144J9F9qGRbPc4Kb/txpSUIEnywSh7EE1WQ2xRVAcrNQYzxYTbUkamD+ndIsYLtNAv+KPlqpTw7ojfemkpLxauuUgggL+bt2utzzvgAJ5RBd27l+p8aY5Kya3PEK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689834; c=relaxed/simple; bh=ROxI8I56kgfmTN4J4BZy2V7chA2+oyHggossUsMnPoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qdoV/4/iBMpyMYc1CMai+yHi5aou3KUu7a15CzhHZwVDqpu56gmvY4ZGW94F3lMCmkhTCCG0ZiBpaQE8ktBpYvoM+DAoAzp1wfYxdztMMARVubTROi/Hh+ICHihevu/ux5FkDF8QBEz+ctFkHfCVOQ2/6GikyfxJRQ6gd1TtqFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UwhDZecj; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UwhDZecj" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8486672f03cso758851b3a.0 for ; Fri, 10 Jul 2026 06:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783689832; x=1784294632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=z1ptaSjjmJUeSpstZTVLuscns/xpL1khD7u065BJaVM=; b=UwhDZecjx/s9srJmWVSfX9ZTUDWZsrNTxI59YZ4sxQgCsPLkI7jVHoCqL6aSTA+aA3 pgyn1qy51shf79LpkI86VqYQM8SRAPfCc/qWcUK0UhxRhqs8I5yYh4eMHjMW/1Bjoe7P bFGZOrnX9sYeQYcI2MnVN273esc1gKmTFdKHrcIFOfaZlrzZhN8+9zI6q61OPT4LzJcS AgWW06qxYcJCo98X1KM4xm96ibw2z5zXKotltWDKCBVRNWHNRTtTItKHSE06B2GZRztj YrH6e0zcCh7jJWTk+N56LRJcQ+LOz63Ia5/0PYTlSavRszXhUoTjt5taRY5SqgoWRq9x qOsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783689832; x=1784294632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=z1ptaSjjmJUeSpstZTVLuscns/xpL1khD7u065BJaVM=; b=LxwU1/637VP0IoWRRS4KkQy6GAJKM4TJpeK8G8BGjImITYYNz+TiLfrFNlacimCrS2 b95GA/tGi5JT5dQtPf0In3GilGvzm12X9eb6Ipfz34x6x2ltbp1KFbMF9vVwzkv9mvCm ayOPWKebQVIKsnVRg/vYNOqtPV1S8J75V8N9xnybjhMsZedwndKx1BL5KoECBeSw1rCz xshEBNxoYDVZB74QET0n50FSCwKSzsqmWKeRx2LVt/XZl/hsRqtQW1UARrvCOWOeScgz wtpKh96G/k5YersfA7zj9j+FYy0yeXASk5yzXsN25VzWYw0zqshSS2oUaueOLzl5VKaz xmuA== X-Forwarded-Encrypted: i=1; AHgh+RpJ2OhLYyCMlnKUvW7OKnQRwsBjJYvy2n4RPtG3bG6hNpOEPkxomVHoqwqnnzsh25etf7IzSXHWHEXoeBU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9+aDjW4k5vSh00WAgMYuTQ2DtmyF2Nk+kyQ0cx702JjN2Uym2 VLf/Z1+1g20jxlSgfASaDJABG7/G/exaOAqh1T4+Hd+g2Vpr4teVPYL4 X-Gm-Gg: AfdE7cntJIRXnGzMGi051TUTucVzYESgbJ8B9nurJJ+tXKLl+cmLGfuNSGIF84N8tb+ 9an6nbdJAXz3menj6eN1j7xIp7Mq6yubes8uEvPaad5McFn060+Wg9PSYEwC5TpZAnxAqjQX2u7 2TbnK921fSZtS8I5HkyWxioLlJ45/Ty//dTRvqK7HdW6CEh/DwtQy9R8KsWzx/iWCoZzadCg6l9 dDj8jMFCmkBdYcx/+hPqsIm5npnyGgZEzc8/7dkieinq4XfxP6V5LxFNaml9QJZIW9Pb6JHNIj7 wkKzd5tiWex1dsINJYY6F4EZGvBGfjSjYuBrQvSUtDY7yAdv0TNlTZ5tiarvBUnm3gM/hEkGT3r 7chETPUIR7DHirheSN8ZajdKAX6EH52nx19zPgYuh+UOumN9a6kwMYwcuwc642byOAHjmNsktXy MBj6zRtwvlYHCUqcyc91oQtCLJa5m107oXlDLK2XtIqVWV21pgnhK2UHWrR1VJSBfi8SZkQTCou mFRzQY= X-Received: by 2002:a05:6a20:a10e:b0:398:7df5:2dae with SMTP id adf61e73a8af0-3c0bcf49b71mr13545168637.9.1783689831988; Fri, 10 Jul 2026 06:23:51 -0700 (PDT) Received: from research02.. ([2601:1c1:8700:f5b:fe34:97ff:fea3:c147]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ca5b3b251eesm4903776a12.31.2026.07.10.06.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 06:23:51 -0700 (PDT) From: Hiroshi Nishida To: Song Liu , Yu Kuai Cc: Li Nan , Xiao Ni , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Hiroshi Nishida Subject: [PATCH 4/6] md/raid5: make the stripe batch size a module parameter Date: Fri, 10 Jul 2026 06:23:44 -0700 Message-ID: <20260710132346.7295-5-nishidafmly@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710132346.7295-1-nishidafmly@gmail.com> References: <20260710132346.7295-1-nishidafmly@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit handle_active_stripes() dequeues up to MAX_STRIPE_BATCH (8) stripes from a worker group under a single device_lock acquisition, and raid5_wakeup_stripe_thread() divides group->stripes_cnt by the same value to decide how many additional workers to wake. The two uses must move together: the dequeue cap bounds how many stripes one worker drains, while the spawn divisor sizes the worker fan-out to match. Make the batch size a per-array value chosen by a new max_stripe_batch module parameter (1-32, default 8, so behaviour is unchanged out of the box). Both the dequeue cap and the spawn divisor read the single conf->max_stripe_batch, so they cannot drift apart. The on-stack batch[] array in handle_active_stripes() is sized to the STRIPE_BATCH_MAX (32) upper bound; only conf->max_stripe_batch entries are ever used. The value is resolved when an array is created. On busy multi-threaded arrays a larger batch amortises the device_lock over more stripes at some latency cost; unlike the hash-lock count and the cache-size limit there is no general hardware signal for the best batch size, so the default is left at the historical 8 and the value is simply exposed for tuning. Signed-off-by: Hiroshi Nishida --- drivers/md/raid5.c | 15 ++++++++++++--- drivers/md/raid5.h | 12 +++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index e41d3fc92dd0..5f0825c5effe 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -78,6 +78,11 @@ module_param(stripe_cache_size_max, uint, 0644); MODULE_PARM_DESC(stripe_cache_size_max, "Maximum the per-array stripe_cache_size may be raised to. 0 (the default) derives the limit from system memory (never below the historical 32768), so large-memory hosts can grow the stripe cache without a recompile while small ones are not offered a limit above what RAM can back. A non-zero value sets a fixed limit"); +static unsigned int max_stripe_batch = STRIPE_BATCH_DEFAULT; +module_param(max_stripe_batch, uint, 0644); +MODULE_PARM_DESC(max_stripe_batch, + "Number of stripes a worker thread handles per device_lock acquisition, 1-32 (default 8). Larger values amortise the lock over more stripes on busy multi-threaded arrays at some latency cost. Read when an array is created"); + static bool devices_handle_discard_safely = false; module_param(devices_handle_discard_safely, bool, 0644); MODULE_PARM_DESC(devices_handle_discard_safely, @@ -221,7 +226,7 @@ static void raid5_wakeup_stripe_thread(struct stripe_head *sh) /* at least one worker should run to avoid race */ queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); - thread_cnt = group->stripes_cnt / MAX_STRIPE_BATCH - 1; + thread_cnt = group->stripes_cnt / conf->max_stripe_batch - 1; /* wakeup more workers */ for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { if (group->workers[i].working == false) { @@ -6734,11 +6739,11 @@ static int handle_active_stripes(struct r5conf *conf, int group, struct list_head *temp_inactive_list) __must_hold(&conf->device_lock) { - struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; + struct stripe_head *batch[STRIPE_BATCH_MAX], *sh; int i, batch_size = 0, hash; bool release_inactive = false; - while (batch_size < MAX_STRIPE_BATCH && + while (batch_size < conf->max_stripe_batch && (sh = __get_priority_stripe(conf, group)) != NULL) batch[batch_size++] = sh; @@ -7640,6 +7645,10 @@ static struct r5conf *setup_conf(struct mddev *mddev) !conf->temp_inactive_list) goto abort; + /* Resolve the stripe batch size (see STRIPE_BATCH_* in raid5.h). */ + conf->max_stripe_batch = clamp_t(int, max_stripe_batch, + 1, STRIPE_BATCH_MAX); + #if PAGE_SIZE != DEFAULT_STRIPE_SIZE conf->stripe_size = DEFAULT_STRIPE_SIZE; conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9; diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 10c45fa22955..69a41c1310af 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -490,7 +490,16 @@ struct disk_info { #define BYPASS_THRESHOLD 1 #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) #define HASH_MASK (NR_HASH - 1) -#define MAX_STRIPE_BATCH 8 +/* + * Stripe batch size: how many stripes a worker dequeues from its group per + * device_lock acquisition in handle_active_stripes(); the same value divides + * group->stripes_cnt in raid5_wakeup_stripe_thread() to choose how many extra + * workers to spawn, so the two stay coupled. Selected per array by the + * max_stripe_batch module parameter: STRIPE_BATCH_DEFAULT is the historical + * value and STRIPE_BATCH_MAX bounds the on-stack batch[] array. + */ +#define STRIPE_BATCH_DEFAULT 8 +#define STRIPE_BATCH_MAX 32 /* * The stripe cache hash is striped across a power-of-two number of spinlocks, @@ -690,6 +699,7 @@ struct r5conf { struct r5worker_group *worker_groups; int group_cnt; int worker_cnt_per_group; + int max_stripe_batch; /* stripes/dequeue, 1..STRIPE_BATCH_MAX */ struct r5l_log *log; void *log_private; -- 2.43.0