All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel van Smoorenburg <mikevs@xs4all.net>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] elevator.c: prevent flushing small requests to device
Date: Thu, 23 Oct 2008 18:13:37 +0200	[thread overview]
Message-ID: <20081023161333.GA28155@xs4all.net> (raw)

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

             reply	other threads:[~2008-10-23 16:13 UTC|newest]

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

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=20081023161333.GA28155@xs4all.net \
    --to=mikevs@xs4all.net \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.