[1/1] Block device throttling [Re: Distributed storage.]

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Evgeniy Polyakov
Date: Wednesday, August 8, 2007 - 3:17 am

This throttling mechanism allows to limit maximum amount of queued bios 
per physical device. By default it is turned off and old block layer 
behaviour with unlimited number of bios is used. When turned on (queue
limit is set to something different than -1U via blk_set_queue_limit()),
generic_make_request() will sleep until there is room in the queue.
number of bios is increased in generic_make_request() and reduced either
in bio_endio(), when bio is completely processed (bi_size is zero), and
recharged from original queue when new device is assigned to bio via
blk_set_bdev(). All oerations are not atomic, since we do not care about
precise number of bios, but a fact, that we are close or close enough to
the limit.

Tested on distributed storage device - with limit of 2 bios it works
slow :)

Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>

diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index c99b463..1882c9b 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1851,6 +1851,10 @@ request_queue_t *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
 	q->backing_dev_info.unplug_io_fn = blk_backing_dev_unplug;
 	q->backing_dev_info.unplug_io_data = q;
 
+	q->bio_limit = -1U;
+	q->bio_queued = 0;
+	init_waitqueue_head(&q->wait);
+
 	mutex_init(&q->sysfs_lock);
 
 	return q;
@@ -3237,6 +3241,16 @@ end_io:
  */
 void generic_make_request(struct bio *bio)
 {
+	request_queue_t *q;
+
+	BUG_ON(!bio->bi_bdev)
+
+	q = bdev_get_queue(bio->bi_bdev);
+	if (q && q->bio_limit != -1U) {
+		wait_event_interruptible(q->wait, q->bio_queued + 1 <= q->bio_limit);
+		q->bio_queued++;
+	}
+
 	if (current->bio_tail) {
 		/* make_request is active */
 		*(current->bio_tail) = bio;
diff --git a/fs/bio.c b/fs/bio.c
index 093345f..0a33958 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1028,6 +1028,16 @@ void bio_endio(struct bio *bio, unsigned int bytes_done, int error)
 	bio->bi_size -= bytes_done;
 	bio->bi_sector += (bytes_done >> 9);
 
+	if (!bio->bi_size && bio->bi_bdev) {
+		request_queue_t *q;
+
+		q = bdev_get_queue(bio->bi_bdev);
+		if (q) {
+			q->bio_queued--;
+			wake_up(&q->wait);
+		}
+	}
+
 	if (bio->bi_end_io)
 		bio->bi_end_io(bio, bytes_done, error);
 }
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index db5b00a..7ce0cd7 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -467,6 +467,9 @@ struct request_queue
 	struct request		*orig_bar_rq;
 	unsigned int		bi_size;
 
+	wait_queue_head_t	wait;
+	unsigned int		bio_limit, bio_queued;
+
 	struct mutex		sysfs_lock;
 };
 
@@ -764,6 +767,30 @@ extern long nr_blockdev_pages(void);
 int blk_get_queue(request_queue_t *);
 request_queue_t *blk_alloc_queue(gfp_t);
 request_queue_t *blk_alloc_queue_node(gfp_t, int);
+
+static inline void blk_queue_set_limit(request_queue_t *q, unsigned int limit)
+{
+	q->bio_limit = limit;
+}
+
+static inline void blk_set_bdev(struct bio *bio, struct block_device *bdev)
+{
+	request_queue_t *q;
+
+	if (!bio->bi_bdev) {
+		bio->bi_bdev = bdev;
+		return;
+	}
+	
+	q = bdev_get_queue(bio->bi_bdev);
+	if (q) {
+		q->bio_queued--;
+		wake_up(&q->wait);
+	}
+
+	bio->bi_bdev = bdev;
+}
+
 extern void blk_put_queue(request_queue_t *);
 
 /*

-- 
	Evgeniy Polyakov
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Distributed storage., Evgeniy Polyakov, (Tue Jul 31, 10:13 am)
Re: Distributed storage., Daniel Phillips, (Thu Aug 2, 2:08 pm)
Re: Distributed storage., Mike Snitzer, (Thu Aug 2, 9:09 pm)
Re: Distributed storage., Manu Abraham, (Thu Aug 2, 10:04 pm)
Re: Distributed storage., Evgeniy Polyakov, (Fri Aug 3, 3:26 am)
Re: Distributed storage., Evgeniy Polyakov, (Fri Aug 3, 3:42 am)
Re: Distributed storage., Evgeniy Polyakov, (Fri Aug 3, 3:44 am)
Re: Distributed storage., Evgeniy Polyakov, (Fri Aug 3, 3:57 am)
Re: Distributed storage., Peter Zijlstra, (Fri Aug 3, 5:27 am)
Re: Distributed storage., Evgeniy Polyakov, (Fri Aug 3, 6:49 am)
Re: Distributed storage., Peter Zijlstra, (Fri Aug 3, 7:53 am)
Re: Distributed storage., Daniel Phillips, (Fri Aug 3, 12:41 pm)
Re: Distributed storage., Daniel Phillips, (Fri Aug 3, 12:48 pm)
Re: Distributed storage., Daniel Phillips, (Fri Aug 3, 5:41 pm)
Re: Distributed storage., Daniel Phillips, (Fri Aug 3, 5:49 pm)
Re: Distributed storage., Daniel Phillips, (Fri Aug 3, 6:19 pm)
Re: Distributed storage., Dave Dillow, (Fri Aug 3, 7:51 pm)
Re: Distributed storage., Manu Abraham, (Fri Aug 3, 8:44 pm)
Re: Distributed storage., Evgeniy Polyakov, (Sat Aug 4, 9:37 am)
Re: Distributed storage., Evgeniy Polyakov, (Sat Aug 4, 9:44 am)
Re: Distributed storage., Evgeniy Polyakov, (Sat Aug 4, 10:03 am)
Re: Distributed storage., Daniel Phillips, (Sun Aug 5, 1:04 am)
Re: Distributed storage., Daniel Phillips, (Sun Aug 5, 1:06 am)
Re: Distributed storage., Evgeniy Polyakov, (Sun Aug 5, 8:01 am)
Re: Distributed storage., Evgeniy Polyakov, (Sun Aug 5, 8:08 am)
Re: Distributed storage., Daniel Phillips, (Sun Aug 5, 2:23 pm)
Re: Distributed storage., Daniel Phillips, (Sun Aug 5, 2:35 pm)
Re: Distributed storage., Evgeniy Polyakov, (Mon Aug 6, 1:25 am)
Re: Distributed storage., Evgeniy Polyakov, (Mon Aug 6, 1:28 am)
Re: Distributed storage., Jens Axboe, (Tue Aug 7, 5:05 am)
Re: Distributed storage., Daniel Phillips, (Tue Aug 7, 11:24 am)
Re: Distributed storage., Jens Axboe, (Tue Aug 7, 1:55 pm)
Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Wed Aug 8, 2:54 am)
[1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Wed Aug 8, 3:17 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Wed Aug 8, 6:28 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Daniel Phillips, (Sun Aug 12, 4:16 pm)
Re: Distributed storage., Daniel Phillips, (Sun Aug 12, 4:36 pm)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Sun Aug 12, 10:22 pm)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Sun Aug 12, 10:36 pm)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Sun Aug 12, 11:44 pm)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 12:28 am)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 12:45 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 1:14 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 1:18 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 1:23 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 1:59 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 2:08 am)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 2:12 am)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 2:13 am)
Re: Distributed storage., Evgeniy Polyakov, (Mon Aug 13, 2:18 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 2:55 am)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 3:06 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 3:12 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 3:15 am)
Re: Distributed storage., Jens Axboe, (Mon Aug 13, 3:22 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 3:32 am)
Re: Distributed storage., Evgeniy Polyakov, (Mon Aug 13, 4:03 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Mon Aug 13, 4:04 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Mon Aug 13, 4:18 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 4:45 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 5:04 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 5:18 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Mon Aug 13, 5:18 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Mon Aug 13, 5:24 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Mon Aug 13, 6:04 am)
Re: Distributed storage., Daniel Phillips, (Mon Aug 13, 4:27 pm)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 14, 1:46 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 14, 4:13 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 14, 4:30 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 14, 4:35 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 14, 4:50 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 14, 5:32 am)
Re: Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 14, 5:46 am)
Re: Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 14, 5:54 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Daniel Phillips, (Mon Aug 27, 2:57 pm)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 28, 2:35 am)
Re: Distributed storage., Evgeniy Polyakov, (Tue Aug 28, 10:19 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 28, 10:27 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Tue Aug 28, 10:54 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Daniel Phillips, (Tue Aug 28, 2:08 pm)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Wed Aug 29, 1:53 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Daniel Phillips, (Thu Aug 30, 4:20 pm)
Re: [1/1] Block device throttling [Re: Distributed storage.], Evgeniy Polyakov, (Fri Aug 31, 10:33 am)
Re: [1/1] Block device throttling [Re: Distributed storage.], Alasdair G Kergon, (Fri Aug 31, 2:41 pm)