public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <jens.axboe@oracle.com>
To: Miquel van Smoorenburg <mikevs@xs4all.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] elevator.c: prevent flushing small requests to device
Date: Fri, 31 Oct 2008 08:33:39 +0100	[thread overview]
Message-ID: <20081031073338.GZ31673@kernel.dk> (raw)
In-Reply-To: <20081023161333.GA28155@xs4all.net>

On Thu, Oct 23 2008, Miquel van Smoorenburg wrote:
> While tracing I/O patterns with blktrace (a great tool) a few
> weeks ago I identified a minor issue in elevator.c
> 
> [PATCH] elevator.c: prevent flushing small requests to device
> 
> When elv_insert() is called to insert a new request, and the
> device is plugged,  bit of code at the end of the function
> will unplug the device if the number of pending requests >= q->unplug_thresh.
> 
> This means the current request is also sent to the device immidiately
> while it is potentially mergeable with the next request. This has been
> observed when a lot of small sequential requests are made.
> 
> By unplugging the device before we add the new request to the
> queue this can be prevented.
> 
> Signed-off-by: Miquel van Smoorenburg <mikevs@xs4all.net>
> 
> diff -ruN linux-2.6.26.5.orig/block/elevator.c linux-2.6.26.5/block/elevator.c
> --- linux-2.6.26.5.orig/block/elevator.c	2008-09-08 19:40:20.000000000 +0200
> +++ linux-2.6.26.5/block/elevator.c	2008-10-23 00:33:21.000000000 +0200
> @@ -602,6 +602,20 @@
>  
>  	case ELEVATOR_INSERT_SORT:
>  		BUG_ON(!blk_fs_request(rq));
> +		/*
> +		 * If we're going to unplug the device, do it now before
> +		 * we put a potentially small and mergeable new
> +		 * request on the queue, instead of just after it.
> +		 */
> +		if (blk_queue_plugged(q)) {
> +			int nrq = q->rq.count[READ] + q->rq.count[WRITE]
> +				- q->in_flight;
> +			if (nrq >= q->unplug_thresh)
> +				__generic_unplug_device(q);
> +			if (elv_queue_empty(q))
> +				blk_plug_device(q);
> +			unplug_it = 0;
> +		}
>  		rq->cmd_flags |= REQ_SORTED;
>  		q->nr_sorted++;
>  		if (rq_mergeable(rq)) {

This makes sense, I'll throw it into the 2.6.29 mix for some testing.
I've slightly modified your patch, there's no need to check for queue
empty and plug on your own, __make_request() will do that.

-- 
Jens Axboe


      reply	other threads:[~2008-10-31  7:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-23 16:13 [PATCH] elevator.c: prevent flushing small requests to device Miquel van Smoorenburg
2008-10-31  7:33 ` Jens Axboe [this message]

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=20081031073338.GZ31673@kernel.dk \
    --to=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikevs@xs4all.net \
    /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