Patch: linux-2.5.20/fs/bio.c - ll_rw_kio made incorrect assumptions about queue handler's capabilities
Arg! I forgot to attach the patch. Here it is.
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."
fs/bio.c +20 -9
@@ -338,10 +338,12 @@**/ void ll_rw_kio (int rw,struct kiobuf *kio,struct block_device *bdev,sector_t sector) { -int i, offset, size, err, map_i, total_nr_pages, nr_pages; +int offset, size, err, map_i, total_nr_pages, nr_pages;struct bio_vec *bvec;struct bio *bio;kdev_t dev =to_kdev_t (bdev->bd_dev); +request_queue_t *q = bdev->bd_queue; +int max_bytes, max_pages; err =0 ;if ((rw &WRITE ) &&is_read_only (dev)) {
@@ -355,6 +357,7 @@ goto out; } + max_bytes = q->max_sectors <<9 ;/* * maybe kio is bigger than the max we can easily map into a bio. * if so, split it up in appropriately sized chunks.
@@ -367,8 +370,14 @@ map_i =0 ; + max_pages = (max_bytes +PAGE_MASK ) >>PAGE_SHIFT ; +if (max_pages > q->max_phys_segments) + max_pages = q->max_phys_segments; +if (max_pages > q->max_hw_segments) + max_pages = q->max_hw_segments; + next_chunk: - nr_pages =BIO_MAX_SECTORS >> (PAGE_SHIFT -9 ); + nr_pages = max_pages;if (nr_pages > total_nr_pages) nr_pages = total_nr_pages;
@@ -389,15 +398,17 @@ bio->bi_private = kio; bvec = bio->bi_io_vec; -for (i =0 ; i < nr_pages; i++, bvec++, map_i++) { +for (;total_nr_pages >0 ; bvec++) {int nbytes =PAGE_SIZE - offset;if (nbytes > size) nbytes = size; +if (nbytes > max_bytes) + nbytes = max_bytes;BUG_ON (kio->maplist[map_i] ==NULL ); -if (bio->bi_size + nbytes > (BIO_MAX_SECTORS <<9 )) +if (bio->bi_size + nbytes > max_bytes) goto queue_io; bio->bi_vcnt++;
@@ -407,14 +418,14 @@ bvec->bv_len = nbytes; bvec->bv_offset = offset; -/* -* kiobuf only has an offset into the first page -*/ - offset =0 ; + offset = (offset + nbytes) &PAGE_MASK ; +if (offset ==0 ) { + total_nr_pages--; + map_i++; + } sector += nbytes >>9 ; size -= nbytes; - total_nr_pages--; kio->offset += nbytes; }
Quoted 3 lines · Adam J. Richter
..
+max_bytes=q->max_sectors<< 9;
Does this not also need to be done in fs/mpage.c? It's just using BIO_MAX_SIZE.
What particular problem are you trying to solve here?
fs/bio.c line 378
Quoted 13 lines
/*
* maybe kio is bigger than the max we can easily map into a bio.
* if so, split it up in appropriately sized chunks.fs/bio.c +6
-0@@ -367,8 +370,14 @@ map_i =0 ; + max_pages = (max_bytes +PAGE_MASK ) >>PAGE_SHIFT ; +if (max_pages > q->max_phys_segments) + max_pages = q->max_phys_segments; +if (max_pages > q->max_hw_segments) + max_pages = q->max_hw_segments; +
I think probably this should be implemented as a block API function.
This is going to drag us back into the BIO splitting quagmire.
fs/bio.c line 380
Quoted 3 lines
fs/bio.c +1
-1next_chunk: - nr_pages =BIO_MAX_SECTORS >> (PAGE_SHIFT -9 ); + nr_pages = max_pages;
hmm. So BIO is based on PAGE_SIZE pages. Not PAGE_CACHE_SIZE. I currently have:
unsigned nr_bvecs = MPAGE_BIO_MAX_SIZE / PAGE_CACHE_SIZE;
Which is about the only sane way in which the pagecache BIO assembly code can go from "bytes" to "number of pages".
It's going to get interesting if someone makes PAGE_SIZE != PAGE_CACHE_SIZE.