From: "Thomas Maier" <balagi@justmail.de>
To: linux-kernel@vger.kernel.org
Cc: petero2@telia.com, akpm@osdl.org, "Jens Axboe" <jens.axboe@oracle.com>
Subject: [PATCH 2/2] 2.6.19-rc2-mm1 pktcdvd: bio write congestion using blk_congestion_wait()
Date: Tue, 17 Oct 2006 21:49:48 +0200 [thread overview]
Message-ID: <op.thkz1adbiudtyh@master> (raw)
[-- Attachment #1: Type: text/plain, Size: 502 bytes --]
Hello,
this adds a bio write queue congestion control
to the pktcdvd driver with fixed on/off marks.
It prevents that the driver consumes a unlimited
amount of write requests.
Needs this patch named:
[PATCH 1/2] 2.6.19-rc2-mm1 ll_rw_blk.c: export clear_queue_congested and set_queue_congested
I hope this code is ok now ;)
(Maybe the surrounding spin_locks can be removed,
but for atomic access to bio_write_size etc., they may
be a good thing...)
Signed-off-by: Thomas Maier <balagi@justmail.de>
[-- Attachment #2: 2-wqueue-congestion-2.6.19-rc2-mm1.patch --]
[-- Type: application/octet-stream, Size: 3555 bytes --]
diff -urpN linux-2.6.19-rc2-mm1/drivers/block/pktcdvd.c 2-wqueue-congestion-2.6.19-rc2-mm1/drivers/block/pktcdvd.c
--- linux-2.6.19-rc2-mm1/drivers/block/pktcdvd.c 2006-10-17 20:17:49.000000000 +0200
+++ 2-wqueue-congestion-2.6.19-rc2-mm1/drivers/block/pktcdvd.c 2006-10-17 20:50:34.000000000 +0200
@@ -84,6 +84,8 @@
static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
static struct proc_dir_entry *pkt_proc;
static int pktdev_major;
+static int write_congestion_on = PKT_WRITE_CONGESTION_ON;
+static int write_congestion_off = PKT_WRITE_CONGESTION_OFF;
static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */
static mempool_t *psd_pool;
@@ -894,6 +896,7 @@ static int pkt_handle_queue(struct pktcd
sector_t zone = 0; /* Suppress gcc warning */
struct pkt_rb_node *node, *first_node;
struct rb_node *n;
+ int wakeup;
VPRINTK("handle_queue\n");
@@ -966,7 +969,13 @@ try_next_bio:
pkt->write_size += bio->bi_size / CD_FRAMESIZE;
spin_unlock(&pkt->lock);
}
+ /* check write congestion marks, and if bio_queue_size is
+ below, wake up any waiters */
+ wakeup = (pd->write_congestion_on > 0
+ && pd->bio_queue_size <= pd->write_congestion_off);
spin_unlock(&pd->lock);
+ if (wakeup)
+ blk_clear_queue_congested(pd->disk->queue, WRITE);
pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2179,6 +2188,23 @@ static int pkt_make_request(request_queu
}
spin_unlock(&pd->cdrw.active_list_lock);
+ /*
+ * Test if there is enough room left in the bio work queue
+ * (queue size >= congestion on mark).
+ * If not, wait till the work queue size is below the congestion off mark.
+ */
+ spin_lock(&pd->lock);
+ if (pd->write_congestion_on > 0
+ && pd->bio_queue_size >= pd->write_congestion_on) {
+ blk_set_queue_congested(q, WRITE);
+ do {
+ spin_unlock(&pd->lock);
+ blk_congestion_wait(WRITE, HZ);
+ spin_lock(&pd->lock);
+ } while(pd->bio_queue_size > pd->write_congestion_off);
+ }
+ spin_unlock(&pd->lock);
+
/*
* No matching packet found. Store the bio in the work queue.
*/
@@ -2298,6 +2324,9 @@ static int pkt_seq_show(struct seq_file
seq_printf(m, "\tstate:\t\t\ti:%d ow:%d rw:%d ww:%d rec:%d fin:%d\n",
states[0], states[1], states[2], states[3], states[4], states[5]);
+ seq_printf(m, "\twrite congestion marks:\toff=%d on=%d\n",
+ pd->write_congestion_off,
+ pd->write_congestion_on);
return 0;
}
@@ -2474,6 +2503,9 @@ static int pkt_setup_dev(dev_t dev, dev_
init_waitqueue_head(&pd->wqueue);
pd->bio_queue = RB_ROOT;
+ pd->write_congestion_on = write_congestion_on;
+ pd->write_congestion_off = write_congestion_off;
+
disk = alloc_disk(1);
if (!disk)
goto out_mem;
diff -urpN linux-2.6.19-rc2-mm1/include/linux/pktcdvd.h 2-wqueue-congestion-2.6.19-rc2-mm1/include/linux/pktcdvd.h
--- linux-2.6.19-rc2-mm1/include/linux/pktcdvd.h 2006-10-17 20:17:49.000000000 +0200
+++ 2-wqueue-congestion-2.6.19-rc2-mm1/include/linux/pktcdvd.h 2006-10-17 20:34:53.000000000 +0200
@@ -112,6 +112,12 @@ struct pkt_ctrl_command {
#include <linux/completion.h>
#include <linux/cdrom.h>
+
+/* default bio write queue congestion marks */
+#define PKT_WRITE_CONGESTION_ON 10000
+#define PKT_WRITE_CONGESTION_OFF 9000
+
+
struct packet_settings
{
__u32 size; /* packet size in (512 byte) sectors */
@@ -271,6 +277,9 @@ struct pktcdvd_device
struct packet_iosched iosched;
struct gendisk *disk;
+
+ int write_congestion_off;
+ int write_congestion_on;
};
#endif /* __KERNEL__ */
reply other threads:[~2006-10-17 19:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=op.thkz1adbiudtyh@master \
--to=balagi@justmail.de \
--cc=akpm@osdl.org \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=petero2@telia.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 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.