linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/1] raid5: avoid release list until last reference of the stripe
@ 2014-05-28  1:35 Eivind Sarto
  2014-05-28  2:01 ` NeilBrown
  0 siblings, 1 reply; 2+ messages in thread
From: Eivind Sarto @ 2014-05-28  1:35 UTC (permalink / raw)
  To: linux-raid; +Cc: NeilBrown

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

This simple patch will reduce the number of times stripes are queued on the release_list.
Currently stripes are queued more than twice as many times on this list as they need to be.

-eivind

[-- Attachment #2: raid5_avoid_release_list_until_last_reference.patch --]
[-- Type: application/octet-stream, Size: 2468 bytes --]

Author: Eivind Sarto <esarto@fusionio.com>
Date: Fri Apr 11 12:54:33 2014

raid5: avoid release list until last reference of the stripe

The (lockless) release_list reduces lock contention, but there is excessive
queueing and dequeuing of stripes on this list.  A stripe will currently be
queued on the release_list with a stripe reference count > 1.  This can cause
the raid5 kernel thread(s) to dequeue the stripe and decrement the refcount
without doing any other useful processing of the stripe.  The are two cases
when the stripe can be put on the release_list multiple times before it is
actually handled by the kernel thread(s).
1) make_request() activates the stripe processing in 4k increments.  When a
   write request is large enough to span multiple chunks of a stripe_head, the
   first 4k chunk adds the stripe to the plug list.  The next 4k chunk that is
   processed for the same stripe puts the stripe on the release_list with a
   refcount=2.  This can cause the kernel thread to process and decrement the
   stripe before the stripe us unplugged, which again will put it back on the
   release_list.
2) Whenever IO is scheduled on a stripe (pre-read and/or write), the stripe
   refcount is set to the number of active IO (for each chunk).  The stripe is
   released as each IO complete, and can be queued and dequeued multiple times
   on the release_list, until its refcount finally reached zero.

This simple patch will ensure a stripe is only queued on the release_list when
its refcount=1 and is ready to be handled by the kernel thread(s).  I added some
instrumentation to raid5 and counted the number of times striped were queued on
the release_list for a variety of write IO sizes.  Without this patch the number
of times stripes got queued on the release_list was 100-500% higher than with
the patch.  The excess queuing will increase with the IO size.  The patch also
improved throughput by 5-10%.

Signed-off-by: Eivind Sarto <esarto@fusionio.com>

Index: current/drivers/md/raid5.c
===================================================================
--- current.orig/drivers/md/raid5.c
+++ current/drivers/md/raid5.c
@@ -423,6 +423,11 @@ static void release_stripe(struct stripe
 	int hash;
 	bool wakeup;
 
+	/* Avoid release_list until the last reference.
+	 */
+	if (atomic_add_unless(&sh->count, -1, 1))
+		return;
+
 	if (unlikely(!conf->mddev->thread) ||
 		test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state))
 		goto slow_path;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch 1/1] raid5: avoid release list until last reference of the stripe
  2014-05-28  1:35 [patch 1/1] raid5: avoid release list until last reference of the stripe Eivind Sarto
@ 2014-05-28  2:01 ` NeilBrown
  0 siblings, 0 replies; 2+ messages in thread
From: NeilBrown @ 2014-05-28  2:01 UTC (permalink / raw)
  To: Eivind Sarto; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 318 bytes --]

On Tue, 27 May 2014 18:35:11 -0700 Eivind Sarto <eivindsarto@gmail.com> wrote:

> This simple patch will reduce the number of times stripes are queued on the release_list.
> Currently stripes are queued more than twice as many times on this list as they need to be.
> 
> -eivind

Applied, thanks.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-28  2:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-28  1:35 [patch 1/1] raid5: avoid release list until last reference of the stripe Eivind Sarto
2014-05-28  2:01 ` NeilBrown

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).