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 07/11] md: change the type of nr_pending from atomic_t to percpu_ref
Date: Thu, 18 Apr 2024 05:44:18 +0000	[thread overview]
Message-ID: <7da99b09cb524bdcb705be1b74fdf3e0@kioxia.com> (raw)

This patch depends on patch 05.

Change the type of nr_pending from atomic_t to percpu_ref.
Additionally, temporarily switch from percpu mode to atomic mode.
This is to reduce the amount of changes from patches 8 to 10.
Patches 8 to 10 assume that nr_pending is run in percpu mode.
Finally, switch from atomic mode to percpu mode in patch 11.

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

diff --git a/drivers/md/md.c b/drivers/md/md.c
index d53ca23bacf7..7e6966e65d0d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1002,6 +1002,7 @@ void md_rdev_clear(struct md_rdev *rdev)
 		put_page(rdev->bb_page);
 		rdev->bb_page = NULL;
 	}
+	percpu_ref_exit(&rdev->nr_pending);
 	badblocks_exit(&rdev->badblocks);
 }
 EXPORT_SYMBOL_GPL(md_rdev_clear);
@@ -3724,8 +3725,14 @@ static const struct kobj_type rdev_ktype = {
 	.default_groups	= rdev_default_groups,
 };
 
+static void percpu_wakeup_handle_req_pending(struct percpu_ref *ref)
+{
+}
+
 int md_rdev_init(struct md_rdev *rdev)
 {
+	int ret;
+
 	rdev->desc_nr = -1;
 	rdev->saved_raid_disk = -1;
 	rdev->raid_disk = -1;
@@ -3736,7 +3743,11 @@ int md_rdev_init(struct md_rdev *rdev)
 	rdev->last_read_error = 0;
 	rdev->sb_loaded = 0;
 	rdev->bb_page = NULL;
-	atomic_set(&rdev->nr_pending, 0);
+	ret = percpu_ref_init(&rdev->nr_pending, percpu_wakeup_handle_req_pending,
+		PERCPU_REF_ALLOW_REINIT, GFP_KERNEL);
+	WARN_ON(ret);
+	percpu_ref_switch_to_atomic_sync(&rdev->nr_pending);
+	nr_pending_dec(rdev);
 	atomic_set(&rdev->read_errors, 0);
 	atomic_set(&rdev->corrected_errors, 0);
 
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 783fec1f1445..ab09e312c9bb 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -107,10 +107,10 @@ struct md_rdev {
 					 */
 	};
 
-	atomic_t	nr_pending;	/* number of pending requests.
-					 * only maintained for arrays that
-					 * support hot removal
-					 */
+	struct percpu_ref	nr_pending;	/* number of pending requests.
+						 * only maintained for arrays that
+						 * support hot removal
+						 */
 	atomic_t	read_errors;	/* number of consecutive read errors that
 					 * we have tried to ignore.
 					 */
@@ -213,27 +213,27 @@ enum flag_bits {
 
 static inline void nr_pending_inc(struct md_rdev *rdev)
 {
-	atomic_inc(&rdev->nr_pending);
+	percpu_ref_get(&rdev->nr_pending);
 }
 
 static inline void nr_pending_dec(struct md_rdev *rdev)
 {
-	atomic_dec(&rdev->nr_pending);
+	percpu_ref_put(&rdev->nr_pending);
 }
 
 static inline bool nr_pending_is_zero(struct md_rdev *rdev)
 {
-	return atomic_read(&rdev->nr_pending) == 0;
+	return percpu_ref_is_zero(&rdev->nr_pending);
 }
 
 static inline bool nr_pending_is_not_zero(struct md_rdev *rdev)
 {
-	return atomic_read(&rdev->nr_pending) != 0;
+	return !percpu_ref_is_zero(&rdev->nr_pending);
 }
 
 static inline unsigned long nr_pending_read(struct md_rdev *rdev)
 {
-	return (unsigned long)atomic_read(&rdev->nr_pending);
+	return atomic_long_read(&rdev->nr_pending.data->count);
 }
 
 static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,
-- 
2.34.1



                 reply	other threads:[~2024-04-18  7:04 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=7da99b09cb524bdcb705be1b74fdf3e0@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).