Zoned XFS code improvements
v2 cover Zoned XFS code improvements
All,
Here are 4 simple patches to cleanup the code for zoned XFS. Overall, there is no functional changes introduced beside the change of information displayed in /proc/self/mountstats (patch 3).
Changes from v1:
- Split former patch 1 into patch 1 and 2.
- Changed patch 3 to add new lines of information instead of changing the existing lines.
- Reworked commit titles and messages.
Damien Le Moal (4):
xfs: avoid unnecessary open zone check in xfs_select_zone_nowait()
xfs: fix a comment typo in xfs_select_zone_nowait()
xfs: display more zone related information in mountstats
xfs: avoid unnecessary calculations in xfs_zoned_need_gc()
fs/xfs/xfs_zone_alloc.c | 9 +++++---- fs/xfs/xfs_zone_gc.c | 24 ++++++++++++++++++------ fs/xfs/xfs_zone_info.c | 7 ++++++- 3 files changed, 29 insertions(+), 11 deletions(-)
base-commit: f8544b654f22b1138ba12bc0971a96963b20311d
Signature · 1 line
2.53.0
PATCH v2 1/4 xfs: avoid unnecessary open zone check in xfs_select_zone_nowait()
When xfs_select_zone_nowait() is called with pack_tight equal to true, the function xfs_select_open_zone_mru() is called if no open zone is returned by xfs_select_open_zone_lru(), that is, when oz is NULL. The open zone pointer return of xfs_select_zone_nowait() is then checked, but this check is outside of the "if (pack_tight)" that trigered the call to xfs_select_open_zone_mru(). In other word, this check is unnecessarily done even when pack_tight is false.
Move the check for the return value of the call to xfs_select_open_zone_mru() inside the if that controls the call to this function, so that we do not uselessly test again the value of oz when pack_tight is false.
No functional changes.
--- fs/xfs/xfs_zone_alloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +4 -3
@@ -675,10 +675,11 @@ xfs_select_zone_nowait(if (oz) goto out_unlock; -if (pack_tight) +if (pack_tight) { oz =xfs_select_open_zone_mru (zi, write_hint); -if (oz) - goto out_unlock; +if (oz) + goto out_unlock; + }/* * See if we can open a new zone and use that so that data for different
Signature · 1 line
2.53.0
PATCH v2 2/4 xfs: fix a comment typo in xfs_select_zone_nowait()
In reply to Damien Le MoalFix a typo in the comment describing the second call to xfs_select_open_zone_lru() in xfs_select_zone_nowait().
--- fs/xfs/xfs_zone_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +1 -1
@@ -690,7 +690,7 @@ xfs_select_zone_nowait( goto out_unlock;/* -* Try to find an zone that is an ok match to colocate data with. +* Try to find a zone that is an ok match to colocate data with. */ oz =xfs_select_open_zone_lru (zi, write_hint,XFS_ZONE_ALLOC_OK );if (oz)
Signature · 1 line
2.53.0
PATCH v2 3/4 xfs: display more zone related information in mountstats
In reply to Damien Le MoalModify xfs_zoned_show_stats() to add to the information displayed with /proc/self/mountstats the total number of zones (RT groups) and the number of open zones together with the maximum number of open zones.
--- fs/xfs/xfs_zone_info.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/xfs_zone_info.c +6 -1
@@ -90,9 +90,14 @@ xfs_zoned_show_stats(seq_printf (m,"\tRT GC required: %d\n" ,xfs_zoned_need_gc (mp)); +seq_printf (m,"\ttotal number of zones: %u\n" , + mp->m_sb.sb_rgcount);seq_printf (m,"\tfree zones: %d\n" ,atomic_read (&zi->zi_nr_free_zones)); -seq_puts (m,"\topen zones:\n" ); +spin_lock (&zi->zi_open_zones_lock); +seq_printf (m,"\tnumber of open zones: %u / %u\n" , + zi->zi_nr_open_zones, mp->m_max_open_zones); +seq_puts (m,"\topen zones:\n" );list_for_each_entry (oz, &zi->zi_open_zones, oz_entry)xfs_show_open_zone (m, oz);if (zi->zi_open_gc_zone) {
Signature · 1 line
2.53.0
PATCH v2 4/4 xfs: avoid unnecessary calculations in xfs_zoned_need_gc()
In reply to Damien Le MoalIf zonegc_low_space is set to zero (which is the default), the second condition in xfs_zoned_need_gc() that triggers GC never evaluates to true because the calculated threshold will always be 0. So there is no need to calculate the threshold and to evaluate that condition. Return early when zonegc_low_space is zero.
While at it, add comments to document the intent of each of the 3 tests used to determine the return value to control the execution of garbage collection.
--- fs/xfs/xfs_zone_gc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
fs/xfs/xfs_zone_gc.c +18 -6
@@ -170,25 +170,37 @@ xfs_zoned_need_gc(s64 available, free, threshold;s32 remainder; +/* If we have no reclaimable blocks, running GC is useless. */ if (!xfs_zoned_have_reclaimable (mp->m_zone_info))return false; +/* +* In order to avoid file fragmentation as much as possible, we should +* make sure that we can open enough zones. So trigger GC if the number +* of blocks immediately available for writes is lower than the total +* number of blocks from all possible open zones. +*/ available =xfs_estimate_freecounter (mp,XC_FREE_RTAVAILABLE ); -if (available <xfs_rtgs_to_rfsbs (mp, mp->m_max_open_zones -XFS_OPEN_GC_ZONES ))return true; - free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); +/* +* For cases where the user wants to be more aggressive with GC, +* the sysfs attribute zonegc_low_space may be set to a non zero value, +* to indicate that GC should try to maintain at least zonegc_low_space +* percent of the free space to be directly available for writing. Check +* this here. +*/ +if (!mp->m_zonegc_low_space) +return false; + free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); threshold =div_s64_rem (free,100 , &remainder); threshold = threshold * mp->m_zonegc_low_space + remainder *div_s64 (mp->m_zonegc_low_space,100 ); -if (available < threshold) -return true; - -return false; +return available < threshold; } static struct xfs_zone_gc_data *
Signature · 1 line
2.53.0
Re: [PATCH v2 1/4] xfs: avoid unnecessary open zone check in xfs_select_zone_nowait()
In reply to Damien Le MoalLooks good:
Re: [PATCH v2 2/4] xfs: fix a comment typo in xfs_select_zone_nowait()
In reply to Damien Le MoalLooks good:
Re: [PATCH v2 3/4] xfs: display more zone related information in mountstats
In reply to Damien Le MoalRe: [PATCH v2 4/4] xfs: avoid unnecessary calculations in xfs_zoned_need_gc()
In reply to Damien Le MoalQuoted 9 lines · Damien Le Moal
If
zonegc_low_spaceis set to zero (which is the default), the second condition inxfs_zoned_need_gc()that triggers GC never evaluates to true because the calculated threshold will always be 0. So there is no need to calculate the threshold and to evaluate that condition. Return early whenzonegc_low_spaceis zero.While at it, add comments to document the intent of each of the 3 tests used to determine the return value to control the execution of garbage collection.
Looks good:
Re: [PATCH v2 1/4] xfs: avoid unnecessary open zone check in xfs_select_zone_nowait()
In reply to Damien Le MoalQuoted 29 lines · Damien Le Moal
When
xfs_select_zone_nowait()is called withpack_tightequal to true, the functionxfs_select_open_zone_mru()is called if no open zone is returned byxfs_select_open_zone_lru(), that is, when oz is NULL. The open zone pointer return ofxfs_select_zone_nowait()is then checked, but this check is outside of the "if (pack_tight)" that trigered the call toxfs_select_open_zone_mru(). In other word, this check is unnecessarily done even whenpack_tightis false.Move the check for the return value of the call to
xfs_select_open_zone_mru()inside the if that controls the call to this function, so that we do not uselessly test again the value of oz whenpack_tightis false.No functional changes.
Signed-off-by Damien Le Moal <[email protected]>--- fs/xfs/xfs_zone_alloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/xfs/xfs_zone_alloc.c +0
-1@@ -675,10 +675,11 @@ xfs_select_zone_nowait(if (oz) goto out_unlock; -if (pack_tight)
fs/xfs/xfs_zone_alloc.c xfs_select_zone_nowait( · line 685
Quoted 10 lines
fs/xfs/xfs_zone_alloc.c +4
-2+if (pack_tight) { oz =xfs_select_open_zone_mru (zi, write_hint); -if (oz) - goto out_unlock; +if (oz) + goto out_unlock; + }/* * See if we can open a new zone and use that so that data for different
Looks good,
Re: [PATCH v2 2/4] xfs: fix a comment typo in xfs_select_zone_nowait()
In reply to Damien Le MoalQuoted 13 lines · Damien Le Moal
Fix a typo in the comment describing the second call to
xfs_select_open_zone_lru()inxfs_select_zone_nowait().Signed-off-by Damien Le Moal <[email protected]>--- fs/xfs/xfs_zone_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_zone_alloc.c +0
-0
fs/xfs/xfs_zone_alloc.c xfs_select_zone_nowait( · line 696
Quoted 8 lines
fs/xfs/xfs_zone_alloc.c +1
-1@@ -690,7 +690,7 @@ xfs_select_zone_nowait( goto out_unlock;/* -* Try to find an zone that is an ok match to colocate data with. +* Try to find a zone that is an ok match to colocate data with. */ oz =xfs_select_open_zone_lru (zi, write_hint,XFS_ZONE_ALLOC_OK );if (oz)
Looks good,
Re: [PATCH v2 3/4] xfs: display more zone related information in mountstats
In reply to Damien Le MoalQuoted 19 lines · Damien Le Moal
Modify
xfs_zoned_show_stats()to add to the information displayed with/proc/self/mountstatsthe total number of zones (RT groups) and the number of open zones together with the maximum number of open zones.Signed-off-by Damien Le Moal <[email protected]>--- fs/xfs/xfs_zone_info.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fs/xfs/xfs_zone_info.c +2
-0@@ -90,9 +90,14 @@ xfs_zoned_show_stats(seq_printf (m,"\tRT GC required: %d\n" ,xfs_zoned_need_gc (mp)); +seq_printf (m,"\ttotal number of zones: %u\n" , + mp->m_sb.sb_rgcount);
fs/xfs/xfs_zone_info.c xfs_zoned_show_stats( · line 103
Quoted 10 lines
fs/xfs/xfs_zone_info.c +4
-1seq_printf (m,"\tfree zones: %d\n" ,atomic_read (&zi->zi_nr_free_zones)); -seq_puts (m,"\topen zones:\n" ); +spin_lock (&zi->zi_open_zones_lock); +seq_printf (m,"\tnumber of open zones: %u / %u\n" , + zi->zi_nr_open_zones, mp->m_max_open_zones); +seq_puts (m,"\topen zones:\n" );list_for_each_entry (oz, &zi->zi_open_zones, oz_entry)xfs_show_open_zone (m, oz);if (zi->zi_open_gc_zone) {
Awesome, i've been wanting to have the current number of open zones as part of these stats for a while :)
Re: [PATCH v2 4/4] xfs: avoid unnecessary calculations in xfs_zoned_need_gc()
In reply to Damien Le MoalQuoted 53 lines · Damien Le Moal
If
zonegc_low_spaceis set to zero (which is the default), the second condition inxfs_zoned_need_gc()that triggers GC never evaluates to true because the calculated threshold will always be 0. So there is no need to calculate the threshold and to evaluate that condition. Return early whenzonegc_low_spaceis zero.While at it, add comments to document the intent of each of the 3 tests used to determine the return value to control the execution of garbage collection.
Signed-off-by Damien Le Moal <[email protected]>--- fs/xfs/xfs_zone_gc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)fs/xfs/xfs_zone_gc.c +17
-2@@ -170,25 +170,37 @@ xfs_zoned_need_gc(s64 available, free, threshold;s32 remainder; +/* If we have no reclaimable blocks, running GC is useless. */ if (!xfs_zoned_have_reclaimable (mp->m_zone_info))return false; +/* +* In order to avoid file fragmentation as much as possible, we should +* make sure that we can open enough zones. So trigger GC if the number +* of blocks immediately available for writes is lower than the total +* number of blocks from all possible open zones. +*/ available =xfs_estimate_freecounter (mp,XC_FREE_RTAVAILABLE ); -if (available <xfs_rtgs_to_rfsbs (mp, mp->m_max_open_zones -XFS_OPEN_GC_ZONES ))return true; - free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); +/* +* For cases where the user wants to be more aggressive with GC, +* the sysfs attribute zonegc_low_space may be set to a non zero value, +* to indicate that GC should try to maintain at least zonegc_low_space +* percent of the free space to be directly available for writing. Check +* this here. +*/ +if (!mp->m_zonegc_low_space) +return false; + free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); threshold =div_s64_rem (free,100 , &remainder); threshold = threshold * mp->m_zonegc_low_space +
fs/xfs/xfs_zone_gc.c xfs_zoned_need_gc( · line 206
Quoted 10 lines
fs/xfs/xfs_zone_gc.c +1
-4remainder *div_s64 (mp->m_zonegc_low_space,100 ); -if (available < threshold) -return true; - -return false; +return available < threshold; } static struct xfs_zone_gc_data *
The optimization makes sense & thanks for providing the documentation!
Quoted 6 lines · Damien Le Moal
All,
Here are 4 simple patches to cleanup the code for zoned XFS. Overall, there is no functional changes introduced beside the change of information displayed in
/proc/self/mountstats(patch 3).
Quoted 7 lines
Changes from v1:
- Split former patch 1 into patch 1 and 2.
- Changed patch 3 to add new lines of information instead of changing the existing lines.
- Reworked commit titles and messages.[...]
Applied to for-next, thanks!
[1/4] xfs: avoid unnecessary open zone check in xfs_select_zone_nowait()
commit: 770323d418ed5848cc21af172f77377b2cc0542d
[2/4] xfs: fix a comment typo in xfs_select_zone_nowait()
commit: 6a82a691b08070ad03b237d7db89aa0bfef389e2
[3/4] xfs: display more zone related information in mountstats
commit: 68aa101bf2046aa8365333a3768cece07975ca5f
[4/4] xfs: avoid unnecessary calculations in xfs_zoned_need_gc()
commit: c1f955437440f92632e2efca4b591371bb3caefcBest regards,
Signature · 1 line
Carlos Maiolino <[email protected]>