Skip to content

Commit 618f40e

Browse files
Gao Xianggregkh
authored andcommitted
erofs: use read_cache_page_gfp for erofs_get_meta_page
As Christoph said [1], "I'd much prefer to just use read_cache_page_gfp, and live with the fact that this allocates bufferheads behind you for now. I'll try to speed up my attempts to get rid of the buffer heads on the block device mapping instead. " This simplifies the code a lot and a minor thing is "no REQ_META (e.g. for blktrace) on metadata at all..." [1] https://lore.kernel.org/r/20190903153704.GA2201@infradead.org/ Reported-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com> Link: https://lore.kernel.org/r/20190904020912.63925-26-gaoxiang25@huawei.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4231138 commit 618f40e

1 file changed

Lines changed: 9 additions & 61 deletions

File tree

‎fs/erofs/data.c‎

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -32,71 +32,13 @@ static void erofs_readendio(struct bio *bio)
3232
bio_put(bio);
3333
}
3434

35-
static struct bio *erofs_grab_raw_bio(struct super_block *sb,
36-
erofs_blk_t blkaddr,
37-
unsigned int nr_pages,
38-
bool ismeta)
39-
{
40-
struct bio *bio = bio_alloc(GFP_NOIO, nr_pages);
41-
42-
bio->bi_end_io = erofs_readendio;
43-
bio_set_dev(bio, sb->s_bdev);
44-
bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK;
45-
if (ismeta)
46-
bio->bi_opf = REQ_OP_READ | REQ_META;
47-
else
48-
bio->bi_opf = REQ_OP_READ;
49-
50-
return bio;
51-
}
52-
5335
struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
5436
{
5537
struct inode *const bd_inode = sb->s_bdev->bd_inode;
5638
struct address_space *const mapping = bd_inode->i_mapping;
57-
const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS);
58-
struct page *page;
59-
int err;
60-
61-
repeat:
62-
page = find_or_create_page(mapping, blkaddr, gfp);
63-
if (!page)
64-
return ERR_PTR(-ENOMEM);
65-
66-
DBG_BUGON(!PageLocked(page));
67-
68-
if (!PageUptodate(page)) {
69-
struct bio *bio;
70-
71-
bio = erofs_grab_raw_bio(sb, blkaddr, 1, true);
72-
73-
if (bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE) {
74-
err = -EFAULT;
75-
goto err_out;
76-
}
77-
78-
submit_bio(bio);
79-
lock_page(page);
8039

81-
/* this page has been truncated by others */
82-
if (page->mapping != mapping) {
83-
unlock_page(page);
84-
put_page(page);
85-
goto repeat;
86-
}
87-
88-
/* more likely a read error */
89-
if (!PageUptodate(page)) {
90-
err = -EIO;
91-
goto err_out;
92-
}
93-
}
94-
return page;
95-
96-
err_out:
97-
unlock_page(page);
98-
put_page(page);
99-
return ERR_PTR(err);
40+
return read_cache_page_gfp(mapping, blkaddr,
41+
mapping_gfp_constraint(mapping, ~__GFP_FS));
10042
}
10143

10244
static int erofs_map_blocks_flatmode(struct inode *inode,
@@ -272,7 +214,13 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
272214
if (nblocks > BIO_MAX_PAGES)
273215
nblocks = BIO_MAX_PAGES;
274216

275-
bio = erofs_grab_raw_bio(sb, blknr, nblocks, false);
217+
bio = bio_alloc(GFP_NOIO, nblocks);
218+
219+
bio->bi_end_io = erofs_readendio;
220+
bio_set_dev(bio, sb->s_bdev);
221+
bio->bi_iter.bi_sector = (sector_t)blknr <<
222+
LOG_SECTORS_PER_BLOCK;
223+
bio->bi_opf = REQ_OP_READ;
276224
}
277225

278226
err = bio_add_page(bio, page, PAGE_SIZE, 0);

0 commit comments

Comments
 (0)