2016-04-05 12:07:58

by Ming Lei

[permalink] [raw]
Subject: [PATCH 15/27] bcache: super: use bio_set_vec_table()

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/bcache/super.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index a296425..3f649c9 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1151,8 +1151,7 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,
dc->bdev->bd_holder = dc;

bio_init(&dc->sb_bio);
- dc->sb_bio.bi_max_vecs = 1;
- dc->sb_bio.bi_io_vec = dc->sb_bio.bi_inline_vecs;
+ bio_set_vec_table(&dc->sb_bio, dc->sb_bio.bi_inline_vecs, 1);
dc->sb_bio.bi_io_vec[0].bv_page = sb_page;
get_page(sb_page);

@@ -1812,8 +1811,8 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca)
kobject_init(&ca->kobj, &bch_cache_ktype);

bio_init(&ca->journal.bio);
- ca->journal.bio.bi_max_vecs = 8;
- ca->journal.bio.bi_io_vec = ca->journal.bio.bi_inline_vecs;
+ bio_set_vec_table(&ca->journal.bio,
+ ca->journal.bio.bi_inline_vecs, 8);

free = roundup_pow_of_two(ca->sb.nbuckets) >> 10;

@@ -1850,8 +1849,7 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
ca->bdev->bd_holder = ca;

bio_init(&ca->sb_bio);
- ca->sb_bio.bi_max_vecs = 1;
- ca->sb_bio.bi_io_vec = ca->sb_bio.bi_inline_vecs;
+ bio_set_vec_table(&ca->sb_bio, ca->sb_bio.bi_inline_vecs, 1);
ca->sb_bio.bi_io_vec[0].bv_page = sb_page;
get_page(sb_page);

--
1.9.1


2016-04-05 12:08:14

by Ming Lei

[permalink] [raw]
Subject: [PATCH 16/27] bcache: super: use bio_get_base_vec

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/bcache/super.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 3f649c9..56ad797 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -208,7 +208,12 @@ static void write_bdev_super_endio(struct bio *bio)

static void __write_super(struct cache_sb *sb, struct bio *bio)
{
- struct cache_sb *out = page_address(bio->bi_io_vec[0].bv_page);
+ /*
+ * For accessing page pointed to by the 1st bvec, it
+ * works too after multipage bvecs.
+ */
+ struct bio_vec *bvec = bio_get_base_vec(bio);
+ struct cache_sb *out = page_address(bvec->bv_page);
unsigned i;

bio->bi_iter.bi_sector = SB_SECTOR;
@@ -1145,6 +1150,7 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,
char name[BDEVNAME_SIZE];
const char *err = "cannot allocate memory";
struct cache_set *c;
+ struct bio_vec *bvec;

memcpy(&dc->sb, sb, sizeof(struct cache_sb));
dc->bdev = bdev;
@@ -1152,7 +1158,8 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,

bio_init(&dc->sb_bio);
bio_set_vec_table(&dc->sb_bio, dc->sb_bio.bi_inline_vecs, 1);
- dc->sb_bio.bi_io_vec[0].bv_page = sb_page;
+ bvec = bio_get_base_vec(&dc->sb_bio);
+ bvec->bv_page = sb_page;
get_page(sb_page);

if (cached_dev_init(dc, sb->block_size << 9))
@@ -1776,6 +1783,7 @@ void bch_cache_release(struct kobject *kobj)
{
struct cache *ca = container_of(kobj, struct cache, kobj);
unsigned i;
+ struct bio_vec *bvec = bio_get_base_vec(&ca->sb_bio);

if (ca->set) {
BUG_ON(ca->set->cache[ca->sb.nr_this_dev] != ca);
@@ -1793,7 +1801,7 @@ void bch_cache_release(struct kobject *kobj)
free_fifo(&ca->free[i]);

if (ca->sb_bio.bi_inline_vecs[0].bv_page)
- put_page(ca->sb_bio.bi_io_vec[0].bv_page);
+ put_page(bvec->bv_page);

if (!IS_ERR_OR_NULL(ca->bdev))
blkdev_put(ca->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
@@ -1843,6 +1851,7 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
char name[BDEVNAME_SIZE];
const char *err = NULL;
int ret = 0;
+ struct bio_vec *bvec;

memcpy(&ca->sb, sb, sizeof(struct cache_sb));
ca->bdev = bdev;
@@ -1850,7 +1859,8 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,

bio_init(&ca->sb_bio);
bio_set_vec_table(&ca->sb_bio, ca->sb_bio.bi_inline_vecs, 1);
- ca->sb_bio.bi_io_vec[0].bv_page = sb_page;
+ bvec = bio_get_base_vec(&ca->sb_bio);
+ bvec->bv_page = sb_page;
get_page(sb_page);

if (blk_queue_discard(bdev_get_queue(ca->bdev)))
--
1.9.1

2016-04-05 12:08:31

by Ming Lei

[permalink] [raw]
Subject: [PATCH 17/27] dm: crypt: use bio_add_page()

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/dm-crypt.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 4f3cb35..a2805c1 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -995,7 +995,6 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
gfp_t gfp_mask = GFP_NOWAIT | __GFP_HIGHMEM;
unsigned i, len, remaining_size;
struct page *page;
- struct bio_vec *bvec;

retry:
if (unlikely(gfp_mask & __GFP_DIRECT_RECLAIM))
@@ -1020,12 +1019,7 @@ retry:

len = (remaining_size > PAGE_SIZE) ? PAGE_SIZE : remaining_size;

- bvec = &clone->bi_io_vec[clone->bi_vcnt++];
- bvec->bv_page = page;
- bvec->bv_len = len;
- bvec->bv_offset = 0;
-
- clone->bi_iter.bi_size += len;
+ bio_add_page(clone, page, len, 0);

remaining_size -= len;
}
--
1.9.1

2016-04-05 12:08:41

by Ming Lei

[permalink] [raw]
Subject: [PATCH 18/27] dm: dm-io.c: use bio_get_base_vec()

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/dm-io.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 06d426e..6b0e466 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -221,7 +221,12 @@ static void bio_dp_init(struct dpages *dp, struct bio *bio)
{
dp->get_page = bio_get_page;
dp->next_page = bio_next_page;
- dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
+
+ /*
+ * need to fix both bio_get_page() and bio_next_page()
+ * before multipage bvecs
+ */
+ dp->context_ptr = bio_get_base_vec(bio);
dp->context_u = bio->bi_iter.bi_bvec_done;
}

--
1.9.1

2016-04-05 12:08:52

by Ming Lei

[permalink] [raw]
Subject: [PATCH 19/27] dm: dm.c: replace 'bio->bi_vcnt == 1' with !bio_multiple_segments

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/dm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index be49057..4c34f88 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2172,7 +2172,8 @@ static void dm_request_fn(struct request_queue *q)
pos = blk_rq_pos(rq);

if ((dm_request_peeked_before_merge_deadline(md) &&
- md_in_flight(md) && rq->bio && rq->bio->bi_vcnt == 1 &&
+ md_in_flight(md) && rq->bio &&
+ !bio_multiple_segments(rq->bio) &&
md->last_rq_pos == pos && md->last_rq_rw == rq_data_dir(rq)) ||
(ti->type->busy && ti->type->busy(ti))) {
blk_delay_queue(q, HZ / 100);
--
1.9.1

2016-04-05 12:09:06

by Ming Lei

[permalink] [raw]
Subject: [PATCH 20/27] dm: dm-bufio.c: use bio_set_vec_table()

Signed-off-by: Ming Lei <[email protected]>
---
drivers/md/dm-bufio.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index cd77216..0e48ad7 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -624,8 +624,7 @@ static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
int len;

bio_init(&b->bio);
- b->bio.bi_io_vec = b->bio_vec;
- b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS;
+ bio_set_vec_table(&b->bio, b->bio_vec, DM_BUFIO_INLINE_VECS);
b->bio.bi_iter.bi_sector = block << b->c->sectors_per_block_bits;
b->bio.bi_bdev = b->c->bdev;
b->bio.bi_end_io = inline_endio;
--
1.9.1

2016-04-05 12:09:21

by Ming Lei

[permalink] [raw]
Subject: [PATCH 21/27] fs: logfs: use bio_set_vec_table()

Signed-off-by: Ming Lei <[email protected]>
---
fs/logfs/dev_bdev.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index a709d80..bc422bc9 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -20,8 +20,7 @@ static int sync_request(struct page *page, struct block_device *bdev, int rw)
struct bio_vec bio_vec;

bio_init(&bio);
- bio.bi_max_vecs = 1;
- bio.bi_io_vec = &bio_vec;
+ bio_set_vec_table(&bio, &bio_vec, 1);
bio_vec.bv_page = page;
bio_vec.bv_len = PAGE_SIZE;
bio_vec.bv_offset = 0;
--
1.9.1

2016-04-05 12:09:33

by Ming Lei

[permalink] [raw]
Subject: [PATCH 22/27] fs: logfs: convert to bio_add_page() in sync_request()

Signed-off-by: Ming Lei <[email protected]>
---
fs/logfs/dev_bdev.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index bc422bc9..957c237 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -21,13 +21,10 @@ static int sync_request(struct page *page, struct block_device *bdev, int rw)

bio_init(&bio);
bio_set_vec_table(&bio, &bio_vec, 1);
- bio_vec.bv_page = page;
- bio_vec.bv_len = PAGE_SIZE;
- bio_vec.bv_offset = 0;
- bio.bi_vcnt = 1;
bio.bi_bdev = bdev;
bio.bi_iter.bi_sector = page->index * (PAGE_SIZE >> 9);
- bio.bi_iter.bi_size = PAGE_SIZE;
+
+ bio_add_page(&bio, page, PAGE_SIZE, 0);

return submit_bio_wait(rw, &bio);
}
--
1.9.1

2016-04-05 12:09:46

by Ming Lei

[permalink] [raw]
Subject: [PATCH 23/27] fs: logfs: use bio_add_page() in __bdev_writeseg()

Also this patch simplify the code a bit.

Signed-off-by: Ming Lei <[email protected]>
---
fs/logfs/dev_bdev.c | 51 +++++++++++++++++++++------------------------------
1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 957c237..1df84e0 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -72,54 +72,45 @@ static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index,
{
struct logfs_super *super = logfs_super(sb);
struct address_space *mapping = super->s_mapping_inode->i_mapping;
- struct bio *bio;
+ struct bio *bio = NULL;
struct page *page;
unsigned int max_pages;
- int i;
+ int i, ret;

max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES);

- bio = bio_alloc(GFP_NOFS, max_pages);
- BUG_ON(!bio);
-
for (i = 0; i < nr_pages; i++) {
- if (i >= max_pages) {
- /* Block layer cannot split bios :( */
- bio->bi_vcnt = i;
- bio->bi_iter.bi_size = i * PAGE_SIZE;
+ if (!bio) {
+ bio = bio_alloc(GFP_NOFS, max_pages);
+ BUG_ON(!bio);
bio->bi_bdev = super->s_bdev;
bio->bi_iter.bi_sector = ofs >> 9;
bio->bi_private = sb;
bio->bi_end_io = writeseg_end_io;
- atomic_inc(&super->s_pending_writes);
- submit_bio(WRITE, bio);
-
- ofs += i * PAGE_SIZE;
- index += i;
- nr_pages -= i;
- i = 0;
-
- bio = bio_alloc(GFP_NOFS, max_pages);
- BUG_ON(!bio);
}
+
page = find_lock_page(mapping, index + i);
BUG_ON(!page);
- bio->bi_io_vec[i].bv_page = page;
- bio->bi_io_vec[i].bv_len = PAGE_SIZE;
- bio->bi_io_vec[i].bv_offset = 0;
+
+ ret = bio_add_page(bio, page, PAGE_SIZE, 0);

BUG_ON(PageWriteback(page));
set_page_writeback(page);
unlock_page(page);
+ if (!ret) {
+ /* Block layer cannot split bios :( */
+ ofs += bio->bi_iter.bi_size;
+ atomic_inc(&super->s_pending_writes);
+ submit_bio(WRITE, bio);
+
+ bio = NULL;
+ }
+ }
+
+ if (bio) {
+ atomic_inc(&super->s_pending_writes);
+ submit_bio(WRITE, bio);
}
- bio->bi_vcnt = nr_pages;
- bio->bi_iter.bi_size = nr_pages * PAGE_SIZE;
- bio->bi_bdev = super->s_bdev;
- bio->bi_iter.bi_sector = ofs >> 9;
- bio->bi_private = sb;
- bio->bi_end_io = writeseg_end_io;
- atomic_inc(&super->s_pending_writes);
- submit_bio(WRITE, bio);
return 0;
}

--
1.9.1

2016-04-05 12:10:05

by Ming Lei

[permalink] [raw]
Subject: [PATCH 24/27] fs: logfs: use bio_add_page() in do_erase()

Also code gets simplified a bit.

Signed-off-by: Ming Lei <[email protected]>
---
fs/logfs/dev_bdev.c | 45 ++++++++++++++++++---------------------------
1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 1df84e0..db04231 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -154,47 +154,38 @@ static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index,
size_t nr_pages)
{
struct logfs_super *super = logfs_super(sb);
- struct bio *bio;
+ struct bio *bio = NULL;
unsigned int max_pages;
- int i;
+ int i, ret;

max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES);

- bio = bio_alloc(GFP_NOFS, max_pages);
- BUG_ON(!bio);
-
for (i = 0; i < nr_pages; i++) {
- if (i >= max_pages) {
- /* Block layer cannot split bios :( */
- bio->bi_vcnt = i;
- bio->bi_iter.bi_size = i * PAGE_SIZE;
+ if (!bio) {
+ bio = bio_alloc(GFP_NOFS, max_pages);
+ BUG_ON(!bio);
+
bio->bi_bdev = super->s_bdev;
bio->bi_iter.bi_sector = ofs >> 9;
bio->bi_private = sb;
bio->bi_end_io = erase_end_io;
+ }
+
+ ret = bio_add_page(bio, super->s_erase_page, PAGE_SIZE, 0);
+ if (!ret) {
+ /* Block layer cannot split bios :( */
+ ofs += bio->bi_iter.bi_size;
atomic_inc(&super->s_pending_writes);
submit_bio(WRITE, bio);

- ofs += i * PAGE_SIZE;
- index += i;
- nr_pages -= i;
- i = 0;
-
- bio = bio_alloc(GFP_NOFS, max_pages);
- BUG_ON(!bio);
+ bio = NULL;
}
- bio->bi_io_vec[i].bv_page = super->s_erase_page;
- bio->bi_io_vec[i].bv_len = PAGE_SIZE;
- bio->bi_io_vec[i].bv_offset = 0;
}
- bio->bi_vcnt = nr_pages;
- bio->bi_iter.bi_size = nr_pages * PAGE_SIZE;
- bio->bi_bdev = super->s_bdev;
- bio->bi_iter.bi_sector = ofs >> 9;
- bio->bi_private = sb;
- bio->bi_end_io = erase_end_io;
- atomic_inc(&super->s_pending_writes);
- submit_bio(WRITE, bio);
+
+ if (bio) {
+ atomic_inc(&super->s_pending_writes);
+ submit_bio(WRITE, bio);
+ }
return 0;
}

--
1.9.1

2016-04-05 12:10:21

by Ming Lei

[permalink] [raw]
Subject: [PATCH 25/27] fs: logfs: remove unnecesary check

The check on bio->bi_vcnt doesn't make sense in erase_end_io().

Signed-off-by: Ming Lei <[email protected]>
---
fs/logfs/dev_bdev.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index db04231..3d9cde7 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -144,7 +144,6 @@ static void erase_end_io(struct bio *bio)
struct logfs_super *super = logfs_super(sb);

BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */
- BUG_ON(bio->bi_vcnt == 0);
bio_put(bio);
if (atomic_dec_and_test(&super->s_pending_writes))
wake_up(&wq);
--
1.9.1

2016-04-05 12:10:37

by Ming Lei

[permalink] [raw]
Subject: [PATCH 26/27] kernel/power/swap.c: use bio_get_base_vec()

Signed-off-by: Ming Lei <[email protected]>
---
kernel/power/swap.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 12cd989..cedf752 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -230,7 +230,15 @@ static void hib_init_batch(struct hib_bio_batch *hb)
static void hib_end_io(struct bio *bio)
{
struct hib_bio_batch *hb = bio->bi_private;
- struct page *page = bio->bi_io_vec[0].bv_page;
+
+ /*
+ * Single bvec bio.
+ *
+ * For accessing page pointed to by the 1st bvec, it
+ * works too after multipage bvecs.
+ */
+ struct bio_vec *bvec = bio_get_base_vec(bio);
+ struct page *page = bvec->bv_page;

if (bio->bi_error) {
printk(KERN_ALERT "Read-error on swap-device (%u:%u:%Lu)\n",
--
1.9.1

2016-04-05 12:10:47

by Ming Lei

[permalink] [raw]
Subject: [PATCH 27/27] mm: page_io.c: use bio_get_base_vec()

Signed-off-by: Ming Lei <[email protected]>
---
mm/page_io.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 18aac78..b5a6baf 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -43,7 +43,14 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,

void end_swap_bio_write(struct bio *bio)
{
- struct page *page = bio->bi_io_vec[0].bv_page;
+ /*
+ * Single bvec bio.
+ *
+ * For accessing page pointed to by the 1st bvec, it
+ * works too after multipage bvecs.
+ */
+ struct bio_vec *bvec = bio_get_base_vec(bio);
+ struct page *page = bvec->bv_page;

if (bio->bi_error) {
SetPageError(page);
@@ -116,7 +123,14 @@ static void swap_slot_free_notify(struct page *page)

static void end_swap_bio_read(struct bio *bio)
{
- struct page *page = bio->bi_io_vec[0].bv_page;
+ /*
+ * Single bvec bio.
+ *
+ * For accessing page pointed to by the 1st bvec, it
+ * works too after multipage bvecs.
+ */
+ struct bio_vec *bvec = bio_get_base_vec(bio);
+ struct page *page = bvec->bv_page;

if (bio->bi_error) {
SetPageError(page);
--
1.9.1

2016-04-05 12:49:27

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 17/27] dm: crypt: use bio_add_page()

Looks fine,

Reviewed-by: Christoph Hellwig <[email protected]>

2016-04-05 12:50:31

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 21/27] fs: logfs: use bio_set_vec_table()

On Tue, Apr 05, 2016 at 08:07:36PM +0800, Ming Lei wrote:
> Signed-off-by: Ming Lei <[email protected]>

Need to be converted to bio_alloc instead.

2016-04-05 12:56:35

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 26/27] kernel/power/swap.c: use bio_get_base_vec()

I really don't like all these bio_get_base_vec uses. The end_io
handlers generall want to iterate over all pages in the bio, with
a special case where all of them is the fixed number one.

So What I think we'll need is a bio_for_each_page, and if there is
any good justification for it as special version of the single
page case.

2016-04-05 13:04:19

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 20/27] dm: dm-bufio.c: use bio_set_vec_table()

On Tue, Apr 05, 2016 at 08:07:35PM +0800, Ming Lei wrote:
> Signed-off-by: Ming Lei <[email protected]>
> ---
> drivers/md/dm-bufio.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index cd77216..0e48ad7 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c
> @@ -624,8 +624,7 @@ static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
> int len;
>
> bio_init(&b->bio);
> - b->bio.bi_io_vec = b->bio_vec;
> - b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS;
> + bio_set_vec_table(&b->bio, b->bio_vec, DM_BUFIO_INLINE_VECS);
> b->bio.bi_iter.bi_sector = block << b->c->sectors_per_block_bits;
> b->bio.bi_bdev = b->c->bdev;
> b->bio.bi_end_io = inline_endio;

Should be switched to use bio_alloc instead.

2016-04-05 13:19:35

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH 26/27] kernel/power/swap.c: use bio_get_base_vec()

On Tue, Apr 5, 2016 at 8:56 PM, Christoph Hellwig <[email protected]> wrote:
> I really don't like all these bio_get_base_vec uses. The end_io
> handlers generall want to iterate over all pages in the bio, with
> a special case where all of them is the fixed number one.
>
> So What I think we'll need is a bio_for_each_page, and if there is
> any good justification for it as special version of the single
> page case.

I thought about that too, and bio_get_base_vec() can be thought as
the special version too, IMO. Actually it is just about the name of
the helper, do you have a better name or other idea for such issue?

There are about ten such usages, as found in this patchset.


Thanks,
Ming Lei

2016-04-05 18:11:30

by Mike Snitzer

[permalink] [raw]
Subject: Re: [PATCH 20/27] dm: dm-bufio.c: use bio_set_vec_table()

On Tue, Apr 05 2016 at 9:04am -0400,
Christoph Hellwig <[email protected]> wrote:

> On Tue, Apr 05, 2016 at 08:07:35PM +0800, Ming Lei wrote:
> > Signed-off-by: Ming Lei <[email protected]>
> > ---
> > drivers/md/dm-bufio.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> > index cd77216..0e48ad7 100644
> > --- a/drivers/md/dm-bufio.c
> > +++ b/drivers/md/dm-bufio.c
> > @@ -624,8 +624,7 @@ static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
> > int len;
> >
> > bio_init(&b->bio);
> > - b->bio.bi_io_vec = b->bio_vec;
> > - b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS;
> > + bio_set_vec_table(&b->bio, b->bio_vec, DM_BUFIO_INLINE_VECS);
> > b->bio.bi_iter.bi_sector = block << b->c->sectors_per_block_bits;
> > b->bio.bi_bdev = b->c->bdev;
> > b->bio.bi_end_io = inline_endio;
>
> Should be switched to use bio_alloc instead.

Why does the use of bio_init() vs bio_alloc() bother you?

'struct dm_buffer' has a 'struct bio'. That bio is allocated as part of
the dm_buffer in drivers/md/dmbufio.c:alloc_buffer() -- which is called
by various other bufio interfaces (e.g. __alloc_buffer_wait). Bufio is
in control of ensuring forward progress by carefully managing the memory
associated with these buffers. I don't see the benefit of bio_alloc()
here. What am I missing?