From: Shaohua Li <shli@kernel.org>
To: linux-raid@vger.kernel.org
Cc: neilb@suse.de, axboe@kernel.dk, dan.j.williams@intel.com,
shli@fusionio.com
Subject: [patch 2/8] raid5: lockless access raid5 overrided bi_phys_segments
Date: Mon, 04 Jun 2012 16:01:54 +0800 [thread overview]
Message-ID: <20120604080307.401236650@kernel.org> (raw)
In-Reply-To: 20120604080152.098975870@kernel.org
[-- Attachment #1: raid5-atomic-segment-accounting.patch --]
[-- Type: text/plain, Size: 2780 bytes --]
Raid5 overrides bio->bi_phys_segments, accessing it is with device_lock hold,
which is unnecessary, We can make it lockless actually.
Signed-off-by: Shaohua Li <shli@fusionio.com>
---
drivers/md/raid5.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
Index: linux/drivers/md/raid5.c
===================================================================
--- linux.orig/drivers/md/raid5.c 2012-06-01 13:43:05.594056130 +0800
+++ linux/drivers/md/raid5.c 2012-06-01 13:50:39.852349690 +0800
@@ -101,32 +101,43 @@ static inline struct bio *r5_next_bio(st
*/
static inline int raid5_bi_phys_segments(struct bio *bio)
{
- return bio->bi_phys_segments & 0xffff;
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ return atomic_read(segments) & 0xffff;
}
static inline int raid5_bi_hw_segments(struct bio *bio)
{
- return (bio->bi_phys_segments >> 16) & 0xffff;
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ return (atomic_read(segments) >> 16) & 0xffff;
}
static inline int raid5_dec_bi_phys_segments(struct bio *bio)
{
- --bio->bi_phys_segments;
- return raid5_bi_phys_segments(bio);
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ return atomic_sub_return(1, segments) & 0xffff;
}
-static inline int raid5_dec_bi_hw_segments(struct bio *bio)
+static inline void raid5_inc_bi_phys_segments(struct bio *bio)
{
- unsigned short val = raid5_bi_hw_segments(bio);
-
- --val;
- bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio);
- return val;
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ atomic_inc(segments);
}
static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt)
{
- bio->bi_phys_segments = raid5_bi_phys_segments(bio) | (cnt << 16);
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ int old, new;
+
+ do {
+ old = atomic_read(segments);
+ new = (old & 0xffff) | (cnt << 16);
+ } while (atomic_cmpxchg(segments, old, new) != old);
+}
+
+static inline void raid5_set_bi_segments(struct bio *bio, unsigned int cnt)
+{
+ atomic_t *segments = (atomic_t *)&bio->bi_phys_segments;
+ atomic_set(segments, cnt);
}
/* Find first data disk in a raid6 stripe */
@@ -2354,7 +2365,7 @@ static int add_stripe_bio(struct stripe_
if (*bip)
bi->bi_next = *bip;
*bip = bi;
- bi->bi_phys_segments++;
+ raid5_inc_bi_phys_segments(bi);
if (forwrite) {
/* check if page is covered */
@@ -3783,7 +3794,7 @@ static struct bio *remove_bio_from_retry
* this sets the active strip count to 1 and the processed
* strip count to zero (upper 8 bits)
*/
- bi->bi_phys_segments = 1; /* biased count of active stripes */
+ raid5_set_bi_segments(bi, 1); /* biased count of active stripes */
}
return bi;
next prev parent reply other threads:[~2012-06-04 8:01 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-04 8:01 [patch 0/8] raid5: improve write performance for fast storage Shaohua Li
2012-06-04 8:01 ` [patch 1/8] raid5: add a per-stripe lock Shaohua Li
2012-06-07 0:54 ` NeilBrown
2012-06-07 6:29 ` Shaohua Li
2012-06-07 6:35 ` NeilBrown
2012-06-07 6:52 ` Shaohua Li
2012-06-12 21:02 ` Dan Williams
2012-06-13 4:08 ` Dan Williams
2012-06-13 4:23 ` Shaohua Li
2012-06-12 21:10 ` Dan Williams
2012-06-04 8:01 ` Shaohua Li [this message]
2012-06-07 1:06 ` [patch 2/8] raid5: lockless access raid5 overrided bi_phys_segments NeilBrown
2012-06-12 20:41 ` Dan Williams
2012-06-04 8:01 ` [patch 3/8] raid5: remove some device_lock locking places Shaohua Li
2012-06-04 8:01 ` [patch 4/8] raid5: reduce chance release_stripe() taking device_lock Shaohua Li
2012-06-07 0:50 ` NeilBrown
2012-06-04 8:01 ` [patch 5/8] raid5: add batch stripe release Shaohua Li
2012-06-04 8:01 ` [patch 6/8] raid5: make_request use " Shaohua Li
2012-06-07 1:23 ` NeilBrown
2012-06-07 6:33 ` Shaohua Li
2012-06-07 7:33 ` NeilBrown
2012-06-07 7:58 ` Shaohua Li
2012-06-08 6:16 ` Shaohua Li
2012-06-08 6:42 ` NeilBrown
2012-06-04 8:01 ` [patch 7/8] raid5: raid5d handle stripe in batch way Shaohua Li
2012-06-07 1:32 ` NeilBrown
2012-06-07 6:35 ` Shaohua Li
2012-06-07 7:38 ` NeilBrown
2012-06-04 8:02 ` [patch 8/8] raid5: create multiple threads to handle stripes Shaohua Li
2012-06-07 1:39 ` NeilBrown
2012-06-07 6:45 ` Shaohua Li
2012-06-13 4:08 ` Dan Williams
2012-06-21 10:09 ` Shaohua Li
2012-07-02 20:43 ` Dan Williams
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=20120604080307.401236650@kernel.org \
--to=shli@kernel.org \
--cc=axboe@kernel.dk \
--cc=dan.j.williams@intel.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
--cc=shli@fusionio.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 NNTP newsgroup(s).