[PATCH] block: bio: stop to pin pages if bio can't hold more

From: Ming Lei
Date: Sun Jan 25 2015 - 05:58:15 EST


It doesn't make sense to continue to pin user pages when
bio can't hold more pages.

Also this patch fixes possible double page release issue
when get_user_pages_fast() failure happens just after some
of pages in last round weren't added in the bio.

Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxxxxx>
---
block/bio.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 471d738..fcf0b15 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1365,9 +1365,13 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
cur_page = j;
/*
* release the pages we didn't map into the bio, if any
+ * and stop to pin pages if page can't be added.
*/
- while (j < page_limit)
- page_cache_release(pages[j++]);
+ if (j < page_limit) {
+ while (j < page_limit)
+ page_cache_release(pages[j++]);
+ break;
+ }
}

kfree(pages);
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/