Skip to contentSkip to conversation

Patch (2.5.21): bio size fixes for ll_rw_kio and mpage.c

PATCH Adam J. Richter 1 participant 1 message Jun 13, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Jens,

ll_rw_kio and the mpage.c routines could generate bio's that
are bigger than the device that they are for claims to be able to handle. That was actually causing kernel panics for a fellow and IBM, so this is an actual problem. This change has ll_rw_kio and the mpage routines calculate their maximum bio sizes from the queue parameters rather than some compiled in guesses which are too big for some devices.

A nice side effect of this change is that more flexible
I/O devices (including IDE disks, for one) can get their I/O requests in the larger chunks that they can handle.

A temporary negative side effect is that pseudo-devices
like /dev/loop and raid currently do not correctly reflect the I/O limits of the devices that they pass requests to. The real bug is in /dev/loop and the raid code. They currently export the limits set by blk_queue_make_request, which are about are about twice what mpage.c previously assumed. So, while my change eliminates the problem for mounting /dev/disc/..., it also makes it possible for the problem to happen on a couple more scsi controllers *if* the file system is mounted via /dev/loop or raid.

However, raid has not compiled for a long time under
2.5 and the loop driver quickly crashes under 2.5.21. I have a fix for the loop driver to make it constain its queue to the I/O limits of its underlying device, but not for the existing problem with /dev/loop crashing.

I would like to get this patch into 2.5.21. I will
work on fixing loop.c and the device mapper (raid replacement), and will keep an eye out for when someone gets the non-device mapper raid code running if that occurs.

Jens, do you have any objection to this going into Linus's tree?

Adam J. Richter     __     ______________   575 Oroville Road
[email protected]     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America

"Free Software For The Rest Of Us."

include/linux/bio.h +0 -3
@@ -35,9 +35,6 @@
 #define BIO_BUG_ON
 #endif
 
-#define BIO_MAX_SECTORS	128
-#define BIO_MAX_SIZE	(BIO_MAX_SECTORS << 9)
-
 /*
  * was unsigned short, but we might as well be ready for > 64kB I/O pages
  */
include/linux/blkdev.h +2 -0
@@ -415,4 +425,6 @@
 	page_cache_release(p.v);
 }
 
+extern int bio_max_iovecs(request_queue_t *q, int *iovec_size);
+
 #endif
fs/bio.c +37 -14

107 lines not on this page · raw message

fs/mpage.c +11 -9
@@ -21,12 +21,6 @@
 #include <linux/mpage.h>
 
 /*
- * The largest-sized BIO which this code will assemble, in bytes.  Set this
- * to PAGE_CACHE_SIZE if your drivers are broken.
- */
-#define MPAGE_BIO_MAX_SIZE BIO_MAX_SIZE
-
-/*
  * I/O completion handler for multipage BIOs.
  *
  * The mpage code never puts partial pages into a BIO (except for end-of-file).
@@ -220,9 +214,13 @@
 		bio = mpage_bio_submit(READ, bio);
 
 	if (bio == NULL) {
-		unsigned nr_bvecs = MPAGE_BIO_MAX_SIZE / PAGE_CACHE_SIZE;
+		int bvec_size = PAGE_CACHE_SIZE;
+		unsigned nr_bvecs = bio_max_iovecs(bdev->bd_queue,&bvec_size);
 
-		if (nr_bvecs > nr_pages)
+		if (bvec_size != PAGE_CACHE_SIZE)
+			goto confused;
+
+ 		if (nr_bvecs > nr_pages)
 			nr_bvecs = nr_pages;
 		bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
 					nr_bvecs, GFP_KERNEL);
@@ -422,7 +420,11 @@
 		bio = mpage_bio_submit(WRITE, bio);
 
 	if (bio == NULL) {
-		unsigned nr_bvecs = MPAGE_BIO_MAX_SIZE / PAGE_CACHE_SIZE;
+		int bvec_size = PAGE_CACHE_SIZE;
+		unsigned nr_bvecs = bio_max_iovecs(bdev->bd_queue,&bvec_size);
+
+		if (bvec_size != PAGE_CACHE_SIZE)
+			goto confused;
 
 		bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
 					nr_bvecs, GFP_NOFS);