Skip to content

Commit 9744b92

Browse files
committed
Merge tag 'iomap-5.7-merge-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull iomap fix from Darrick Wong: "Fix a problem in readahead where we can crash if we can't allocate a full bio due to GFP_NORETRY" * tag 'iomap-5.7-merge-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: iomap: Handle memory allocation failure in readahead
2 parents d8fc9cd + 457df33 commit 9744b92

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/iomap/buffered-io.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
302302

303303
if (!ctx->bio || !is_contig || bio_full(ctx->bio, plen)) {
304304
gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL);
305+
gfp_t orig_gfp = gfp;
305306
int nr_vecs = (length + PAGE_SIZE - 1) >> PAGE_SHIFT;
306307

307308
if (ctx->bio)
@@ -310,6 +311,13 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
310311
if (ctx->is_readahead) /* same as readahead_gfp_mask */
311312
gfp |= __GFP_NORETRY | __GFP_NOWARN;
312313
ctx->bio = bio_alloc(gfp, min(BIO_MAX_PAGES, nr_vecs));
314+
/*
315+
* If the bio_alloc fails, try it again for a single page to
316+
* avoid having to deal with partial page reads. This emulates
317+
* what do_mpage_readpage does.
318+
*/
319+
if (!ctx->bio)
320+
ctx->bio = bio_alloc(orig_gfp, 1);
313321
ctx->bio->bi_opf = REQ_OP_READ;
314322
if (ctx->is_readahead)
315323
ctx->bio->bi_opf |= REQ_RAHEAD;

0 commit comments

Comments
 (0)