Commit 8be31270 authored by Gao Xiang's avatar Gao Xiang Committed by Greg Kroah-Hartman

staging: erofs: introduce erofs_grab_bio

this patch renames prepare_bio to erofs_grab_bio, and
adds a nofail option in order to retry in the bio allocator
under memory pressure.
Signed-off-by: default avatarGao Xiang <gaoxiang25@huawei.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cca5dd87
...@@ -60,7 +60,8 @@ struct page *erofs_get_meta_page(struct super_block *sb, ...@@ -60,7 +60,8 @@ struct page *erofs_get_meta_page(struct super_block *sb,
struct bio *bio; struct bio *bio;
int err; int err;
bio = prepare_bio(sb, blkaddr, 1, read_endio); bio = erofs_grab_bio(sb, blkaddr, 1, read_endio, true);
err = bio_add_page(bio, page, PAGE_SIZE, 0); err = bio_add_page(bio, page, PAGE_SIZE, 0);
BUG_ON(err != PAGE_SIZE); BUG_ON(err != PAGE_SIZE);
...@@ -278,7 +279,14 @@ static inline struct bio *erofs_read_raw_page( ...@@ -278,7 +279,14 @@ static inline struct bio *erofs_read_raw_page(
if (nblocks > BIO_MAX_PAGES) if (nblocks > BIO_MAX_PAGES)
nblocks = BIO_MAX_PAGES; nblocks = BIO_MAX_PAGES;
bio = prepare_bio(inode->i_sb, blknr, nblocks, read_endio); bio = erofs_grab_bio(inode->i_sb,
blknr, nblocks, read_endio, false);
if (IS_ERR(bio)) {
err = PTR_ERR(bio);
bio = NULL;
goto err_out;
}
} }
err = bio_add_page(bio, page, PAGE_SIZE, 0); err = bio_add_page(bio, page, PAGE_SIZE, 0);
......
...@@ -420,26 +420,26 @@ struct erofs_map_blocks { ...@@ -420,26 +420,26 @@ struct erofs_map_blocks {
#define EROFS_GET_BLOCKS_RAW 0x0001 #define EROFS_GET_BLOCKS_RAW 0x0001
/* data.c */ /* data.c */
static inline struct bio *prepare_bio( static inline struct bio *
struct super_block *sb, erofs_grab_bio(struct super_block *sb,
erofs_blk_t blkaddr, unsigned nr_pages, erofs_blk_t blkaddr, unsigned int nr_pages,
bio_end_io_t endio) bio_end_io_t endio, bool nofail)
{ {
gfp_t gfp = GFP_NOIO; const gfp_t gfp = GFP_NOIO;
struct bio *bio = bio_alloc(gfp, nr_pages); struct bio *bio;
if (unlikely(bio == NULL) && do {
(current->flags & PF_MEMALLOC)) { if (nr_pages == 1) {
do { bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1);
nr_pages /= 2; if (unlikely(bio == NULL)) {
if (unlikely(!nr_pages)) { DBG_BUGON(nofail);
bio = bio_alloc(gfp | __GFP_NOFAIL, 1); return ERR_PTR(-ENOMEM);
BUG_ON(bio == NULL);
break;
} }
bio = bio_alloc(gfp, nr_pages); break;
} while (bio == NULL); }
} bio = bio_alloc(gfp, nr_pages);
nr_pages /= 2;
} while (unlikely(bio == NULL));
bio->bi_end_io = endio; bio->bi_end_io = endio;
bio_set_dev(bio, sb->s_bdev); bio_set_dev(bio, sb->s_bdev);
......
...@@ -1213,8 +1213,8 @@ static bool z_erofs_vle_submit_all(struct super_block *sb, ...@@ -1213,8 +1213,8 @@ static bool z_erofs_vle_submit_all(struct super_block *sb,
} }
if (bio == NULL) { if (bio == NULL) {
bio = prepare_bio(sb, first_index + i, bio = erofs_grab_bio(sb, first_index + i,
BIO_MAX_PAGES, z_erofs_vle_read_endio); BIO_MAX_PAGES, z_erofs_vle_read_endio, true);
bio->bi_private = tagptr_cast_ptr(bi_private); bio->bi_private = tagptr_cast_ptr(bi_private);
++nr_bios; ++nr_bios;
......
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