Skip to content

Commit 53c1c82

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: refactor GC zone selection helpers
Merge xfs_zone_gc_ensure_target into xfs_zone_gc_select_target to keep all zone selection code together. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent ca0170a commit 53c1c82

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

fs/xfs/xfs_zone_gc.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -552,19 +552,35 @@ xfs_zone_gc_steal_open(
552552
return 0;
553553
}
554554

555+
/*
556+
* Ensure we have a valid open zone to write to.
557+
*/
555558
static struct xfs_open_zone *
556559
xfs_zone_gc_select_target(
557560
struct xfs_mount *mp)
558561
{
559562
struct xfs_zone_info *zi = mp->m_zone_info;
560563
struct xfs_open_zone *oz = zi->zi_open_gc_zone;
561564

565+
if (oz) {
566+
/*
567+
* If we have space available, just keep using the existing
568+
* zone.
569+
*/
570+
if (oz->oz_allocated < rtg_blocks(oz->oz_rtg))
571+
return oz;
572+
573+
/*
574+
* Wait for all writes to the current zone to finish before
575+
* picking a new one.
576+
*/
577+
if (oz->oz_written < rtg_blocks(oz->oz_rtg))
578+
return NULL;
579+
}
580+
562581
/*
563-
* We need to wait for pending writes to finish.
582+
* Open a new zone when there is none currently in use.
564583
*/
565-
if (oz && oz->oz_written < rtg_blocks(oz->oz_rtg))
566-
return NULL;
567-
568584
ASSERT(zi->zi_nr_open_zones <=
569585
mp->m_max_open_zones - XFS_OPEN_GC_ZONES);
570586
oz = xfs_open_zone(mp, WRITE_LIFE_NOT_SET, true);
@@ -576,23 +592,6 @@ xfs_zone_gc_select_target(
576592
return oz;
577593
}
578594

579-
/*
580-
* Ensure we have a valid open zone to write the GC data to.
581-
*
582-
* If the current target zone has space keep writing to it, else first wait for
583-
* all pending writes and then pick a new one.
584-
*/
585-
static struct xfs_open_zone *
586-
xfs_zone_gc_ensure_target(
587-
struct xfs_mount *mp)
588-
{
589-
struct xfs_open_zone *oz = mp->m_zone_info->zi_open_gc_zone;
590-
591-
if (!oz || oz->oz_allocated == rtg_blocks(oz->oz_rtg))
592-
return xfs_zone_gc_select_target(mp);
593-
return oz;
594-
}
595-
596595
static void
597596
xfs_zone_gc_end_io(
598597
struct bio *bio)
@@ -615,7 +614,7 @@ xfs_zone_gc_alloc_blocks(
615614
struct xfs_mount *mp = data->mp;
616615
struct xfs_open_zone *oz;
617616

618-
oz = xfs_zone_gc_ensure_target(mp);
617+
oz = xfs_zone_gc_select_target(mp);
619618
if (!oz)
620619
return NULL;
621620

@@ -1019,7 +1018,7 @@ xfs_zone_gc_should_start_new_work(
10191018
if (!data->scratch_available)
10201019
return false;
10211020

1022-
oz = xfs_zone_gc_ensure_target(data->mp);
1021+
oz = xfs_zone_gc_select_target(data->mp);
10231022
if (!oz || oz->oz_allocated == rtg_blocks(oz->oz_rtg))
10241023
return false;
10251024

0 commit comments

Comments
 (0)