xfs: start gc on zonegc_low_space attribute updates
Subsystems (2)
PATCH v2 1/1 xfs: start gc on zonegc_low_space attribute updates
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
---
v2:
- Added a new helper to wake up the gc thread in stead of unparking it, which is required to make this work properly.
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
- Added fixes and stable cc tags as provided by Darrick.
v1: https://lore.kernel.org/linux-xfs/[email protected]/
fs/xfs/xfs_sysfs.c | 7 ++++++- fs/xfs/xfs_zone_alloc.h | 4 ++++ fs/xfs/xfs_zone_gc.c | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-)
fs/xfs/xfs_sysfs.c +6 -1
@@ -14,6 +14,7 @@#include "xfs_log_priv.h" #include "xfs_mount.h" #include "xfs_zones.h" +#include "xfs_zone_alloc.h" struct xfs_sysfs_attr {struct attribute attr;
@@ -724,6 +725,7 @@ zonegc_low_space_store( const char *buf, size_t count) { +struct xfs_mount *mp =zoned_to_mp (kobj);int ret;unsigned int val;
@@ -734,7 +736,10 @@ zonegc_low_space_store(if (val >100 )return -EINVAL ; -zoned_to_mp (kobj)->m_zonegc_low_space = val; +if (mp->m_zonegc_low_space != val) { + mp->m_zonegc_low_space = val; +xfs_zone_gc_wakeup (mp); + }return count; }
fs/xfs/xfs_zone_alloc.h +4 -0
@@ -51,6 +51,7 @@ int xfs_mount_zones(struct xfs_mount *mp);void xfs_unmount_zones (struct xfs_mount *mp);void xfs_zone_gc_start (struct xfs_mount *mp);void xfs_zone_gc_stop (struct xfs_mount *mp); +void xfs_zone_gc_wakeup (struct xfs_mount *mp);#else static inline int xfs_mount_zones (struct xfs_mount *mp) {
@@ -65,6 +66,9 @@ static inline void xfs_zone_gc_start(struct xfs_mount *mp)static inline void xfs_zone_gc_stop (struct xfs_mount *mp) { } +static inline void xfs_zone_gc_wakeup (struct xfs_mount *mp) +{ +}#endif /* CONFIG_XFS_RT */ #endif /* _XFS_ZONE_ALLOC_H */
fs/xfs/xfs_zone_gc.c +17 -0
@@ -1171,6 +1171,23 @@ xfs_zone_gc_stop(kthread_park (mp->m_zone_info->zi_gc_thread); } +void +xfs_zone_gc_wakeup ( +struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; + +/* +* If we are unmounting the file system we must not try to +* wake gc as m_zone_info might have been freed already. +*/ +if (down_read_trylock (&sb->s_umount)) { +if (!xfs_is_readonly (mp)) +wake_up_process (mp->m_zone_info->zi_gc_thread); +up_read (&sb->s_umount); + } +} +int xfs_zone_gc_mount (struct xfs_mount *mp)
Signature · 1 line
2.34.1
Quoted 89 lines · Hans Holmberg
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
Cc <[email protected]> # v6.15Fixes 845abeb1f06a8a ("xfs: add tunable threshold parameter for triggering zone GC")Signed-off-by Hans Holmberg <[email protected]>---
v2:
- Added a new helper to wake up the gc thread in stead of unparking it, which is required to make this work properly.
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
- Added fixes and stable cc tags as provided by Darrick.v1: https://lore.kernel.org/linux-xfs/[email protected]/
fs/xfs/xfs_sysfs.c | 7 ++++++- fs/xfs/xfs_zone_alloc.h | 4 ++++ fs/xfs/xfs_zone_gc.c | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-)fs/xfs/xfs_sysfs.c +6
-1@@ -14,6 +14,7 @@#include "xfs_log_priv.h" #include "xfs_mount.h" #include "xfs_zones.h" +#include "xfs_zone_alloc.h" struct xfs_sysfs_attr {struct attribute attr;@@ -724,6 +725,7 @@ zonegc_low_space_store( const char *buf, size_t count) { +struct xfs_mount *mp =zoned_to_mp (kobj);int ret;unsigned int val;@@ -734,7 +736,10 @@ zonegc_low_space_store(if (val >100 )return -EINVAL ; -zoned_to_mp (kobj)->m_zonegc_low_space = val; +if (mp->m_zonegc_low_space != val) { + mp->m_zonegc_low_space = val; +xfs_zone_gc_wakeup (mp); + }return count; }fs/xfs/xfs_zone_alloc.h +4
-0@@ -51,6 +51,7 @@ int xfs_mount_zones(struct xfs_mount *mp);void xfs_unmount_zones (struct xfs_mount *mp);void xfs_zone_gc_start (struct xfs_mount *mp);void xfs_zone_gc_stop (struct xfs_mount *mp); +void xfs_zone_gc_wakeup (struct xfs_mount *mp);#else static inline int xfs_mount_zones (struct xfs_mount *mp) {@@ -65,6 +66,9 @@ static inline void xfs_zone_gc_start(struct xfs_mount *mp)static inline void xfs_zone_gc_stop (struct xfs_mount *mp) { } +static inline void xfs_zone_gc_wakeup (struct xfs_mount *mp) +{ +}#endif /* CONFIG_XFS_RT */ #endif /* _XFS_ZONE_ALLOC_H */ fs/xfs/xfs_zone_gc.c +1
-0@@ -1171,6 +1171,23 @@ xfs_zone_gc_stop(kthread_park (mp->m_zone_info->zi_gc_thread); } +void
fs/xfs/xfs_zone_gc.c xfs_zone_gc_stop( · line 1184
Quoted 10 lines
fs/xfs/xfs_zone_gc.c +10
-0+xfs_zone_gc_wakeup ( + struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; + +/* +* If we are unmounting the file system we must not try to +* wake gc as m_zone_info might have been freed already. +*/ +if (down_read_trylock (&sb->s_umount)) {
s_umount can be held exclusively for other things (e.g. freeze attempts) which means that you might miss a wakeup here even though the filesystem isn't unmounting.
That's probably benign here and in the other place (inode flush) that does this, but it's worth asking -- will it matter that there's a slight chance that someone adjusts the value and we fail to wake up the gc thread?
--D
Quoted 13 lines
fs/xfs/xfs_zone_gc.c +6
-0+if (!xfs_is_readonly (mp)) +wake_up_process (mp->m_zone_info->zi_gc_thread); +up_read (&sb->s_umount); + } +} +int xfs_zone_gc_mount (struct xfs_mount *mp)Signature · 1 line
2.34.1
Quoted 105 lines · Darrick J. Wong
Quoted 89 lines · Hans Holmberg
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
Cc <[email protected]> # v6.15Fixes 845abeb1f06a8a ("xfs: add tunable threshold parameter for triggering zone GC")Signed-off-by Hans Holmberg <[email protected]>---
v2:
- Added a new helper to wake up the gc thread in stead of unparking it, which is required to make this work properly.
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
- Added fixes and stable cc tags as provided by Darrick.v1: https://lore.kernel.org/linux-xfs/[email protected]/
fs/xfs/xfs_sysfs.c | 7 ++++++- fs/xfs/xfs_zone_alloc.h | 4 ++++ fs/xfs/xfs_zone_gc.c | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-)fs/xfs/xfs_sysfs.c +6
-1@@ -14,6 +14,7 @@#include "xfs_log_priv.h" #include "xfs_mount.h" #include "xfs_zones.h" +#include "xfs_zone_alloc.h" struct xfs_sysfs_attr {struct attribute attr;@@ -724,6 +725,7 @@ zonegc_low_space_store( const char *buf, size_t count) { +struct xfs_mount *mp =zoned_to_mp (kobj);int ret;unsigned int val;@@ -734,7 +736,10 @@ zonegc_low_space_store(if (val >100 )return -EINVAL ; -zoned_to_mp (kobj)->m_zonegc_low_space = val; +if (mp->m_zonegc_low_space != val) { + mp->m_zonegc_low_space = val; +xfs_zone_gc_wakeup (mp); + }return count; }fs/xfs/xfs_zone_alloc.h +4
-0@@ -51,6 +51,7 @@ int xfs_mount_zones(struct xfs_mount *mp);void xfs_unmount_zones (struct xfs_mount *mp);void xfs_zone_gc_start (struct xfs_mount *mp);void xfs_zone_gc_stop (struct xfs_mount *mp); +void xfs_zone_gc_wakeup (struct xfs_mount *mp);#else static inline int xfs_mount_zones (struct xfs_mount *mp) {@@ -65,6 +66,9 @@ static inline void xfs_zone_gc_start(struct xfs_mount *mp)static inline void xfs_zone_gc_stop (struct xfs_mount *mp) { } +static inline void xfs_zone_gc_wakeup (struct xfs_mount *mp) +{ +}#endif /* CONFIG_XFS_RT */ #endif /* _XFS_ZONE_ALLOC_H */ fs/xfs/xfs_zone_gc.c +1
-0@@ -1171,6 +1171,23 @@ xfs_zone_gc_stop(kthread_park (mp->m_zone_info->zi_gc_thread); } +void fs/xfs/xfs_zone_gc.c xfs_zone_gc_stop( · line 1184
Quoted 10 lines
fs/xfs/xfs_zone_gc.c +10
-0+xfs_zone_gc_wakeup ( + struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; + +/* +* If we are unmounting the file system we must not try to +* wake gc as m_zone_info might have been freed already. +*/ +if (down_read_trylock (&sb->s_umount)) {
s_umountcan be held exclusively for other things (e.g. freeze attempts) which means that you might miss a wakeup here even though the filesystem isn't unmounting.
Quoted 5 lines
That's probably benign here and in the other place (inode flush) that does this, but it's worth asking -- will it matter that there's a slight chance that someone adjusts the value and we fail to wake up the gc thread?
For freezes, we'll check the condition for starting gc when we've thawed, and in general I don't think it's a big deal to miss a wakeup when writing the attribute for rare corner cases. The new setting will take effect as soon as a zone is filled or marked as partially used.
Quoted 9 lines · Hans Holmberg
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
Cc <[email protected]> # v6.15Fixes 845abeb1f06a8a ("xfs: add tunable threshold parameter for triggering zone GC")Signed-off-by Hans Holmberg <[email protected]>
Looks OK to me.
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 9 lines · Hans Holmberg
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
Cc <[email protected]> # v6.15Fixes 845abeb1f06a8a ("xfs: add tunable threshold parameter for triggering zone GC")Signed-off-by Hans Holmberg <[email protected]>
Quoted 8 lines
---
v2:
- Added a new helper to wake up the gc thread in stead of unparking it, which is required to make this work properly.
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
Isn't that a deadlock vector?
i.e. unmount takes s_umount, concurrently userspace writes a new value to sysfs file. sysfs file write blocks on s_umount, unmount blocks holding s_umount waiting for sysfs file reference count to go to zero to destroy it?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 6 lines · Dave Chinner
Quoted 5 lines
- Added a new helper to wake up the gc thread in stead of unparking it, which is required to make this work properly.
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
Quoted 6 lines
Isn't that a deadlock vector?
i.e. unmount takes
s_umount, concurrently userspace writes a new value to sysfs file. sysfs file write blocks ons_umount, unmount blocks holdings_umountwaiting for sysfs file reference count to go to zero to destroy it?
Given that the code does a trylock it should not.
Quoted 3 lines · Hans Holmberg
- Added protection against races with unmounts as sysfs gets torn down after the zone info struct is freed. This also avoids unneded wakeups during remount.
Independent of this patch we really should tear down sysfs early in unmount, otherwise we'll run into issues with data structures torn down first eventually.
Otherwise looks good:
Quoted 8 lines · Hans Holmberg
Start gc if the agressiveness of zone garbage collection is changed by the user (if the file system is not read only).
Without this change, the new setting will not be taken into account until the gc thread is woken up by e.g. a write.
[...]
Applied to for-next, thanks!
[1/1] xfs: start gc on zonegc_low_space attribute updates
commit: 181ea4e2de422aa0a66f355bd59bccccdd169826
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>