From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 5264842DFE6 for ; Fri, 10 Jul 2026 13:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689826; cv=none; b=Y6XkdGg0vzlQN88ko6MQWZ3N+zjGOGzy2e7S4TEyY2TFZ1a6dDBoOF9Q8Oa/3qWKOEHVOHNhXJsOm6wACFtUI0xz4EM41VFcm3QH7vD9dp+2cUBPmtBxcVflKg0qH+jPpassCJ/T/3/jpEop+CJdJ1l392mX12u2u4VQLn63tFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783689826; c=relaxed/simple; bh=rILqh2AK/wV2oaCV6mXWPyP6nIH7VlWbJRVUdRAVWuc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojd2xD5ypnRvLk06qmMjde6KZoqYkGWXgq26gPzeNYdRn5fPWGDeOmMFjUa+c63R8GHnBIJtaBSWT8Jhm7TVNq94kqgQZamvy5x9GPxMtBwHqIjiqEfzJqfTgS946oAD0IJ33OQl/UOcte1ghSUTWxUEXQRWo26OlIjHAaBfuFQ= 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=EK4aSRsP; arc=none smtp.client-ip=209.85.216.42 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="EK4aSRsP" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-37e0a189b0bso860480a91.1 for ; Fri, 10 Jul 2026 06:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783689825; x=1784294625; 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=htRKr+bV2R+fMpKz8/j8vcbQE0s04qSNR7/x8WoH3ss=; b=EK4aSRsPKEg9Zb+/EsMN2w1GDyRm8f0JMvU08cl++aVkOxf5975T3MyyyWFp004CT8 km/YbZt9k4BwhVZNTd4F0wp1rLEv16XOl65a/F/Cc2qwkon4GLAEjG4dCpYzQ6sPtqPF O0WurkQIE5AxQXC/egqQtObpRAzpCQ0w+lE2RBB37ZoLv4g5YzzXKlAgXM4Z/wnjegy5 jiClReeeBQiUaxGHoYxzGgJYdgwZi82KIcPnL2TYk74PcYNBYJY6q4YYsZWpwpsOEDX1 7hz0wwj7FZA2HiQdN6vIeMl0wD7BXqMjQiO8d01EUv8D2gJtKT8nX1vuq9BNBKF0SLKD SLBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783689825; x=1784294625; 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=htRKr+bV2R+fMpKz8/j8vcbQE0s04qSNR7/x8WoH3ss=; b=F1xM+eiqDuXGZZOB8O85uzM/5odUdG+J3mXcCgMj5bzFB8GT7fDAFYKRu3i6HeQWOh rE++uNsAsOitNm4dtAeVsBGFqdTn6D75pwcGfHZEcWYLkOxSKdIW6PQd3nwF+dIZIv7l 81b+vbLtyvjKCag8Dl+jfbMMuzxgwTplOfgcBVo4YSJ1OzLyW/L9IN2cuYld+ULh7bD3 d1VU85KIK2a6lUhTm4d0HdNEy4rx0UtObG/on28a/l+YXtJ5KJ7NAjFlbCr5OuOquIcB xdHDfvPNYrep8Nqt4EmAhsh6acxgZ2kgJxt81nYmhqW97PmnWCt3DJOMH9jZkOoOH6Bc ZVjg== X-Forwarded-Encrypted: i=1; AHgh+RpVUrJBHr67WHd3h/RaugpcQjMDXBInzm9kuVC8bdVR9YzbZlu6DQi5y68ZzrWbN7NgvC7krFe7Jd4MhGg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8e2Swdr8+6Wgtil17nSIoxpg9RT2ad5czkuZzR1QmLlywCria bN7CgBxrzMD77r3Po5QIXVdXb5pQ+A83tlVNiDaeDNJwFgIyExwNOpFR X-Gm-Gg: AfdE7cnV9bds4XQ18AkGmR0Aj94EZLdFxr8bYCWrX3qIX2bPY3l9/Jd8s95P1a4agd8 1QGRHws5tz+3WddwrNYVjaJ79+dzSLIWxxtk/TrHWmQ0GAOn8ey2hHPxC7rJVnLtBNRKDpOmzns R+l402XO+Ii9mE4dkSCgMXJKV4E45DMCP1EYAYOf+nHb+VHEC9sRZiNFSppP+Md3W+RwJD7g1A4 UbRzYOaLRNp/E6FZ/tRrBibsAcGrUprXCA7f2HTeKQVSsb20lhs8Rsdd5CjJUmxjQCPxR6i3Ok6 03KHTv+2wOZQvu4nTfzDYDuQZ5uZLspdvg1lTMeQadLVfPZosREZtQesqRM+2jDw6a/Cq1hNhpO YsjxuKYtbbsEVZZnOPMb4Q8jN0czYX1HTuEC689n7WwSq6KdE5zZFvGOwrRs+bfbaVbQNA6de9A H5+pHdBZGKeBdmP6OkGVPbAWtNEwfwPtSNdwDjubRHWrx68DDZJi1jCxGPXwfOCkVHBn2bo7hTd 8n6G5Y= X-Received: by 2002:a17:90a:e70d:b0:37f:9cdf:f03a with SMTP id 98e67ed59e1d1-38941fb57e3mr11438439a91.29.1783689824706; Fri, 10 Jul 2026 06:23:44 -0700 (PDT) Received: from research02.. ([2601:1c1:8700:f5b:fe34:97ff:fea3:c147]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38d2fbc64b5sm549778a91.2.2026.07.10.06.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 06:23:44 -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 2/2] md/raid5: reserve stripe cache for user I/O during rebuild Date: Fri, 10 Jul 2026 06:23:39 -0700 Message-ID: <20260710132339.7284-3-nishidafmly@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710132339.7284-1-nishidafmly@gmail.com> References: <20260710132339.7284-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 The resync read-ahead window (RAID5_SYNC_WINDOW) can fill the stripe cache with rebuild stripes and starve concurrent user I/O, producing a burst-starvation flip-flop between rebuild and application throughput. Add two yield points to the window-submission loop: - stop the window immediately if any thread is waiting for a stripe (waitqueue_active(&conf->wait_for_stripe)); the check is intentionally racy -- a waiter appearing just after is serviced by the next sync_request call, so no barrier is needed. - stop expanding once active_stripes reaches half the cache (max_nr_stripes / RAID5_SYNC_HWMARK), but only when preread_active_stripes > 0, i.e. user write I/O is actually competing. Sync stripes never set STRIPE_PREREAD_ACTIVE, so during a pure rebuild the counter stays zero and the window fills freely; rebuild-only throughput is unchanged. This bounds the share of the stripe cache a rebuild may hold while user I/O is present, so application latency no longer collapses during the read-ahead bursts, without throttling a rebuild that has the array to itself. Signed-off-by: Hiroshi Nishida --- drivers/md/raid5.c | 21 +++++++++++++++++++++ drivers/md/raid5.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 574880e4f23f..6575bdb84bb2 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -6656,6 +6656,27 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n submitted < RAID5_SYNC_WINDOW && win_sector < max_sector && win_sector < mddev->resync_max; submitted++, win_sector += RAID5_STRIPE_SECTORS(conf)) { + /* + * Yield to user I/O: stop the read-ahead if anyone is waiting + * for a stripe. The check is intentionally racy -- a waiter + * appearing just after is serviced by the next sync_request + * call, so no barrier is needed. + */ + if (waitqueue_active(&conf->wait_for_stripe)) + break; + /* + * Reserve cache for user I/O only when it is actually competing. + * preread_active_stripes counts stripes queued for write I/O + * (including the read phase of RMW); sync stripes never set + * STRIPE_PREREAD_ACTIVE, so during a pure rebuild it stays zero + * and the window fills freely. Competing user reads do not bump + * the counter but are caught by the waitqueue_active() check + * above. + */ + if (atomic_read(&conf->preread_active_stripes) > 0 && + atomic_read(&conf->active_stripes) >= + conf->max_nr_stripes / RAID5_SYNC_HWMARK) + break; sh = raid5_get_active_stripe(conf, NULL, win_sector, R5_GAS_NOBLOCK); if (!sh) diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 63b630118782..263330af4e7d 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -492,6 +492,7 @@ struct disk_info { #define HASH_MASK (NR_HASH - 1) #define MAX_STRIPE_BATCH 8 #define RAID5_SYNC_WINDOW 32 /* stripes to pre-submit per sync_request call */ +#define RAID5_SYNC_HWMARK 2 /* rebuild uses at most 1/N of stripe cache */ /* NOTE NR_STRIPE_HASH_LOCKS must remain below 64. * This is because we sometimes take all the spinlocks -- 2.43.0