[PATCH] mm: hugepage accounting fix
[sfrench/cifs-2.6.git] / fs / bio.c
index 38d3e8023a0795273595b46ef8647ebaee9952e6..1f3bb501c262bc9b94ad9e0b73c5af8acc511c90 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -123,9 +123,10 @@ static void bio_fs_destructor(struct bio *bio)
        bio_free(bio, fs_bio_set);
 }
 
-inline void bio_init(struct bio *bio)
+void bio_init(struct bio *bio)
 {
        bio->bi_next = NULL;
+       bio->bi_bdev = NULL;
        bio->bi_flags = 1 << BIO_UPTODATE;
        bio->bi_rw = 0;
        bio->bi_vcnt = 0;
@@ -252,7 +253,7 @@ inline int bio_hw_segments(request_queue_t *q, struct bio *bio)
  *     the actual data it points to. Reference count of returned
  *     bio will be one.
  */
-inline void __bio_clone(struct bio *bio, struct bio *bio_src)
+void __bio_clone(struct bio *bio, struct bio *bio_src)
 {
        request_queue_t *q = bdev_get_queue(bio_src->bi_bdev);
 
@@ -325,10 +326,31 @@ static int __bio_add_page(request_queue_t *q, struct bio *bio, struct page
        if (unlikely(bio_flagged(bio, BIO_CLONED)))
                return 0;
 
-       if (bio->bi_vcnt >= bio->bi_max_vecs)
+       if (((bio->bi_size + len) >> 9) > max_sectors)
                return 0;
 
-       if (((bio->bi_size + len) >> 9) > max_sectors)
+       /*
+        * For filesystems with a blocksize smaller than the pagesize
+        * we will often be called with the same page as last time and
+        * a consecutive offset.  Optimize this special case.
+        */
+       if (bio->bi_vcnt > 0) {
+               struct bio_vec *prev = &bio->bi_io_vec[bio->bi_vcnt - 1];
+
+               if (page == prev->bv_page &&
+                   offset == prev->bv_offset + prev->bv_len) {
+                       prev->bv_len += len;
+                       if (q->merge_bvec_fn &&
+                           q->merge_bvec_fn(q, bio, prev) < len) {
+                               prev->bv_len -= len;
+                               return 0;
+                       }
+
+                       goto done;
+               }
+       }
+
+       if (bio->bi_vcnt >= bio->bi_max_vecs)
                return 0;
 
        /*
@@ -382,12 +404,14 @@ static int __bio_add_page(request_queue_t *q, struct bio *bio, struct page
        bio->bi_vcnt++;
        bio->bi_phys_segments++;
        bio->bi_hw_segments++;
+ done:
        bio->bi_size += len;
        return len;
 }
 
 /**
  *     bio_add_pc_page -       attempt to add page to bio
+ *     @q: the target queue
  *     @bio: destination bio
  *     @page: page to add
  *     @len: vec entry length