Skip to content

Commit 0a0fc96

Browse files
sboxnetLinus Torvalds
authored andcommitted
[PATCH] pktcdvd: bio write congestion using congestion_wait()
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. [akpm@osdl.org: sync with congestion_wait() renaming] Signed-off-by: Thomas Maier <balagi@justmail.de> Cc: Peter Osterlund <petero2@telia.com> Cc: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 2d4eeec commit 0a0fc96

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎drivers/block/pktcdvd.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
8585
static struct proc_dir_entry *pkt_proc;
8686
static int pktdev_major;
87+
static int write_congestion_on = PKT_WRITE_CONGESTION_ON;
88+
static int write_congestion_off = PKT_WRITE_CONGESTION_OFF;
8789
static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */
8890
static mempool_t *psd_pool;
8991

@@ -894,6 +896,7 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
894896
sector_t zone = 0; /* Suppress gcc warning */
895897
struct pkt_rb_node *node, *first_node;
896898
struct rb_node *n;
899+
int wakeup;
897900

898901
VPRINTK("handle_queue\n");
899902

@@ -966,7 +969,13 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
966969
pkt->write_size += bio->bi_size / CD_FRAMESIZE;
967970
spin_unlock(&pkt->lock);
968971
}
972+
/* check write congestion marks, and if bio_queue_size is
973+
below, wake up any waiters */
974+
wakeup = (pd->write_congestion_on > 0
975+
&& pd->bio_queue_size <= pd->write_congestion_off);
969976
spin_unlock(&pd->lock);
977+
if (wakeup)
978+
blk_clear_queue_congested(pd->disk->queue, WRITE);
970979

971980
pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
972981
pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2179,6 +2188,23 @@ static int pkt_make_request(request_queue_t *q, struct bio *bio)
21792188
}
21802189
spin_unlock(&pd->cdrw.active_list_lock);
21812190

2191+
/*
2192+
* Test if there is enough room left in the bio work queue
2193+
* (queue size >= congestion on mark).
2194+
* If not, wait till the work queue size is below the congestion off mark.
2195+
*/
2196+
spin_lock(&pd->lock);
2197+
if (pd->write_congestion_on > 0
2198+
&& pd->bio_queue_size >= pd->write_congestion_on) {
2199+
blk_set_queue_congested(q, WRITE);
2200+
do {
2201+
spin_unlock(&pd->lock);
2202+
congestion_wait(WRITE, HZ);
2203+
spin_lock(&pd->lock);
2204+
} while(pd->bio_queue_size > pd->write_congestion_off);
2205+
}
2206+
spin_unlock(&pd->lock);
2207+
21822208
/*
21832209
* No matching packet found. Store the bio in the work queue.
21842210
*/
@@ -2298,6 +2324,9 @@ static int pkt_seq_show(struct seq_file *m, void *p)
22982324
seq_printf(m, "\tstate:\t\t\ti:%d ow:%d rw:%d ww:%d rec:%d fin:%d\n",
22992325
states[0], states[1], states[2], states[3], states[4], states[5]);
23002326

2327+
seq_printf(m, "\twrite congestion marks:\toff=%d on=%d\n",
2328+
pd->write_congestion_off,
2329+
pd->write_congestion_on);
23012330
return 0;
23022331
}
23032332

@@ -2474,6 +2503,9 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
24742503
init_waitqueue_head(&pd->wqueue);
24752504
pd->bio_queue = RB_ROOT;
24762505

2506+
pd->write_congestion_on = write_congestion_on;
2507+
pd->write_congestion_off = write_congestion_off;
2508+
24772509
disk = alloc_disk(1);
24782510
if (!disk)
24792511
goto out_mem;

‎include/linux/pktcdvd.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ struct pkt_ctrl_command {
112112
#include <linux/completion.h>
113113
#include <linux/cdrom.h>
114114

115+
116+
/* default bio write queue congestion marks */
117+
#define PKT_WRITE_CONGESTION_ON 10000
118+
#define PKT_WRITE_CONGESTION_OFF 9000
119+
120+
115121
struct packet_settings
116122
{
117123
__u32 size; /* packet size in (512 byte) sectors */
@@ -271,6 +277,9 @@ struct pktcdvd_device
271277

272278
struct packet_iosched iosched;
273279
struct gendisk *disk;
280+
281+
int write_congestion_off;
282+
int write_congestion_on;
274283
};
275284

276285
#endif /* __KERNEL__ */

0 commit comments

Comments
 (0)