Commit 63b9d36d authored by Jens Axboe's avatar Jens Axboe

[PATCH] bio_get_nr_vecs

Add bio_get_nr_vecs(). It returns an approximate number of pages that
can be added to a block device. It's just a ballpark number, but I think
this is quite fine for the type of thing it is needed for: mpage etc
need to know an approx size of a bio that they need to allocate. It
would be silly to continously allocate 64-page sized bio_vec entries, if
the target cannot do more than 8, for example.
parent 58c1b542
...@@ -321,6 +321,29 @@ struct bio *bio_copy(struct bio *bio, int gfp_mask, int copy) ...@@ -321,6 +321,29 @@ struct bio *bio_copy(struct bio *bio, int gfp_mask, int copy)
return NULL; return NULL;
} }
/**
* bio_get_nr_vecs - return approx number of vecs
* @bdev: I/O target
*
* Return the approximate number of pages we can send to this target.
* There's no guarentee that you will be able to fit this number of pages
* into a bio, it does not account for dynamic restrictions that vary
* on offset.
*/
int bio_get_nr_vecs(struct block_device *bdev)
{
request_queue_t *q = bdev_get_queue(bdev);
int nr_pages;
nr_pages = q->max_sectors >> (PAGE_SHIFT - 9);
if (nr_pages > q->max_phys_segments)
nr_pages = q->max_phys_segments;
if (nr_pages > q->max_hw_segments)
nr_pages = q->max_hw_segments;
return nr_pages;
}
/** /**
* bio_add_page - attempt to add page to bio * bio_add_page - attempt to add page to bio
* @bio: destination bio * @bio: destination bio
...@@ -635,3 +658,4 @@ EXPORT_SYMBOL(bio_clone); ...@@ -635,3 +658,4 @@ EXPORT_SYMBOL(bio_clone);
EXPORT_SYMBOL(bio_phys_segments); EXPORT_SYMBOL(bio_phys_segments);
EXPORT_SYMBOL(bio_hw_segments); EXPORT_SYMBOL(bio_hw_segments);
EXPORT_SYMBOL(bio_add_page); EXPORT_SYMBOL(bio_add_page);
EXPORT_SYMBOL(bio_get_nr_vecs);
...@@ -206,6 +206,7 @@ extern struct bio *bio_copy(struct bio *, int, int); ...@@ -206,6 +206,7 @@ extern struct bio *bio_copy(struct bio *, int, int);
extern inline void bio_init(struct bio *); extern inline void bio_init(struct bio *);
extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
extern int bio_get_nr_vecs(struct block_device *);
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment