linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shaohua Li <shli@kernel.org>
To: Vivek Goyal <vgoyal@redhat.com>, axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org, neilb@suse.de, martin.petersen@oracle.com
Subject: [patch 1/2]block: handle merged discard request
Date: Wed, 21 Mar 2012 20:14:36 +0800	[thread overview]
Message-ID: <4F69C62C.7020604@kernel.org> (raw)
In-Reply-To: <CANejiEWecb58G--=mwez+A4Ra6nJ0qOHGMcJA-nOGH=jmGA3qQ@mail.gmail.com>

On 3/21/12 9:22 AM, Shaohua Li wrote:
> 2012/3/21 Vivek Goyal<vgoyal@redhat.com>:
>> On Fri, Mar 16, 2012 at 03:32:15PM +0800, Shaohua Li wrote:
>>> Didn't allow discard request merge temporarily, as SCSI layer isn't ready
>>> for discard merge as Martin Petersen pointed out. This isn't fair for
>>> non-scsi device, but looks this is the only way I can do currently.
>>>
>>> We should have the same issue before, but maybe because discard merge is
>>> very rare case. But now raid0/10 makes the merge quite possible, so we need
>>> disable it explicitly.
>> I think you will need to do little more cleanup to make discard
>> unmergeable.
>>
>> - Change rq_mergeable(rq)
>> - Change attempt_merge() and get rid of special conditions of allowing
>>   discard merge.
>>
>> Martin had a bigger patch where he wanted to cleanup many discard specific
>> condition checks.
>>
>> As you are just focusing on disabling merging for discard requests, you
>> might as well just pick the relevant pieces from the patch.
>>
>> http://www.spinics.net/lists/linux-scsi/msg57779.html
> Thanks for pointing out the thread. I didn't think disabling discard merging
> permanently is a good idea. We can't do the merge because that code isn't
> ready (actually just for driver of SCSI). Enabling discard merge is required
> for device with slow discard (and very helpful for raid), so I just want a
> temporarily disabling for the merge. Just changing RQ_NOMERGE_FLAGS
> is an easy workaround for this goal.
I looked at the SCSI code for discard again, looks we can easily make 
discard
mergeable. It's a little hacky (the whole SCSI discard implementation is 
hacky
actually), but quite simple and end the trouble of discard merge 
immediately.

Thanks,
Shaohua


The SCSI discard implementation hacks the first bio of request to
add payload, which makes blk_update_request() can't correctly mark
bios finish.
The patch solves it. We set discard bio size to 0 and finish it after
the hacked payload finishes. The check in blk_update_request() should
make us safe.
It's a little hack here (but the whole discard implementation of SCSI
is hacky) and this makes us have discard request merge immediately,
which is great for some SSDs with slow discard.

Signed-off-by: Shaohua Li <shli@fusionio.com>

---
  block/blk-core.c |   11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)

Index: linux/block/blk-core.c
===================================================================
--- linux.orig/block/blk-core.c	2012-03-21 17:58:07.322320702 +0800
+++ linux/block/blk-core.c	2012-03-21 18:04:34.662320467 +0800
@@ -1177,7 +1177,7 @@ EXPORT_SYMBOL(blk_put_request);
  void blk_add_request_payload(struct request *rq, struct page *page,
  		unsigned int len)
  {
-	struct bio *bio = rq->bio;
+	struct bio *bio = rq->bio, *next = bio->bi_next;

  	bio->bi_io_vec->bv_page = page;
  	bio->bi_io_vec->bv_offset = 0;
@@ -1187,6 +1187,11 @@ void blk_add_request_payload(struct requ
  	bio->bi_vcnt = 1;
  	bio->bi_phys_segments = 1;

+	while (next) {
+		next->bi_size = 0;
+		next = next->bi_next;
+	}
+
  	rq->__data_len = rq->resid_len = len;
  	rq->nr_phys_segments = 1;
  	rq->buffer = bio_data(bio);
@@ -2185,8 +2190,10 @@ bool blk_update_request(struct request *
  		if (bio) {
  			/*
  			 * end more in this run, or just return 'not-done'
+			 * The discard check is a hack, see blk_add_request_payload
  			 */
-			if (unlikely(nr_bytes <= 0))
+			if (unlikely(nr_bytes <= 0 &&
+			   !((req->cmd_flags & REQ_DISCARD) && bio->bi_size == 0)))
  				break;
  		}
  	}

  reply	other threads:[~2012-03-21 12:14 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16  7:32 [patch v2 0/6] Add TRIM support for raid linear/0/1/10 Shaohua Li
2012-03-16  7:32 ` [patch v2 1/6] block: makes bio_split support bio without data Shaohua Li
2012-03-16  7:32 ` [patch v2 2/6] blk: dont allow discard request merge temporarily Shaohua Li
2012-03-20 16:21   ` Vivek Goyal
2012-03-21  1:22     ` Shaohua Li
2012-03-21 12:14       ` Shaohua Li [this message]
2012-03-22  2:32         ` [patch 1/2]block: handle merged discard request Martin K. Petersen
2012-03-22  2:39           ` Shaohua Li
2012-03-22  2:53             ` Martin K. Petersen
2012-06-20  8:57               ` Christoph Hellwig
2012-06-22  3:46                 ` Martin K. Petersen
2012-08-03  2:10                   ` Shaohua Li
2012-08-18  3:06                   ` Mike Snitzer
2012-08-18  3:47                     ` Martin K. Petersen
2012-08-20 13:57                       ` Mike Snitzer
2012-08-20 13:58                         ` Christoph Hellwig
2012-08-20 14:12                           ` Mike Snitzer
2012-08-20 14:15                             ` Christoph Hellwig
2012-03-22  2:18       ` [patch v2 2/6] blk: dont allow discard request merge temporarily Martin K. Petersen
2012-03-22  2:33         ` Shaohua Li
2012-03-22  6:28         ` Christoph Hellwig
2012-03-16  7:32 ` [patch v2 3/6] md: linear supports TRIM Shaohua Li
2012-03-16  7:32 ` [patch v2 4/6] md: raid 0 " Shaohua Li
2012-03-16  7:32 ` [patch v2 5/6] md: raid 1 " Shaohua Li
2012-03-16  7:32 ` [patch v2 6/6] md: raid 10 " Shaohua Li
2012-03-19 19:38 ` [patch v2 0/6] Add TRIM support for raid linear/0/1/10 Holger Kiehl
2012-03-20  1:27   ` Shaohua Li
2012-03-20  9:50     ` Holger Kiehl
2012-03-20 12:09       ` Shaohua Li
2012-03-21  2:08         ` Shaohua Li
2012-03-21  2:24           ` Roberto Spadim
2012-03-21  2:29             ` Mathias Burén
2012-03-21  2:29           ` Mathias Burén
2012-05-08  9:59 ` Patelczyk, Maciej
2012-05-09  2:27   ` 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=4F69C62C.7020604@kernel.org \
    --to=shli@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=neilb@suse.de \
    --cc=vgoyal@redhat.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).