Skip to content

Commit 77c436d

Browse files
Christoph Hellwigaxboe
authored andcommitted
mpage: pass the operation to bio_alloc
Refactor the mpage read/write page code to pass the op to bio_alloc instead of setting it just before the submission. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20220222154634.597067-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 451f0b6 commit 77c436d

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

fs/mpage.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ static void mpage_end_io(struct bio *bio)
5757
bio_put(bio);
5858
}
5959

60-
static struct bio *mpage_bio_submit(int op, int op_flags, struct bio *bio)
60+
static struct bio *mpage_bio_submit(struct bio *bio)
6161
{
6262
bio->bi_end_io = mpage_end_io;
63-
bio_set_op_attrs(bio, op, op_flags);
6463
guard_bio_eod(bio);
6564
submit_bio(bio);
6665
return NULL;
@@ -146,16 +145,15 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
146145
struct block_device *bdev = NULL;
147146
int length;
148147
int fully_mapped = 1;
149-
int op_flags;
148+
int op = REQ_OP_READ;
150149
unsigned nblocks;
151150
unsigned relative_block;
152151
gfp_t gfp;
153152

154153
if (args->is_readahead) {
155-
op_flags = REQ_RAHEAD;
154+
op |= REQ_RAHEAD;
156155
gfp = readahead_gfp_mask(page->mapping);
157156
} else {
158-
op_flags = 0;
159157
gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL);
160158
}
161159

@@ -264,7 +262,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
264262
* This page will go to BIO. Do we need to send this BIO off first?
265263
*/
266264
if (args->bio && (args->last_block_in_bio != blocks[0] - 1))
267-
args->bio = mpage_bio_submit(REQ_OP_READ, op_flags, args->bio);
265+
args->bio = mpage_bio_submit(args->bio);
268266

269267
alloc_new:
270268
if (args->bio == NULL) {
@@ -273,7 +271,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
273271
page))
274272
goto out;
275273
}
276-
args->bio = bio_alloc(bdev, bio_max_segs(args->nr_pages), 0,
274+
args->bio = bio_alloc(bdev, bio_max_segs(args->nr_pages), op,
277275
gfp);
278276
if (args->bio == NULL)
279277
goto confused;
@@ -282,23 +280,23 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
282280

283281
length = first_hole << blkbits;
284282
if (bio_add_page(args->bio, page, length, 0) < length) {
285-
args->bio = mpage_bio_submit(REQ_OP_READ, op_flags, args->bio);
283+
args->bio = mpage_bio_submit(args->bio);
286284
goto alloc_new;
287285
}
288286

289287
relative_block = block_in_file - args->first_logical_block;
290288
nblocks = map_bh->b_size >> blkbits;
291289
if ((buffer_boundary(map_bh) && relative_block == nblocks) ||
292290
(first_hole != blocks_per_page))
293-
args->bio = mpage_bio_submit(REQ_OP_READ, op_flags, args->bio);
291+
args->bio = mpage_bio_submit(args->bio);
294292
else
295293
args->last_block_in_bio = blocks[blocks_per_page - 1];
296294
out:
297295
return args->bio;
298296

299297
confused:
300298
if (args->bio)
301-
args->bio = mpage_bio_submit(REQ_OP_READ, op_flags, args->bio);
299+
args->bio = mpage_bio_submit(args->bio);
302300
if (!PageUptodate(page))
303301
block_read_full_page(page, args->get_block);
304302
else
@@ -361,7 +359,7 @@ void mpage_readahead(struct readahead_control *rac, get_block_t get_block)
361359
put_page(page);
362360
}
363361
if (args.bio)
364-
mpage_bio_submit(REQ_OP_READ, REQ_RAHEAD, args.bio);
362+
mpage_bio_submit(args.bio);
365363
}
366364
EXPORT_SYMBOL(mpage_readahead);
367365

@@ -378,7 +376,7 @@ int mpage_readpage(struct page *page, get_block_t get_block)
378376

379377
args.bio = do_mpage_readpage(&args);
380378
if (args.bio)
381-
mpage_bio_submit(REQ_OP_READ, 0, args.bio);
379+
mpage_bio_submit(args.bio);
382380
return 0;
383381
}
384382
EXPORT_SYMBOL(mpage_readpage);
@@ -469,7 +467,6 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
469467
struct buffer_head map_bh;
470468
loff_t i_size = i_size_read(inode);
471469
int ret = 0;
472-
int op_flags = wbc_to_write_flags(wbc);
473470

474471
if (page_has_buffers(page)) {
475472
struct buffer_head *head = page_buffers(page);
@@ -577,7 +574,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
577574
* This page will go to BIO. Do we need to send this BIO off first?
578575
*/
579576
if (bio && mpd->last_block_in_bio != blocks[0] - 1)
580-
bio = mpage_bio_submit(REQ_OP_WRITE, op_flags, bio);
577+
bio = mpage_bio_submit(bio);
581578

582579
alloc_new:
583580
if (bio == NULL) {
@@ -586,9 +583,10 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
586583
page, wbc))
587584
goto out;
588585
}
589-
bio = bio_alloc(bdev, BIO_MAX_VECS, 0, GFP_NOFS);
586+
bio = bio_alloc(bdev, BIO_MAX_VECS,
587+
REQ_OP_WRITE | wbc_to_write_flags(wbc),
588+
GFP_NOFS);
590589
bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
591-
592590
wbc_init_bio(wbc, bio);
593591
bio->bi_write_hint = inode->i_write_hint;
594592
}
@@ -601,7 +599,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
601599
wbc_account_cgroup_owner(wbc, page, PAGE_SIZE);
602600
length = first_unmapped << blkbits;
603601
if (bio_add_page(bio, page, length, 0) < length) {
604-
bio = mpage_bio_submit(REQ_OP_WRITE, op_flags, bio);
602+
bio = mpage_bio_submit(bio);
605603
goto alloc_new;
606604
}
607605

@@ -611,7 +609,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
611609
set_page_writeback(page);
612610
unlock_page(page);
613611
if (boundary || (first_unmapped != blocks_per_page)) {
614-
bio = mpage_bio_submit(REQ_OP_WRITE, op_flags, bio);
612+
bio = mpage_bio_submit(bio);
615613
if (boundary_block) {
616614
write_boundary_block(boundary_bdev,
617615
boundary_block, 1 << blkbits);
@@ -623,7 +621,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
623621

624622
confused:
625623
if (bio)
626-
bio = mpage_bio_submit(REQ_OP_WRITE, op_flags, bio);
624+
bio = mpage_bio_submit(bio);
627625

628626
if (mpd->use_writepage) {
629627
ret = mapping->a_ops->writepage(page, wbc);
@@ -679,11 +677,8 @@ mpage_writepages(struct address_space *mapping,
679677
};
680678

681679
ret = write_cache_pages(mapping, wbc, __mpage_writepage, &mpd);
682-
if (mpd.bio) {
683-
int op_flags = (wbc->sync_mode == WB_SYNC_ALL ?
684-
REQ_SYNC : 0);
685-
mpage_bio_submit(REQ_OP_WRITE, op_flags, mpd.bio);
686-
}
680+
if (mpd.bio)
681+
mpage_bio_submit(mpd.bio);
687682
}
688683
blk_finish_plug(&plug);
689684
return ret;
@@ -700,11 +695,8 @@ int mpage_writepage(struct page *page, get_block_t get_block,
700695
.use_writepage = 0,
701696
};
702697
int ret = __mpage_writepage(page, wbc, &mpd);
703-
if (mpd.bio) {
704-
int op_flags = (wbc->sync_mode == WB_SYNC_ALL ?
705-
REQ_SYNC : 0);
706-
mpage_bio_submit(REQ_OP_WRITE, op_flags, mpd.bio);
707-
}
698+
if (mpd.bio)
699+
mpage_bio_submit(mpd.bio);
708700
return ret;
709701
}
710702
EXPORT_SYMBOL(mpage_writepage);

0 commit comments

Comments
 (0)