From: NeilBrown <neilb@suse.com>
To: Shaohua Li <shli@kernel.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
Christoph Hellwig <hch@lst.de>,
linux-raid@vger.kernel.org
Subject: [md PATCH 1/5] md: optimize md_write_start() slightly.
Date: Mon, 21 Nov 2016 12:19:43 +1100 [thread overview]
Message-ID: <147969118311.5434.4562756561505136744.stgit@noble> (raw)
In-Reply-To: <147969099621.5434.12384452255155063186.stgit@noble>
If md_write_start() finds that ->writes_pending is non-zero, it
should be able to avoid most of the other checks.
To ensure that a non-zero ->writes_pending does mean that other checks
have completed, move it down until after ->in_sync is known to be
clear. To avoid races with places like array_state_store() which
possible sets ->in_sync, we need to increment ->write_pending inside
the locked region. As ->writes_pending is now incremented *after*
->in_sync is tested, we must always take the spin_lock, but only if
->writes_pending was found to be zero.
If ->writes_pending is found to be non-zero, we still need to wait it
MD_CHANGE_PENDING is true.
In the common case, md_write_start() will now only
- check if data_dir is WRITE
- increment ->writes_pending
- check MD_CHANGE_PENDING is cleared.
Signed-off-by: NeilBrown <neilb@suse.com>
---
drivers/md/md.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 1f1c7f007b68..2f21f6c7156f 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7686,20 +7686,18 @@ void md_write_start(struct mddev *mddev, struct bio *bi)
int did_change = 0;
if (bio_data_dir(bi) != WRITE)
return;
-
- BUG_ON(mddev->ro == 1);
- if (mddev->ro == 2) {
- /* need to switch to read/write */
- mddev->ro = 0;
- set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
- md_wakeup_thread(mddev->sync_thread);
- did_change = 1;
- }
- atomic_inc(&mddev->writes_pending);
- if (mddev->safemode == 1)
- mddev->safemode = 0;
- if (mddev->in_sync) {
+ if (!atomic_inc_not_zero(&mddev->writes_pending)) {
+ BUG_ON(mddev->ro == 1);
+ if (mddev->ro == 2) {
+ /* need to switch to read/write */
+ mddev->ro = 0;
+ set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+ md_wakeup_thread(mddev->thread);
+ md_wakeup_thread(mddev->sync_thread);
+ did_change = 1;
+ }
+ if (mddev->safemode == 1)
+ mddev->safemode = 0;
spin_lock(&mddev->lock);
if (mddev->in_sync) {
mddev->in_sync = 0;
@@ -7708,10 +7706,12 @@ void md_write_start(struct mddev *mddev, struct bio *bi)
md_wakeup_thread(mddev->thread);
did_change = 1;
}
+ atomic_inc(&mddev->writes_pending);
spin_unlock(&mddev->lock);
+
+ if (did_change)
+ sysfs_notify_dirent_safe(mddev->sysfs_state);
}
- if (did_change)
- sysfs_notify_dirent_safe(mddev->sysfs_state);
wait_event(mddev->sb_wait,
!test_bit(MD_CHANGE_PENDING, &mddev->flags));
}
next prev parent reply other threads:[~2016-11-21 1:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-21 1:19 [md PATCH 0/5] Stop using bi_phys_segments as a counter NeilBrown
2016-11-21 1:19 ` [md PATCH 3/5] md/raid5: simplfy delaying of writes while metadata is updated NeilBrown
2016-11-21 1:19 ` [md PATCH 4/5] md/raid5: call bio_endio() directly rather than queuing for later NeilBrown
2016-11-21 1:19 ` [md PATCH 2/5] md/raid5: use md_write_start to count stripes, not bios NeilBrown
2016-11-21 1:19 ` NeilBrown [this message]
2016-11-21 1:19 ` [md PATCH 5/5] md/raid5: use bio_inc_remaining() instead of repurposing bi_phys_segments as a counter NeilBrown
2016-11-21 2:32 ` [md PATCH 6/5] md/raid5: remove over-loading of ->bi_phys_segments NeilBrown
2016-11-21 14:01 ` [md PATCH 0/5] Stop using bi_phys_segments as a counter Christoph Hellwig
2016-11-21 23:43 ` Shaohua Li
2016-11-22 0:25 ` NeilBrown
2016-11-22 1:02 ` Shaohua Li
2016-11-22 2:19 ` NeilBrown
2016-11-22 8:01 ` Shaohua Li
2016-11-23 2:08 ` NeilBrown
2016-11-23 8:45 ` Christoph Hellwig
2016-11-24 0:31 ` NeilBrown
2017-02-06 8:56 ` Christoph Hellwig
2017-02-06 21:41 ` Shaohua Li
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=147969118311.5434.4562756561505136744.stgit@noble \
--to=neilb@suse.com \
--cc=hch@lst.de \
--cc=khlebnikov@yandex-team.ru \
--cc=linux-raid@vger.kernel.org \
--cc=shli@kernel.org \
/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