Skip to contentSkip to conversation

zoned GC fix

PATCH In review Christoph Hellwig 3 participants 7 messages Jul 28 – Jul 29 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi Carlos,

this series fixes a potential deadlock in the zoned GC code, and also adds a comment in the same area while looking at it.

Diffstat:

 xfs_zone_gc.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
#1 lore raw

PATCH 1/2 xfs: add a separate bio_set for spliting GC writes

Allocating the new bio for a split from the same pool as the original one can deadlock under memory pressure. Add a separate pool for splitting GC write bios to avoid this.

Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")
---
 fs/xfs/xfs_zone_gc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
fs/xfs/xfs_zone_gc.c +11 -1
index f76a09130852..e4f70e024632 100644
@@ -130,6 +130,9 @@ struct xfs_zone_gc_data {
 	/* bioset used to allocate the gc_bios */
 	struct bio_set			bio_set;
 
+	/* bioset used when writes need to be split to hardware limits */
+	struct bio_set			split_bio_set;
+
 	/*
 	 * Scratchpad to buffer GC data, organized as a ring buffer over
 	 * discontiguous folios.  scratch_head is where the buffer is filled,
@@ -221,6 +224,9 @@ xfs_zone_gc_data_alloc(
 	if (bioset_init(&data->bio_set, 16, offsetof(struct xfs_gc_bio, bio),
 			BIOSET_NEED_BVECS))
 		goto out_free_recs;
+	if (bioset_init(&data->split_bio_set, 16,
+			offsetof(struct xfs_gc_bio, bio), 0))
+		goto out_exit_bio_set;
 	for (i = 0; i < XFS_GC_NR_BUFS; i++) {
 		data->scratch_folios[i] =
 			folio_alloc(GFP_KERNEL, get_order(XFS_GC_BUF_SIZE));
@@ -238,6 +244,8 @@ xfs_zone_gc_data_alloc(
 out_free_scratch:
 	while (--i >= 0)
 		folio_put(data->scratch_folios[i]);
+	bioset_exit(&data->split_bio_set);
+out_exit_bio_set:
 	bioset_exit(&data->bio_set);
 out_free_recs:
 	kfree(data->iter.recs);
@@ -254,6 +262,7 @@ xfs_zone_gc_data_free(
 
 	for (i = 0; i < XFS_GC_NR_BUFS; i++)
 		folio_put(data->scratch_folios[i]);
+	bioset_exit(&data->split_bio_set);
 	bioset_exit(&data->bio_set);
 	kfree(data->iter.recs);
 	kfree(data);
@@ -810,7 +819,8 @@ xfs_zone_gc_split_write(
 			data->mp->m_sb.sb_blocksize) >> SECTOR_SHIFT;
 	split_len = split_sectors << SECTOR_SHIFT;
 
-	split = bio_split(&chunk->bio, split_sectors, GFP_NOFS, &data->bio_set);
+	split = bio_split(&chunk->bio, split_sectors, GFP_NOFS,
+			&data->split_bio_set);
 	split_chunk = container_of(split, struct xfs_gc_bio, bio);
 	split_chunk->data = data;
 	ihold(VFS_I(chunk->ip));
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: add a separate bio_set for spliting GC writes

Quoted 6 lines · Christoph Hellwig

Allocating the new bio for a split from the same pool as the original one can deadlock under memory pressure. Add a separate pool for splitting GC write bios to avoid this.

Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")

Seems fine to me...

--D

Quoted 59 lines
---
 fs/xfs/xfs_zone_gc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
fs/xfs/xfs_zone_gc.c +11 -1
index f76a09130852..e4f70e024632 100644
@@ -130,6 +130,9 @@ struct xfs_zone_gc_data {
 	/* bioset used to allocate the gc_bios */
 	struct bio_set			bio_set;
 
+	/* bioset used when writes need to be split to hardware limits */
+	struct bio_set			split_bio_set;
+
 	/*
 	 * Scratchpad to buffer GC data, organized as a ring buffer over
 	 * discontiguous folios.  scratch_head is where the buffer is filled,
@@ -221,6 +224,9 @@ xfs_zone_gc_data_alloc(
 	if (bioset_init(&data->bio_set, 16, offsetof(struct xfs_gc_bio, bio),
 			BIOSET_NEED_BVECS))
 		goto out_free_recs;
+	if (bioset_init(&data->split_bio_set, 16,
+			offsetof(struct xfs_gc_bio, bio), 0))
+		goto out_exit_bio_set;
 	for (i = 0; i < XFS_GC_NR_BUFS; i++) {
 		data->scratch_folios[i] =
 			folio_alloc(GFP_KERNEL, get_order(XFS_GC_BUF_SIZE));
@@ -238,6 +244,8 @@ xfs_zone_gc_data_alloc(
 out_free_scratch:
 	while (--i >= 0)
 		folio_put(data->scratch_folios[i]);
+	bioset_exit(&data->split_bio_set);
+out_exit_bio_set:
 	bioset_exit(&data->bio_set);
 out_free_recs:
 	kfree(data->iter.recs);
@@ -254,6 +262,7 @@ xfs_zone_gc_data_free(
 
 	for (i = 0; i < XFS_GC_NR_BUFS; i++)
 		folio_put(data->scratch_folios[i]);
+	bioset_exit(&data->split_bio_set);
 	bioset_exit(&data->bio_set);
 	kfree(data->iter.recs);
 	kfree(data);
@@ -810,7 +819,8 @@ xfs_zone_gc_split_write(
 			data->mp->m_sb.sb_blocksize) >> SECTOR_SHIFT;
 	split_len = split_sectors << SECTOR_SHIFT;
 
-	split = bio_split(&chunk->bio, split_sectors, GFP_NOFS, &data->bio_set);
+	split = bio_split(&chunk->bio, split_sectors, GFP_NOFS,
+			&data->split_bio_set);
 	split_chunk = container_of(split, struct xfs_gc_bio, bio);
 	split_chunk->data = data;
 	ihold(VFS_I(chunk->ip));
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] xfs: add a separate bio_set for spliting GC writes

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Allocating the new bio for a split from the same pool as the original one can deadlock under memory pressure. Add a separate pool for splitting GC write bios to avoid this.

Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")

Looks good to me, but the commit message would be better with an explanation of how the deadlock can happen, as I do not think it is that obvious.

Regardless,

Signature · 2 lines
Damien Le Moal
Western Digital Research
#4 lore raw

PATCH 2/2 xfs: add a comment to describe xfs_gc_bio.victim_rtg

In reply to Christoph Hellwig

All other fields have comments describing them, add one for this field as well.

---
 fs/xfs/xfs_zone_gc.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_zone_gc.c +1 -0
index e4f70e024632..e2bad83b10f6 100644
@@ -103,6 +103,7 @@ struct xfs_gc_bio {
 	/* Open Zone being written to */
 	struct xfs_open_zone		*oz;
 
+	/* Realtime group currently evacuated */
 	struct xfs_rtgroup		*victim_rtg;
 
 	/* Bio used for reads and writes, including the bvec used by it */
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] xfs: add a comment to describe xfs_gc_bio.victim_rtg

Quoted 4 lines · Christoph Hellwig

All other fields have comments describing them, add one for this field as well.

Excellent!

--D

Quoted 20 lines
---
 fs/xfs/xfs_zone_gc.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_zone_gc.c +1 -0
index e4f70e024632..e2bad83b10f6 100644
@@ -103,6 +103,7 @@ struct xfs_gc_bio {
 	/* Open Zone being written to */
 	struct xfs_open_zone		*oz;
 
+	/* Realtime group currently evacuated */
 	struct xfs_rtgroup		*victim_rtg;
 
 	/* Bio used for reads and writes, including the bvec used by it */
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] xfs: add a comment to describe xfs_gc_bio.victim_rtg

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

All other fields have comments describing them, add one for this field as well.

Looks good to me (see nit below).

fs/xfs/xfs_zone_gc.c struct xfs_gc_bio { · line 106

Quoted 13 lines
---
 fs/xfs/xfs_zone_gc.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_zone_gc.c +1 -0
index e4f70e024632..e2bad83b10f6 100644
@@ -103,6 +103,7 @@ struct xfs_gc_bio {
 	/* Open Zone being written to */
 	struct xfs_open_zone		*oz;
 
+	/* Realtime group currently evacuated */

May be: /* Realtime group currently being reclaimed */ ?

Quoted 3 lines
fs/xfs/xfs_zone_gc.c +0 -0
 	struct xfs_rtgroup		*victim_rtg;
 
 	/* Bio used for reads and writes, including the bvec used by it */
Signature · 2 lines
Damien Le Moal
Western Digital Research