Skip to content

Commit e4a7a3f

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: refactor xfs_calc_atomic_write_unit_max
This function and the helpers used by it duplicate the same logic for AGs and RTGs. Use the xfs_group_type enum to unify both variants. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent e74d1fa commit e4a7a3f

File tree

2 files changed

+42
-65
lines changed

2 files changed

+42
-65
lines changed

fs/xfs/xfs_mount.c

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -679,68 +679,46 @@ static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
679679
}
680680

681681
/*
682-
* If the data device advertises atomic write support, limit the size of data
683-
* device atomic writes to the greatest power-of-two factor of the AG size so
684-
* that every atomic write unit aligns with the start of every AG. This is
685-
* required so that the per-AG allocations for an atomic write will always be
682+
* If the underlying device advertises atomic write support, limit the size of
683+
* atomic writes to the greatest power-of-two factor of the group size so
684+
* that every atomic write unit aligns with the start of every group. This is
685+
* required so that the allocations for an atomic write will always be
686686
* aligned compatibly with the alignment requirements of the storage.
687687
*
688-
* If the data device doesn't advertise atomic writes, then there are no
689-
* alignment restrictions and the largest out-of-place write we can do
690-
* ourselves is the number of blocks that user files can allocate from any AG.
688+
* If the device doesn't advertise atomic writes, then there are no alignment
689+
* restrictions and the largest out-of-place write we can do ourselves is the
690+
* number of blocks that user files can allocate from any group.
691691
*/
692-
static inline xfs_extlen_t xfs_calc_perag_awu_max(struct xfs_mount *mp)
693-
{
694-
if (mp->m_ddev_targp->bt_bdev_awu_min > 0)
695-
return max_pow_of_two_factor(mp->m_sb.sb_agblocks);
696-
return rounddown_pow_of_two(mp->m_ag_max_usable);
697-
}
698-
699-
/*
700-
* Reflink on the realtime device requires rtgroups, and atomic writes require
701-
* reflink.
702-
*
703-
* If the realtime device advertises atomic write support, limit the size of
704-
* data device atomic writes to the greatest power-of-two factor of the rtgroup
705-
* size so that every atomic write unit aligns with the start of every rtgroup.
706-
* This is required so that the per-rtgroup allocations for an atomic write
707-
* will always be aligned compatibly with the alignment requirements of the
708-
* storage.
709-
*
710-
* If the rt device doesn't advertise atomic writes, then there are no
711-
* alignment restrictions and the largest out-of-place write we can do
712-
* ourselves is the number of blocks that user files can allocate from any
713-
* rtgroup.
714-
*/
715-
static inline xfs_extlen_t xfs_calc_rtgroup_awu_max(struct xfs_mount *mp)
692+
static xfs_extlen_t
693+
xfs_calc_group_awu_max(
694+
struct xfs_mount *mp,
695+
enum xfs_group_type type)
716696
{
717-
struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG];
697+
struct xfs_groups *g = &mp->m_groups[type];
698+
struct xfs_buftarg *btp = xfs_group_type_buftarg(mp, type);
718699

719-
if (rgs->blocks == 0)
700+
if (g->blocks == 0)
720701
return 0;
721-
if (mp->m_rtdev_targp && mp->m_rtdev_targp->bt_bdev_awu_min > 0)
722-
return max_pow_of_two_factor(rgs->blocks);
723-
return rounddown_pow_of_two(rgs->blocks);
702+
if (btp && btp->bt_bdev_awu_min > 0)
703+
return max_pow_of_two_factor(g->blocks);
704+
return rounddown_pow_of_two(g->blocks);
724705
}
725706

726707
/* Compute the maximum atomic write unit size for each section. */
727708
static inline void
728709
xfs_calc_atomic_write_unit_max(
729-
struct xfs_mount *mp)
710+
struct xfs_mount *mp,
711+
enum xfs_group_type type)
730712
{
731-
struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG];
732-
struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG];
713+
struct xfs_groups *g = &mp->m_groups[type];
733714

734715
const xfs_extlen_t max_write = xfs_calc_atomic_write_max(mp);
735716
const xfs_extlen_t max_ioend = xfs_reflink_max_atomic_cow(mp);
736-
const xfs_extlen_t max_agsize = xfs_calc_perag_awu_max(mp);
737-
const xfs_extlen_t max_rgsize = xfs_calc_rtgroup_awu_max(mp);
738-
739-
ags->awu_max = min3(max_write, max_ioend, max_agsize);
740-
rgs->awu_max = min3(max_write, max_ioend, max_rgsize);
717+
const xfs_extlen_t max_gsize = xfs_calc_group_awu_max(mp, type);
741718

742-
trace_xfs_calc_atomic_write_unit_max(mp, max_write, max_ioend,
743-
max_agsize, max_rgsize);
719+
g->awu_max = min3(max_write, max_ioend, max_gsize);
720+
trace_xfs_calc_atomic_write_unit_max(mp, type, max_write, max_ioend,
721+
max_gsize, g->awu_max);
744722
}
745723

746724
/*
@@ -758,7 +736,8 @@ xfs_set_max_atomic_write_opt(
758736
max(mp->m_groups[XG_TYPE_AG].blocks,
759737
mp->m_groups[XG_TYPE_RTG].blocks);
760738
const xfs_extlen_t max_group_write =
761-
max(xfs_calc_perag_awu_max(mp), xfs_calc_rtgroup_awu_max(mp));
739+
max(xfs_calc_group_awu_max(mp, XG_TYPE_AG),
740+
xfs_calc_group_awu_max(mp, XG_TYPE_RTG));
762741
int error;
763742

764743
if (new_max_bytes == 0)
@@ -814,7 +793,8 @@ xfs_set_max_atomic_write_opt(
814793
return error;
815794
}
816795

817-
xfs_calc_atomic_write_unit_max(mp);
796+
xfs_calc_atomic_write_unit_max(mp, XG_TYPE_AG);
797+
xfs_calc_atomic_write_unit_max(mp, XG_TYPE_RTG);
818798
mp->m_awu_max_bytes = new_max_bytes;
819799
return 0;
820800
}

fs/xfs/xfs_trace.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,33 @@ DEFINE_ATTR_LIST_EVENT(xfs_attr_leaf_list);
171171
DEFINE_ATTR_LIST_EVENT(xfs_attr_node_list);
172172

173173
TRACE_EVENT(xfs_calc_atomic_write_unit_max,
174-
TP_PROTO(struct xfs_mount *mp, unsigned int max_write,
175-
unsigned int max_ioend, unsigned int max_agsize,
176-
unsigned int max_rgsize),
177-
TP_ARGS(mp, max_write, max_ioend, max_agsize, max_rgsize),
174+
TP_PROTO(struct xfs_mount *mp, enum xfs_group_type type,
175+
unsigned int max_write, unsigned int max_ioend,
176+
unsigned int max_gsize, unsigned int awu_max),
177+
TP_ARGS(mp, type, max_write, max_ioend, max_gsize, awu_max),
178178
TP_STRUCT__entry(
179179
__field(dev_t, dev)
180+
__field(enum xfs_group_type, type)
180181
__field(unsigned int, max_write)
181182
__field(unsigned int, max_ioend)
182-
__field(unsigned int, max_agsize)
183-
__field(unsigned int, max_rgsize)
184-
__field(unsigned int, data_awu_max)
185-
__field(unsigned int, rt_awu_max)
183+
__field(unsigned int, max_gsize)
184+
__field(unsigned int, awu_max)
186185
),
187186
TP_fast_assign(
188187
__entry->dev = mp->m_super->s_dev;
188+
__entry->type = type;
189189
__entry->max_write = max_write;
190190
__entry->max_ioend = max_ioend;
191-
__entry->max_agsize = max_agsize;
192-
__entry->max_rgsize = max_rgsize;
193-
__entry->data_awu_max = mp->m_groups[XG_TYPE_AG].awu_max;
194-
__entry->rt_awu_max = mp->m_groups[XG_TYPE_RTG].awu_max;
191+
__entry->max_gsize = max_gsize;
192+
__entry->awu_max = awu_max;
195193
),
196-
TP_printk("dev %d:%d max_write %u max_ioend %u max_agsize %u max_rgsize %u data_awu_max %u rt_awu_max %u",
194+
TP_printk("dev %d:%d %s max_write %u max_ioend %u max_gsize %u awu_max %u",
197195
MAJOR(__entry->dev), MINOR(__entry->dev),
196+
__print_symbolic(__entry->type, XG_TYPE_STRINGS),
198197
__entry->max_write,
199198
__entry->max_ioend,
200-
__entry->max_agsize,
201-
__entry->max_rgsize,
202-
__entry->data_awu_max,
203-
__entry->rt_awu_max)
199+
__entry->max_gsize,
200+
__entry->awu_max)
204201
);
205202

206203
TRACE_EVENT(xfs_calc_max_atomic_write_fsblocks,

0 commit comments

Comments
 (0)