History

[BLOCK] bio: check for same page merge possibilities in __bio_add_page()

For filesystems with a blocksize < page size, we can merge same page calls into the bio_vec at the end of the bio. This saves segments on systems with a page size > the "normal" 4kb fs block size.

Jens Axboe committed 20 years ago

Commit 80cfd541 parent 88ee5ef1 file · +24 −2Browse files

Unified · Split

fs/bio.c+24−2
@@ -325,10 +325,31 @@ static int __bio_add_page(request_queue_t *q, struct bio *bio, struct page · 324 unmodified lines
325325 if (unlikely(bio_flagged(bio, BIO_CLONED)))
326326 return 0;
327327
328− if (bio->bi_vcnt >= bio->bi_max_vecs)
328+ if (((bio->bi_size + len) >> 9) > max_sectors)
329329 return 0;
330330
331− if (((bio->bi_size + len) >> 9) > max_sectors)
331+ /*
332+ * For filesystems with a blocksize smaller than the pagesize
333+ * we will often be called with the same page as last time and
334+ * a consecutive offset. Optimize this special case.
335+ */
336+ if (bio->bi_vcnt > 0) {
337+ struct bio_vec *prev = &bio->bi_io_vec[bio->bi_vcnt - 1];
338+
339+ if (page == prev->bv_page &&
340+ offset == prev->bv_offset + prev->bv_len) {
341+ prev->bv_len += len;
342+ if (q->merge_bvec_fn &&
343+ q->merge_bvec_fn(q, bio, prev) < len) {
344+ prev->bv_len -= len;
345+ return 0;
346+ }
347+
348+ goto done;
349+ }
350+ }
351+
352+ if (bio->bi_vcnt >= bio->bi_max_vecs)
332353 return 0;
333354
334355 /*
@@ -382,6 +403,7 @@ static int __bio_add_page(request_queue_t *q, struct bio *bio, struct page · 47 unmodified lines
382403 bio->bi_vcnt++;
383404 bio->bi_phys_segments++;
384405 bio->bi_hw_segments++;
406+ done:
385407 bio->bi_size += len;
386408 return len;
387409 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t