diff options
author | Junichi Nomura <j-nomura@ce.jp.nec.com> | 2014-10-03 17:27:12 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-10-03 17:28:18 -0400 |
commit | d8f429e1669b9709f5b669aac9d734dbe0640891 (patch) | |
tree | c14ac256f51a230b472ada1525d2e7275f266436 /block | |
parent | 11dfce509eaa35e8fc81cb50d0910c0e235fd7e2 (diff) |
block: add bioset_create_nobvec()
Users of bio_clone_fast() do not want bios with their own bvecs.
Allocating a bvec mempool as part of the bioset intended for such users
is a waste of memory.
bioset_create_nobvec() creates a bioset that doesn't have the bvec
mempool.
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/bio.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/block/bio.c b/block/bio.c index 3e6331d25d90..3e6e1986a5b2 100644 --- a/block/bio.c +++ b/block/bio.c | |||
@@ -428,6 +428,9 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs) | |||
428 | front_pad = 0; | 428 | front_pad = 0; |
429 | inline_vecs = nr_iovecs; | 429 | inline_vecs = nr_iovecs; |
430 | } else { | 430 | } else { |
431 | /* should not use nobvec bioset for nr_iovecs > 0 */ | ||
432 | if (WARN_ON_ONCE(!bs->bvec_pool && nr_iovecs > 0)) | ||
433 | return NULL; | ||
431 | /* | 434 | /* |
432 | * generic_make_request() converts recursion to iteration; this | 435 | * generic_make_request() converts recursion to iteration; this |
433 | * means if we're running beneath it, any bios we allocate and | 436 | * means if we're running beneath it, any bios we allocate and |
@@ -1900,20 +1903,9 @@ void bioset_free(struct bio_set *bs) | |||
1900 | } | 1903 | } |
1901 | EXPORT_SYMBOL(bioset_free); | 1904 | EXPORT_SYMBOL(bioset_free); |
1902 | 1905 | ||
1903 | /** | 1906 | static struct bio_set *__bioset_create(unsigned int pool_size, |
1904 | * bioset_create - Create a bio_set | 1907 | unsigned int front_pad, |
1905 | * @pool_size: Number of bio and bio_vecs to cache in the mempool | 1908 | bool create_bvec_pool) |
1906 | * @front_pad: Number of bytes to allocate in front of the returned bio | ||
1907 | * | ||
1908 | * Description: | ||
1909 | * Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller | ||
1910 | * to ask for a number of bytes to be allocated in front of the bio. | ||
1911 | * Front pad allocation is useful for embedding the bio inside | ||
1912 | * another structure, to avoid allocating extra data to go with the bio. | ||
1913 | * Note that the bio must be embedded at the END of that structure always, | ||
1914 | * or things will break badly. | ||
1915 | */ | ||
1916 | struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad) | ||
1917 | { | 1909 | { |
1918 | unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec); | 1910 | unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec); |
1919 | struct bio_set *bs; | 1911 | struct bio_set *bs; |
@@ -1938,9 +1930,11 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad) | |||
1938 | if (!bs->bio_pool) | 1930 | if (!bs->bio_pool) |
1939 | goto bad; | 1931 | goto bad; |
1940 | 1932 | ||
1941 | bs->bvec_pool = biovec_create_pool(pool_size); | 1933 | if (create_bvec_pool) { |
1942 | if (!bs->bvec_pool) | 1934 | bs->bvec_pool = biovec_create_pool(pool_size); |
1943 | goto bad; | 1935 | if (!bs->bvec_pool) |
1936 | goto bad; | ||
1937 | } | ||
1944 | 1938 | ||
1945 | bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0); | 1939 | bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0); |
1946 | if (!bs->rescue_workqueue) | 1940 | if (!bs->rescue_workqueue) |
@@ -1951,8 +1945,41 @@ bad: | |||
1951 | bioset_free(bs); | 1945 | bioset_free(bs); |
1952 | return NULL; | 1946 | return NULL; |
1953 | } | 1947 | } |
1948 | |||
1949 | /** | ||
1950 | * bioset_create - Create a bio_set | ||
1951 | * @pool_size: Number of bio and bio_vecs to cache in the mempool | ||
1952 | * @front_pad: Number of bytes to allocate in front of the returned bio | ||
1953 | * | ||
1954 | * Description: | ||
1955 | * Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller | ||
1956 | * to ask for a number of bytes to be allocated in front of the bio. | ||
1957 | * Front pad allocation is useful for embedding the bio inside | ||
1958 | * another structure, to avoid allocating extra data to go with the bio. | ||
1959 | * Note that the bio must be embedded at the END of that structure always, | ||
1960 | * or things will break badly. | ||
1961 | */ | ||
1962 | struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad) | ||
1963 | { | ||
1964 | return __bioset_create(pool_size, front_pad, true); | ||
1965 | } | ||
1954 | EXPORT_SYMBOL(bioset_create); | 1966 | EXPORT_SYMBOL(bioset_create); |
1955 | 1967 | ||
1968 | /** | ||
1969 | * bioset_create_nobvec - Create a bio_set without bio_vec mempool | ||
1970 | * @pool_size: Number of bio to cache in the mempool | ||
1971 | * @front_pad: Number of bytes to allocate in front of the returned bio | ||
1972 | * | ||
1973 | * Description: | ||
1974 | * Same functionality as bioset_create() except that mempool is not | ||
1975 | * created for bio_vecs. Saving some memory for bio_clone_fast() users. | ||
1976 | */ | ||
1977 | struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int front_pad) | ||
1978 | { | ||
1979 | return __bioset_create(pool_size, front_pad, false); | ||
1980 | } | ||
1981 | EXPORT_SYMBOL(bioset_create_nobvec); | ||
1982 | |||
1956 | #ifdef CONFIG_BLK_CGROUP | 1983 | #ifdef CONFIG_BLK_CGROUP |
1957 | /** | 1984 | /** |
1958 | * bio_associate_current - associate a bio with %current | 1985 | * bio_associate_current - associate a bio with %current |