Linux-Raid Archives mirror
 help / color / mirror / Atom feed
From: tada keisuke <keisuke1.tada@kioxia.com>
To: "song@kernel.org" <song@kernel.org>,
	"yukuai3@huawei.com" <yukuai3@huawei.com>
Cc: "linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 10/11] md: add atomic mode switching when I/O completion
Date: Thu, 18 Apr 2024 05:44:26 +0000	[thread overview]
Message-ID: <4ee16fa91cd24fb3b5cbe5134e1831f0@kioxia.com> (raw)

This patch depends on patch 09.

If percpu mode in softirq context, switch to atomic mode in delayed execution.
Move from softirq context to a context where RCUs are available and switch to atomic mode.
This patch completes the addition of atomic mode switching.

Signed-off-by: Keisuke TADA <keisuke1.tada@kioxia.com>
Signed-off-by: Toshifumi OHTAKE <toshifumi.ootake@kioxia.com>
---
 drivers/md/md.c | 16 ++++++++++++++++
 drivers/md/md.h |  6 ++++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 5f785353353d..18d0f214098b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9606,6 +9606,7 @@ void md_check_recovery(struct mddev *mddev)
 		return;
 	if ( ! (
 		(mddev->sb_flags & ~ (1<<MD_SB_CHANGE_PENDING)) ||
+		test_bit(MD_RECOVERY_PERCPU, &mddev->recovery) ||
 		test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
 		test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
 		(mddev->external == 0 && mddev->safemode == 1) ||
@@ -9616,6 +9617,21 @@ void md_check_recovery(struct mddev *mddev)
 
 	if (mddev_trylock(mddev)) {
 		bool try_set_sync = mddev->safemode != 0;
+		struct md_rdev *fault_rdev;
+		bool faulty_some = false;
+
+		rdev_for_each(fault_rdev, mddev) {
+			if (fault_rdev->raid_disk >= 0 &&
+			    test_bit(Faulty, &fault_rdev->flags) &&
+			    nr_pending_is_percpu_mode(fault_rdev)) {
+				percpu_ref_switch_to_atomic_sync(&fault_rdev->nr_pending);
+				faulty_some = true;
+			}
+		}
+		if (faulty_some) {
+			clear_bit(MD_RECOVERY_PERCPU, &mddev->recovery);
+			goto unlock;
+		}
 
 		if (!mddev->external && mddev->safemode == 1)
 			mddev->safemode = 0;
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 57b09b567ffa..a3c0b5e8cf05 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -605,6 +605,7 @@ enum recovery_flags {
 	MD_RECOVERY_FROZEN,	/* User request to abort, and not restart, any action */
 	MD_RECOVERY_ERROR,	/* sync-action interrupted because io-error */
 	MD_RECOVERY_WAIT,	/* waiting for pers->start() to finish */
+	MD_RECOVERY_PERCPU,	/* nr_pending when faulty needs to be switched to atomic */
 	MD_RESYNCING_REMOTE,	/* remote node is running resync thread */
 };
 
@@ -887,6 +888,11 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
 	int faulty = test_bit(Faulty, &rdev->flags);
 	nr_pending_dec(rdev);
 	if (faulty) {
+		if (nr_pending_is_percpu_mode(rdev)) {
+			set_bit(MD_RECOVERY_PERCPU, &mddev->recovery);
+			md_wakeup_thread(mddev->thread);
+			return;
+		}
 		if (nr_pending_is_zero(rdev)) {
 			set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
 			md_wakeup_thread(mddev->thread);
-- 
2.34.1



                 reply	other threads:[~2024-04-18  5:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ee16fa91cd24fb3b5cbe5134e1831f0@kioxia.com \
    --to=keisuke1.tada@kioxia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).