Skip to contentSkip to conversation

iomap: add a separate bio_set for iomap_split_ioend

PATCH Applied Christoph Hellwig 3 participants 8 messages Jun 29 – Jul 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: add a separate bio_set for iomap_split_ioend

iomap_split_ioend can split bios that already come from iomap_ioend_bioset and thus deadlock when the bioset is exhausted.

Add a separate bio_set to avoid this deadlock.

Fixes 5fcbd555d483 ("iomap: split bios to zone append limits in the submission handlers")
---
 fs/iomap/ioend.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
fs/iomap/ioend.c +19 -2
index 01287f1ae021..2fbcb06f6938 100644
@@ -13,6 +13,7 @@
 
 struct bio_set iomap_ioend_bioset;
 EXPORT_SYMBOL_GPL(iomap_ioend_bioset);
+struct bio_set iomap_ioend_split_bioset;
 
 struct iomap_ioend *iomap_init_ioend(struct inode *inode,
 		struct bio *bio, loff_t file_offset, u16 ioend_flags)
@@ -483,7 +484,8 @@ struct iomap_ioend *iomap_split_ioend(struct iomap_ioend *ioend,
 	sector_offset = ALIGN_DOWN(sector_offset << SECTOR_SHIFT,
 			i_blocksize(ioend->io_inode)) >> SECTOR_SHIFT;
 
-	split = bio_split(bio, sector_offset, GFP_NOFS, &iomap_ioend_bioset);
+	split = bio_split(bio, sector_offset, GFP_NOFS,
+			&iomap_ioend_split_bioset);
 	if (IS_ERR(split))
 		return ERR_CAST(split);
 	split->bi_private = bio->bi_private;
@@ -506,8 +508,23 @@ EXPORT_SYMBOL_GPL(iomap_split_ioend);
 
 static int __init iomap_ioend_init(void)
 {
-	return bioset_init(&iomap_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE),
+	const unsigned int nr_mempool_entries = 4 * (PAGE_SIZE / SECTOR_SIZE);
+	int error;
+
+	error = bioset_init(&iomap_ioend_bioset, nr_mempool_entries,
 			   offsetof(struct iomap_ioend, io_bio),
 			   BIOSET_NEED_BVECS);
+	if (error)
+		return error;
+	error = bioset_init(&iomap_ioend_split_bioset, nr_mempool_entries,
+			   offsetof(struct iomap_ioend, io_bio),
+			   BIOSET_NEED_BVECS);
+	if (error)
+		goto out_exit_ioend_bioset;
+	return 0;
+
+out_exit_ioend_bioset:
+	bioset_exit(&iomap_ioend_bioset);
+	return error;
 }
 fs_initcall(iomap_ioend_init);
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · Christoph Hellwig

iomap_split_ioend can split bios that already come from iomap_ioend_bioset and thus deadlock when the bioset is exhausted.

Add a separate bio_set to avoid this deadlock.

What happens if &iomap_ioend_split_bioset is exhausted? Won't that also stall the ioend submission?

<confused>

--D

Quoted 56 lines
Fixes 5fcbd555d483 ("iomap: split bios to zone append limits in the submission handlers")
---
 fs/iomap/ioend.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
fs/iomap/ioend.c +19 -2
index 01287f1ae021..2fbcb06f6938 100644
@@ -13,6 +13,7 @@
 
 struct bio_set iomap_ioend_bioset;
 EXPORT_SYMBOL_GPL(iomap_ioend_bioset);
+struct bio_set iomap_ioend_split_bioset;
 
 struct iomap_ioend *iomap_init_ioend(struct inode *inode,
 		struct bio *bio, loff_t file_offset, u16 ioend_flags)
@@ -483,7 +484,8 @@ struct iomap_ioend *iomap_split_ioend(struct iomap_ioend *ioend,
 	sector_offset = ALIGN_DOWN(sector_offset << SECTOR_SHIFT,
 			i_blocksize(ioend->io_inode)) >> SECTOR_SHIFT;
 
-	split = bio_split(bio, sector_offset, GFP_NOFS, &iomap_ioend_bioset);
+	split = bio_split(bio, sector_offset, GFP_NOFS,
+			&iomap_ioend_split_bioset);
 	if (IS_ERR(split))
 		return ERR_CAST(split);
 	split->bi_private = bio->bi_private;
@@ -506,8 +508,23 @@ EXPORT_SYMBOL_GPL(iomap_split_ioend);
 
 static int __init iomap_ioend_init(void)
 {
-	return bioset_init(&iomap_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE),
+	const unsigned int nr_mempool_entries = 4 * (PAGE_SIZE / SECTOR_SIZE);
+	int error;
+
+	error = bioset_init(&iomap_ioend_bioset, nr_mempool_entries,
 			   offsetof(struct iomap_ioend, io_bio),
 			   BIOSET_NEED_BVECS);
+	if (error)
+		return error;
+	error = bioset_init(&iomap_ioend_split_bioset, nr_mempool_entries,
+			   offsetof(struct iomap_ioend, io_bio),
+			   BIOSET_NEED_BVECS);
+	if (error)
+		goto out_exit_ioend_bioset;
+	return 0;
+
+out_exit_ioend_bioset:
+	bioset_exit(&iomap_ioend_bioset);
+	return error;
 }
 fs_initcall(iomap_ioend_init);
Signature · 1 line
2.53.0
#2 lore raw
Quoted 7 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig

iomap_split_ioend can split bios that already come from iomap_ioend_bioset and thus deadlock when the bioset is exhausted.

Add a separate bio_set to avoid this deadlock.

What happens if &iomap_ioend_split_bioset is exhausted?

mempool_alloc will block waiting for an ioend to finish.

Quoted 1 line

Won't that also stall the ioend submission?

Yes, but at least it won't deadlock, unlike the case where we're waiting for the parent one to finish. (multiply a few times as there is more than one entry in the mempool, which is what's saving our ass in practice)

maintainer Applied
#3 lore raw
In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

iomap: add a separate bio_set for iomap_split_ioend

Applied to the vfs-7.3.iomap branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.3.iomap

[1/1] iomap: add a separate bio_set for iomap_split_ioend

      https://git.kernel.org/vfs/vfs/c/f2727952b21d
#4 lore raw
Quoted 5 lines · Christian Brauner
Quoted 1 line · Christoph Hellwig

iomap: add a separate bio_set for iomap_split_ioend

Applied to the vfs-7.3.iomap branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap branch should appear in linux-next soon.

Any chance you could propagates this to vfs.fixes?

#5 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Christian Brauner
Quoted 1 line · Christoph Hellwig

iomap: add a separate bio_set for iomap_split_ioend

Applied to the vfs-7.3.iomap branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap branch should appear in linux-next soon.

Any chance you could propagates this to vfs.fixes?

Ping again.

#6 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Christian Brauner
Quoted 1 line · Christoph Hellwig

iomap: add a separate bio_set for iomap_split_ioend

Applied to the vfs-7.3.iomap branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap branch should appear in linux-next soon.

Any chance you could propagates this to vfs.fixes?

Ping again.

Sorry, didn't see that mail in the tui. Yes, doing that now.

#7 lore raw
Quoted 6 lines · Christian Brauner
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Christian Brauner
Quoted 1 line · Christoph Hellwig

iomap: add a separate bio_set for iomap_split_ioend

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Applied to the vfs-7.3.iomap branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap branch should appear in linux-next soon.

Any chance you could propagates this to vfs.fixes?

Ping again.

Sorry, didn't see that mail in the tui. Yes, doing that now.

Done and pushed.