xfs: consolidate posteof and cowblocks cleanup
v3 cover xfs: consolidate posteof and cowblocks cleanup
Hi all,
Currently, we treat the garbage collection of post-EOF preallocations and copy-on-write preallocations as totally separate tasks -- different incore inode tags, different workqueues, etc. This is wasteful of radix tree tags and workqueue resources since we effectively have parallel code paths to do the same thing.
Therefore, consolidate both functions under one radix tree bit and one workqueue function that scans an inode for both things at the same time. At the end of the series we make the scanning per-AG instead of per-fs so that the scanning can run in parallel. This reduces locking contention from background threads and will free up a radix tree bit for the deferred inode inactivation series.
v2: clean up and rebase against 5.11.
v3: various streamlining as part of restructuring the space reclaim series
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=eofblocks-consolidation-5.12
--- fs/xfs/scrub/common.c | 4 - fs/xfs/xfs_globals.c | 7 + fs/xfs/xfs_icache.c | 258 +++++++++++++++++++++---------------------------- fs/xfs/xfs_icache.h | 16 +-- fs/xfs/xfs_ioctl.c | 2 fs/xfs/xfs_iwalk.c | 2 fs/xfs/xfs_linux.h | 3 - fs/xfs/xfs_mount.c | 5 + fs/xfs/xfs_mount.h | 9 +- fs/xfs/xfs_pwork.c | 80 ++++++++++++++- fs/xfs/xfs_pwork.h | 3 - fs/xfs/xfs_super.c | 51 +++++++--- fs/xfs/xfs_sysctl.c | 15 +-- fs/xfs/xfs_sysctl.h | 3 - fs/xfs/xfs_trace.h | 6 - 15 files changed, 253 insertions(+), 211 deletions(-)
PATCH v3 1/10 xfs: relocate the eofb/cowb workqueue functions
From: Darrick J. Wong <[email protected]>
Move the xfs_{eof,cow}blocks_worker and xfs_queue_{eof,cow}blocks functions further down in the file so that the cleanups in the next patches won't have to pre-declare static functions. No functional changes.
--- fs/xfs/xfs_icache.c | 126 ++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 63 deletions(-)
fs/xfs/xfs_icache.c +63 -63
@@ -915,69 +915,6 @@ xfs_inode_walk(return last_error; } -/* -* Background scanning to trim post-EOF preallocated space. This is queued -* based on the 'speculative_prealloc_lifetime' tunable (5m by default). -*/ -void -xfs_queue_eofblocks ( -struct xfs_mount *mp) -{ -rcu_read_lock (); -if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_EOFBLOCKS_TAG )) -queue_delayed_work (mp->m_eofblocks_workqueue, - &mp->m_eofblocks_work, -msecs_to_jiffies (xfs_eofb_secs *1000 )); -rcu_read_unlock (); -} - -void -xfs_eofblocks_worker ( -struct work_struct *work) -{ -struct xfs_mount *mp =container_of (to_delayed_work (work), - struct xfs_mount, m_eofblocks_work); - -if (!sb_start_write_trylock (mp->m_super)) -return ; -xfs_icache_free_eofblocks (mp,NULL ); -sb_end_write (mp->m_super); - -xfs_queue_eofblocks (mp); -} - -/* -* Background scanning to trim preallocated CoW space. This is queued -* based on the 'speculative_cow_prealloc_lifetime' tunable (5m by default). -* (We'll just piggyback on the post-EOF prealloc space workqueue.) -*/ -void -xfs_queue_cowblocks ( -struct xfs_mount *mp) -{ -rcu_read_lock (); -if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_COWBLOCKS_TAG )) -queue_delayed_work (mp->m_eofblocks_workqueue, - &mp->m_cowblocks_work, -msecs_to_jiffies (xfs_cowb_secs *1000 )); -rcu_read_unlock (); -} - -void -xfs_cowblocks_worker ( -struct work_struct *work) -{ -struct xfs_mount *mp =container_of (to_delayed_work (work), - struct xfs_mount, m_cowblocks_work); - -if (!sb_start_write_trylock (mp->m_super)) -return ; -xfs_icache_free_cowblocks (mp,NULL ); -sb_end_write (mp->m_super); - -xfs_queue_cowblocks (mp); -} -/* * Grab the inode for reclaim exclusively. *
@@ -1396,6 +1333,37 @@ xfs_icache_free_eofblocks( XFS_ICI_EOFBLOCKS_TAG); } +/* +* Background scanning to trim post-EOF preallocated space. This is queued +* based on the 'speculative_prealloc_lifetime' tunable (5m by default). +*/ +void +xfs_queue_eofblocks ( +struct xfs_mount *mp) +{ +rcu_read_lock (); +if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_EOFBLOCKS_TAG )) +queue_delayed_work (mp->m_eofblocks_workqueue, + &mp->m_eofblocks_work, +msecs_to_jiffies (xfs_eofb_secs *1000 )); +rcu_read_unlock (); +} + +void +xfs_eofblocks_worker ( +struct work_struct *work) +{ +struct xfs_mount *mp =container_of (to_delayed_work (work), + struct xfs_mount, m_eofblocks_work); + +if (!sb_start_write_trylock (mp->m_super)) +return ; +xfs_icache_free_eofblocks (mp,NULL ); +sb_end_write (mp->m_super); + +xfs_queue_eofblocks (mp); +} +static inline unsigned long xfs_iflag_for_tag (int tag)
@@ -1608,6 +1576,38 @@ xfs_icache_free_cowblocks( XFS_ICI_COWBLOCKS_TAG); } +/* +* Background scanning to trim preallocated CoW space. This is queued +* based on the 'speculative_cow_prealloc_lifetime' tunable (5m by default). +* (We'll just piggyback on the post-EOF prealloc space workqueue.) +*/ +void +xfs_queue_cowblocks ( +struct xfs_mount *mp) +{ +rcu_read_lock (); +if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_COWBLOCKS_TAG )) +queue_delayed_work (mp->m_eofblocks_workqueue, + &mp->m_cowblocks_work, +msecs_to_jiffies (xfs_cowb_secs *1000 )); +rcu_read_unlock (); +} + +void +xfs_cowblocks_worker ( +struct work_struct *work) +{ +struct xfs_mount *mp =container_of (to_delayed_work (work), + struct xfs_mount, m_cowblocks_work); + +if (!sb_start_write_trylock (mp->m_super)) +return ; +xfs_icache_free_cowblocks (mp,NULL ); +sb_end_write (mp->m_super); + +xfs_queue_cowblocks (mp); +} +void xfs_inode_set_cowblocks_tag (xfs_inode_t *ip)
Re: [PATCH 01/10] xfs: relocate the eofb/cowb workqueue functions
Looks good,
PATCH v3 2/10 xfs: hide xfs_icache_free_eofblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Change the one remaining caller of xfs_icache_free_eofblocks to use our new combined blockgc scan function instead, since we will soon be combining the two scans. This introduces a slight behavior change, since the XFS_IOC_FREE_EOFBLOCKS now clears out speculative CoW reservations in addition to post-eof blocks.
--- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_icache.h | 1 - fs/xfs/xfs_ioctl.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_icache.c +1 -1
@@ -1324,7 +1324,7 @@ xfs_inode_free_eofblocks(return ret; } -int +static int xfs_icache_free_eofblocks (struct xfs_mount *mp,struct xfs_eofblocks *eofb)
fs/xfs/xfs_icache.h +0 -1
@@ -63,7 +63,6 @@ int xfs_blockgc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb);void xfs_inode_set_eofblocks_tag (struct xfs_inode *ip);void xfs_inode_clear_eofblocks_tag (struct xfs_inode *ip); -int xfs_icache_free_eofblocks (struct xfs_mount *,struct xfs_eofblocks *);void xfs_eofblocks_worker (struct work_struct *);void xfs_queue_eofblocks (struct xfs_mount *);
fs/xfs/xfs_ioctl.c +1 -1
@@ -2359,7 +2359,7 @@ xfs_file_ioctl(trace_xfs_ioc_free_eofblocks (mp, &keofb, _RET_IP_);sb_start_write (mp->m_super); - error =xfs_icache_free_eofblocks (mp, &keofb); + error =xfs_blockgc_free_space (mp, &keofb);sb_end_write (mp->m_super);return error; }
Re: [PATCH 02/10] xfs: hide xfs_icache_free_eofblocks
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Change the one remaining caller of
xfs_icache_free_eofblocksto use our new combined blockgc scan function instead, since we will soon be combining the two scans. This introduces a slight behavior change, since theXFS_IOC_FREE_EOFBLOCKSnow clears out speculative CoW reservations in addition to post-eof blocks.Signed-off-by Darrick J. Wong <[email protected]>
Looks good,
PATCH v3 3/10 xfs: hide xfs_icache_free_cowblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Change the one remaining caller of xfs_icache_free_cowblocks to use our new combined blockgc scan function instead, since we will soon be combining the two scans. This introduces a slight behavior change, since a readonly remount now clears out post-EOF preallocations and not just CoW staging extents.
--- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_icache.h | 1 - fs/xfs/xfs_super.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_icache.c +1 -1
@@ -1567,7 +1567,7 @@ xfs_inode_free_cowblocks(return ret; } -int +static int xfs_icache_free_cowblocks (struct xfs_mount *mp,struct xfs_eofblocks *eofb)
fs/xfs/xfs_icache.h +0 -1
@@ -68,7 +68,6 @@ void xfs_queue_eofblocks(struct xfs_mount *);void xfs_inode_set_cowblocks_tag (struct xfs_inode *ip);void xfs_inode_clear_cowblocks_tag (struct xfs_inode *ip); -int xfs_icache_free_cowblocks (struct xfs_mount *,struct xfs_eofblocks *);void xfs_cowblocks_worker (struct work_struct *);void xfs_queue_cowblocks (struct xfs_mount *);
fs/xfs/xfs_super.c +1 -1
@@ -1743,7 +1743,7 @@ xfs_remount_ro(xfs_stop_block_reaping (mp);/* Get rid of any leftover CoW reservations... */ - error =xfs_icache_free_cowblocks (mp,NULL ); + error =xfs_blockgc_free_space (mp,NULL );if (error) {xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE );return error;
Re: [PATCH 03/10] xfs: hide xfs_icache_free_cowblocks
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Change the one remaining caller of
xfs_icache_free_cowblocksto use our new combined blockgc scan function instead, since we will soon be combining the two scans. This introduces a slight behavior change, since a readonly remount now clears out post-EOF preallocations and not just CoW staging extents.Signed-off-by Darrick J. Wong <[email protected]>
Looks good,
PATCH v3 4/10 xfs: remove trivial eof/cowblocks functions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Get rid of these trivial helpers.
--- fs/xfs/xfs_icache.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-)
fs/xfs/xfs_icache.c +8 -22
@@ -1324,15 +1324,6 @@ xfs_inode_free_eofblocks(return ret; } -static int -xfs_icache_free_eofblocks ( -struct xfs_mount *mp, -struct xfs_eofblocks *eofb) -{ -return xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks, eofb, -XFS_ICI_EOFBLOCKS_TAG ); -} -/* * Background scanning to trim post-EOF preallocated space. This is queued * based on the 'speculative_prealloc_lifetime' tunable (5m by default).
@@ -1358,7 +1349,8 @@ xfs_eofblocks_worker(if (!sb_start_write_trylock (mp->m_super))return ; -xfs_icache_free_eofblocks (mp,NULL ); +xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks,NULL , +XFS_ICI_EOFBLOCKS_TAG );sb_end_write (mp->m_super);xfs_queue_eofblocks (mp);
@@ -1567,15 +1559,6 @@ xfs_inode_free_cowblocks(return ret; } -static int -xfs_icache_free_cowblocks ( -struct xfs_mount *mp, -struct xfs_eofblocks *eofb) -{ -return xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks, eofb, -XFS_ICI_COWBLOCKS_TAG ); -} -/* * Background scanning to trim preallocated CoW space. This is queued * based on the 'speculative_cow_prealloc_lifetime' tunable (5m by default).
@@ -1602,7 +1585,8 @@ xfs_cowblocks_worker(if (!sb_start_write_trylock (mp->m_super))return ; -xfs_icache_free_cowblocks (mp,NULL ); +xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks,NULL , +XFS_ICI_COWBLOCKS_TAG );sb_end_write (mp->m_super);xfs_queue_cowblocks (mp);
@@ -1653,11 +1637,13 @@ xfs_blockgc_scan( {int error; - error =xfs_icache_free_eofblocks (mp, eofb); + error =xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks, eofb, +XFS_ICI_EOFBLOCKS_TAG );if (error)return error; - error =xfs_icache_free_cowblocks (mp, eofb); + error =xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks, eofb, +XFS_ICI_COWBLOCKS_TAG );if (error)return error;
Re: [PATCH 04/10] xfs: remove trivial eof/cowblocks functions
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Get rid of these trivial helpers.
Signed-off-by Darrick J. Wong <[email protected]>
Looks good,
PATCH v3 5/10 xfs: increase the default parallelism levels of pwork clients
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Increase the default parallelism level for pwork clients so that we can take advantage of computers with a lot of CPUs and a lot of hardware. The posteof/cowblocks cleanup series will use the functionality presented in this patch to constrain the number of background per-ag gc threads to our best estimate of the amount of parallelism that the filesystem can sustain.
--- fs/xfs/xfs_iwalk.c | 2 + fs/xfs/xfs_pwork.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++----- fs/xfs/xfs_pwork.h | 3 +- 3 files changed, 76 insertions(+), 9 deletions(-)
fs/xfs/xfs_iwalk.c +1 -1
@@ -624,7 +624,7 @@ xfs_iwalk_threaded(ASSERT (agno < mp->m_sb.sb_agcount);ASSERT (!(flags & ~XFS_IWALK_FLAGS_ALL )); - nr_threads =xfs_pwork_guess_datadev_parallelism (mp); + nr_threads =xfs_pwork_guess_workqueue_threads (mp); error =xfs_pwork_init (mp, &pctl, xfs_iwalk_ag_work,"xfs_iwalk" , nr_threads);if (error)
fs/xfs/xfs_pwork.c +73 -7
92 lines not on this page · raw message
fs/xfs/xfs_pwork.h +2 -1
@@ -56,6 +56,7 @@ int xfs_pwork_init(struct xfs_mount *mp, struct xfs_pwork_ctl *pctl,void xfs_pwork_queue (struct xfs_pwork_ctl *pctl,struct xfs_pwork *pwork);int xfs_pwork_destroy (struct xfs_pwork_ctl *pctl);void xfs_pwork_poll (struct xfs_pwork_ctl *pctl); -unsigned int xfs_pwork_guess_datadev_parallelism (struct xfs_mount *mp); +unsigned int xfs_pwork_guess_metadata_threads (struct xfs_mount *mp); +unsigned int xfs_pwork_guess_workqueue_threads (struct xfs_mount *mp);#endif /* __XFS_PWORK_H__ */
PATCH 1/1 xfs: create mount option to override metadata threads
From: Darrick J. Wong <[email protected]>
Create a mount option so that sysadmins can override the estimated parallelism of the filesystem, which in turn controls the number of active work items in background threads.
--- fs/xfs/xfs_mount.h | 3 +++ fs/xfs/xfs_pwork.c | 5 +++++ fs/xfs/xfs_super.c | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+)
fs/xfs/xfs_mount.h +3 -0
@@ -209,6 +209,9 @@ typedef struct xfs_mount {struct mutex m_growlock;/* growfs mutex */ #ifdef DEBUG +/* Desired parallelism of threaded tasks and background workers. */ +unsigned int m_metadata_threads; +/* * Frequency with which errors are injected. Replaces xfs_etest; the * value stored in here is the inverse of the frequency with which the
fs/xfs/xfs_pwork.c +5 -0
@@ -162,6 +162,11 @@ xfs_pwork_guess_metadata_threads( {unsigned int threads; +#ifdef DEBUG +if (mp->m_metadata_threads >0 ) +return mp->m_metadata_threads; +#endif +/* * Estimate the amount of parallelism for metadata operations from the * least capable of the two devices that handle metadata. Cap that
fs/xfs/xfs_super.c +22 -0
@@ -93,6 +93,9 @@ enum { Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota, Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce, Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum, +#ifdef DEBUG + Opt_metadata_threads, +#endif }; static const struct fs_parameter_spec xfs_fs_parameters[] = {
@@ -137,6 +140,9 @@ static const struct fs_parameter_spec xfs_fs_parameters[] = {fsparam_flag ("nodiscard" , Opt_nodiscard),fsparam_flag ("dax" , Opt_dax),fsparam_enum ("dax" , Opt_dax_enum, dax_param_enums), +#ifdef DEBUG + fsparam_u32("metadata_threads", Opt_metadata_threads), +#endif {} };
@@ -222,6 +228,11 @@ xfs_fs_show_options(if (!(mp->m_qflags &XFS_ALL_QUOTA_ACCT ))seq_puts (m,",noquota" ); +#ifdef DEBUG +if (mp->m_metadata_threads >0 ) +seq_printf (m,",metadata_threads=%u" , mp->m_metadata_threads); +#endif +return 0 ; }
@@ -1291,6 +1302,12 @@ xfs_fs_parse_param(case Opt_dax_enum:xfs_mount_set_dax_mode (mp, result.uint_32);return 0 ; +#endif +#ifdef DEBUG +case Opt_metadata_threads: +xfs_warn (mp,"%s set to %u" , param->key, result.uint_32); + mp->m_metadata_threads = result.uint_32; +return 0 ;#endif /* Following mount options will be removed in September 2025 */ case Opt_ikeep:
@@ -1831,6 +1848,11 @@ xfs_fs_reconfigure(return error; } +#ifdef DEBUG + mp->m_metadata_threads = new_mp->m_metadata_threads; +xfs_configure_background_workqueues (mp); +#endif +return 0 ; }
Re: [PATCH 05/10] xfs: increase the default parallelism levels of pwork clients
In reply to Darrick J. WongQuoted 8 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Increase the default parallelism level for pwork clients so that we can take advantage of computers with a lot of CPUs and a lot of hardware. The posteof/cowblocks cleanup series will use the functionality presented in this patch to constrain the number of background per-ag gc threads to our best estimate of the amount of parallelism that the filesystem can sustain.
Dave and I had a conversation on IRC about this trying to figure out the "desired" parallelism of filesystem threads in which he pointed out that we can't easily figure out the real iops capacity of the storage -- devices don't report "nonrotational" status correctly, hardware raid with caches and nvram don't neatly fit our "spinning floppy" vs "ssd" dichotomy, and in the end the device concurrency is the queue depth of the underlying hardware. For really fast storage, even one io submitter per cpu isn't enough to saturate the device.
So rather than try to figure out the magic optimal number and introduce override knobs, XFS should not articially limit its concurrency levels. Wherever it is that the bottlenecks lie (data device, log device, log grants, locks) we might as well schedule work items as they come so that we can see all the hot spots as they arise.
I will rework this patch to remove the artificial limits, convert the quotacheck pworker to be unbound (since we actually /want/ the workers to spread out among the CPUs and we don't care about bounding), and add WQ_SYSFS to all the workqueues so we can examine them in /sys/bus/workqueue/devices.
--D
Quoted 133 lines
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_iwalk.c | 2 + fs/xfs/xfs_pwork.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++----- fs/xfs/xfs_pwork.h | 3 +- 3 files changed, 76 insertions(+), 9 deletions(-)fs/xfs/xfs_iwalk.c +1
-1@@ -624,7 +624,7 @@ xfs_iwalk_threaded(ASSERT (agno < mp->m_sb.sb_agcount);ASSERT (!(flags & ~XFS_IWALK_FLAGS_ALL )); - nr_threads =xfs_pwork_guess_datadev_parallelism (mp); + nr_threads =xfs_pwork_guess_workqueue_threads (mp); error =xfs_pwork_init (mp, &pctl, xfs_iwalk_ag_work,"xfs_iwalk" , nr_threads);if (error)fs/xfs/xfs_pwork.c +73
-7@@ -118,19 +118,85 @@ xfs_pwork_poll(touch_softlockup_watchdog (); } +/* Estimate the amount of parallelism available for a storage device. */ +static unsigned int +xfs_guess_buftarg_parallelism ( +struct xfs_buftarg *btp) +{ +int iomin; +int ioopt; + +/* +* The device tells us that it is non-rotational, and we take that to +* mean there are no moving parts and that the device can handle all +* the CPUs throwing IO requests at it. +*/ +if (blk_queue_nonrot (btp->bt_bdev->bd_disk->queue)) +return num_online_cpus (); + +/* +* The device has a preferred and minimum IO size that suggest a RAID +* setup, so infer the number of disks and assume that the parallelism +* is equal to the disk count. +*/ + iomin =bdev_io_min (btp->bt_bdev); + ioopt =bdev_io_opt (btp->bt_bdev); +if (iomin >0 && ioopt > iomin) +return ioopt / iomin; + +/* +* The device did not indicate that it has any capabilities beyond that +* of a rotating disk with a single drive head, so we estimate no +* parallelism at all. +*/ +return 1 ; +} +/* -* Return the amount of parallelism that the data device can handle, or 0 for -* no limit. +* Estimate the amount of parallelism that is available for metadata operations +* on this filesystem. */ unsigned int -xfs_pwork_guess_datadev_parallelism ( +xfs_pwork_guess_metadata_threads (struct xfs_mount *mp) { -struct xfs_buftarg *btp = mp->m_ddev_targp; +unsigned int threads;/* -* For now we'll go with the most conservative setting possible, -* which is two threads for an SSD and 1 thread everywhere else. +* Estimate the amount of parallelism for metadata operations from the +* least capable of the two devices that handle metadata. Cap that +* estimate to the number of AGs to avoid unnecessary lock contention. */ -return blk_queue_nonrot (btp->bt_bdev->bd_disk->queue) ?2 :1 ; + threads =xfs_guess_buftarg_parallelism (mp->m_ddev_targp); +if (mp->m_logdev_targp != mp->m_ddev_targp) + threads =min (xfs_guess_buftarg_parallelism (mp->m_logdev_targp), + threads); + threads =min (mp->m_sb.sb_agcount, threads); + +/* If the storage told us it has fancy capabilities, we're done. */ +if (threads >1 ) + goto clamp; + +/* +* Metadata storage did not even hint that it has any parallel +* capability. If the filesystem was formatted with a stripe unit and +* width, we'll treat that as evidence of a RAID setup and estimate +* the number of disks. +*/ +if (mp->m_sb.sb_unit >0 && mp->m_sb.sb_width > mp->m_sb.sb_unit) + threads = mp->m_sb.sb_width / mp->m_sb.sb_unit; + +clamp: +/* Don't return an estimate larger than the CPU count. */ +return min (num_online_cpus (), threads); +} + +/* Estimate how many threads we need for a parallel work queue. */ +unsigned int +xfs_pwork_guess_workqueue_threads ( +struct xfs_mount *mp) +{ +/* pwork queues are not unbounded, so we have to abide WQ_MAX_ACTIVE. */ + return min_t(unsigned int, xfs_pwork_guess_metadata_threads(mp), +WQ_MAX_ACTIVE ); }fs/xfs/xfs_pwork.h +2
-1@@ -56,6 +56,7 @@ int xfs_pwork_init(struct xfs_mount *mp, struct xfs_pwork_ctl *pctl,void xfs_pwork_queue (struct xfs_pwork_ctl *pctl,struct xfs_pwork *pwork);int xfs_pwork_destroy (struct xfs_pwork_ctl *pctl);void xfs_pwork_poll (struct xfs_pwork_ctl *pctl); -unsigned int xfs_pwork_guess_datadev_parallelism (struct xfs_mount *mp); +unsigned int xfs_pwork_guess_metadata_threads (struct xfs_mount *mp); +unsigned int xfs_pwork_guess_workqueue_threads (struct xfs_mount *mp);#endif /* __XFS_PWORK_H__ */
PATCH v3 6/10 xfs: consolidate incore inode radix tree posteof/cowblocks tags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The clearing of posteof blocks and cowblocks serve the same purpose:
removing speculative block preallocations from inactive files. We don't need to burn two radix tree tags on this, so combine them into one.
--- fs/xfs/xfs_icache.c | 114 ++++++++++++++++++++++++--------------------------- fs/xfs/xfs_icache.h | 4 +- fs/xfs/xfs_trace.h | 6 +-- 3 files changed, 58 insertions(+), 66 deletions(-)
fs/xfs/xfs_icache.c +54 -60
@@ -1291,6 +1291,9 @@ xfs_inode_free_eofblocks( wait = eofb && (eofb->eof_flags &XFS_EOF_FLAGS_SYNC ); +if (!xfs_iflags_test (ip,XFS_IEOFBLOCKS )) +return 0 ; +if (!xfs_can_free_eofblocks (ip, false)) {/* inode could be preallocated or append-only */ trace_xfs_inode_free_eofblocks_invalid (ip);
@@ -1333,7 +1336,7 @@ xfs_queue_eofblocks( struct xfs_mount *mp) {rcu_read_lock (); -if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_EOFBLOCKS_TAG )) +if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_BLOCKGC_TAG ))queue_delayed_work (mp->m_eofblocks_workqueue, &mp->m_eofblocks_work,msecs_to_jiffies (xfs_eofb_secs *1000 ));
@@ -1350,67 +1353,54 @@ xfs_eofblocks_worker(if (!sb_start_write_trylock (mp->m_super))return ;xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks,NULL , -XFS_ICI_EOFBLOCKS_TAG ); +XFS_ICI_BLOCKGC_TAG );sb_end_write (mp->m_super);xfs_queue_eofblocks (mp); } -static inline unsigned long -xfs_iflag_for_tag ( -int tag) -{ -switch (tag) { -case XFS_ICI_EOFBLOCKS_TAG : -return XFS_IEOFBLOCKS ; -case XFS_ICI_COWBLOCKS_TAG : -return XFS_ICOWBLOCKS ; -default : -ASSERT (0 ); -return 0 ; - } -} -static void -__xfs_inode_set_blocks_tag ( -xfs_inode_t *ip, -void (*execute)(struct xfs_mount *mp), -void (*set_tp)(struct xfs_mount *mp,xfs_agnumber_t agno, -int error,unsigned long caller_ip), -int tag) +xfs_blockgc_set_iflag ( +struct xfs_inode *ip, +void (*execute)(struct xfs_mount *mp), +unsigned long iflag) { -struct xfs_mount *mp = ip->i_mount; -struct xfs_perag *pag; -int tagged; +struct xfs_mount *mp = ip->i_mount; +struct xfs_perag *pag; +int tagged; + +ASSERT ((iflag & ~(XFS_IEOFBLOCKS |XFS_ICOWBLOCKS )) ==0 );/* * Don't bother locking the AG and looking up in the radix trees * if we already know that we have the tag set. */ -if (ip->i_flags &xfs_iflag_for_tag (tag)) +if (ip->i_flags & iflag)return ;spin_lock (&ip->i_flags_lock); - ip->i_flags |=xfs_iflag_for_tag (tag); + ip->i_flags |= iflag;spin_unlock (&ip->i_flags_lock); pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino));spin_lock (&pag->pag_ici_lock); - tagged =radix_tree_tagged (&pag->pag_ici_root, tag); + tagged =radix_tree_tagged (&pag->pag_ici_root,XFS_ICI_BLOCKGC_TAG );radix_tree_tag_set (&pag->pag_ici_root, -XFS_INO_TO_AGINO (ip->i_mount, ip->i_ino), tag); +XFS_INO_TO_AGINO (ip->i_mount, ip->i_ino), +XFS_ICI_BLOCKGC_TAG );if (!tagged) { -/* propagate the eofblocks tag up into the perag radix tree */ +/* propagate the blockgc tag up into the perag radix tree */ spin_lock (&ip->i_mount->m_perag_lock);radix_tree_tag_set (&ip->i_mount->m_perag_tree,XFS_INO_TO_AGNO (ip->i_mount, ip->i_ino), - tag); +XFS_ICI_BLOCKGC_TAG );spin_unlock (&ip->i_mount->m_perag_lock);/* kick off background trimming */ execute (ip->i_mount); -set_tp (ip->i_mount, pag->pag_agno,-1 , _RET_IP_); +trace_xfs_perag_set_blockgc (ip->i_mount, pag->pag_agno,-1 , + _RET_IP_); }spin_unlock (&pag->pag_ici_lock);
@@ -1422,38 +1412,43 @@ xfs_inode_set_eofblocks_tag( xfs_inode_t *ip) {trace_xfs_inode_set_eofblocks_tag (ip); -return __xfs_inode_set_blocks_tag (ip, xfs_queue_eofblocks, - trace_xfs_perag_set_eofblocks, -XFS_ICI_EOFBLOCKS_TAG ); +return xfs_blockgc_set_iflag (ip, xfs_queue_eofblocks,XFS_IEOFBLOCKS ); }static void -__xfs_inode_clear_blocks_tag ( -xfs_inode_t *ip, -void (*clear_tp)(struct xfs_mount *mp,xfs_agnumber_t agno, -int error,unsigned long caller_ip), -int tag) +xfs_blockgc_clear_iflag ( +struct xfs_inode *ip, +unsigned long iflag) { -struct xfs_mount *mp = ip->i_mount; -struct xfs_perag *pag; +struct xfs_mount *mp = ip->i_mount; +struct xfs_perag *pag; +bool clear_tag; + +ASSERT ((iflag & ~(XFS_IEOFBLOCKS |XFS_ICOWBLOCKS )) ==0 );spin_lock (&ip->i_flags_lock); - ip->i_flags &= ~xfs_iflag_for_tag (tag); + ip->i_flags &= ~iflag; + clear_tag = (ip->i_flags & (XFS_IEOFBLOCKS |XFS_ICOWBLOCKS )) ==0 ;spin_unlock (&ip->i_flags_lock); +if (!clear_tag) +return ; + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino));spin_lock (&pag->pag_ici_lock);radix_tree_tag_clear (&pag->pag_ici_root, -XFS_INO_TO_AGINO (ip->i_mount, ip->i_ino), tag); -if (!radix_tree_tagged (&pag->pag_ici_root, tag)) { -/* clear the eofblocks tag from the perag radix tree */ +XFS_INO_TO_AGINO (ip->i_mount, ip->i_ino), +XFS_ICI_BLOCKGC_TAG ); +if (!radix_tree_tagged (&pag->pag_ici_root,XFS_ICI_BLOCKGC_TAG )) { +/* clear the blockgc tag from the perag radix tree */ spin_lock (&ip->i_mount->m_perag_lock);radix_tree_tag_clear (&ip->i_mount->m_perag_tree,XFS_INO_TO_AGNO (ip->i_mount, ip->i_ino), - tag); +XFS_ICI_BLOCKGC_TAG );spin_unlock (&ip->i_mount->m_perag_lock); -clear_tp (ip->i_mount, pag->pag_agno,-1 , _RET_IP_); +trace_xfs_perag_clear_blockgc (ip->i_mount, pag->pag_agno,-1 , + _RET_IP_); }spin_unlock (&pag->pag_ici_lock);
@@ -1465,8 +1460,7 @@ xfs_inode_clear_eofblocks_tag( xfs_inode_t *ip) {trace_xfs_inode_clear_eofblocks_tag (ip); -return __xfs_inode_clear_blocks_tag (ip, - trace_xfs_perag_clear_eofblocks,XFS_ICI_EOFBLOCKS_TAG ); +return xfs_blockgc_clear_iflag (ip,XFS_IEOFBLOCKS ); }/*
@@ -1524,6 +1518,9 @@ xfs_inode_free_cowblocks( wait = eofb && (eofb->eof_flags &XFS_EOF_FLAGS_SYNC ); +if (!xfs_iflags_test (ip,XFS_ICOWBLOCKS )) +return 0 ; +if (!xfs_prep_free_cowblocks (ip))return 0 ;
@@ -1569,7 +1566,7 @@ xfs_queue_cowblocks( struct xfs_mount *mp) {rcu_read_lock (); -if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_COWBLOCKS_TAG )) +if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_BLOCKGC_TAG ))queue_delayed_work (mp->m_eofblocks_workqueue, &mp->m_cowblocks_work,msecs_to_jiffies (xfs_cowb_secs *1000 ));
@@ -1586,7 +1583,7 @@ xfs_cowblocks_worker(if (!sb_start_write_trylock (mp->m_super))return ;xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks,NULL , -XFS_ICI_COWBLOCKS_TAG ); +XFS_ICI_BLOCKGC_TAG );sb_end_write (mp->m_super);xfs_queue_cowblocks (mp);
@@ -1597,9 +1594,7 @@ xfs_inode_set_cowblocks_tag( xfs_inode_t *ip) {trace_xfs_inode_set_cowblocks_tag (ip); -return __xfs_inode_set_blocks_tag (ip, xfs_queue_cowblocks, - trace_xfs_perag_set_cowblocks, -XFS_ICI_COWBLOCKS_TAG ); +return xfs_blockgc_set_iflag (ip, xfs_queue_cowblocks,XFS_ICOWBLOCKS ); }void
@@ -1607,8 +1602,7 @@ xfs_inode_clear_cowblocks_tag( xfs_inode_t *ip) {trace_xfs_inode_clear_cowblocks_tag (ip); -return __xfs_inode_clear_blocks_tag (ip, - trace_xfs_perag_clear_cowblocks,XFS_ICI_COWBLOCKS_TAG ); +return xfs_blockgc_clear_iflag (ip,XFS_ICOWBLOCKS ); }/* Disable post-EOF and CoW block auto-reclamation. */
@@ -1638,12 +1632,12 @@ xfs_blockgc_scan(int error; error =xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks, eofb, -XFS_ICI_EOFBLOCKS_TAG ); +XFS_ICI_BLOCKGC_TAG );if (error)return error; error =xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks, eofb, -XFS_ICI_COWBLOCKS_TAG ); +XFS_ICI_BLOCKGC_TAG );if (error)return error;
fs/xfs/xfs_icache.h +2 -2
@@ -23,8 +23,8 @@ struct xfs_eofblocks {#define XFS_ICI_NO_TAG (-1)/* special flag for an untagged lookup in xfs_inode_walk */ #define XFS_ICI_RECLAIM_TAG 0/* inode is to be reclaimed */ -#define XFS_ICI_EOFBLOCKS_TAG 1/* inode has blocks beyond EOF */ -#define XFS_ICI_COWBLOCKS_TAG 2/* inode can have cow blocks to gc */ +/* Inode has speculative preallocations (posteof or cow) to clean. */ +#define XFS_ICI_BLOCKGC_TAG 1/* * Flags for xfs_iget()
fs/xfs/xfs_trace.h +2 -4
@@ -155,10 +155,8 @@ DEFINE_PERAG_REF_EVENT(xfs_perag_get_tag);DEFINE_PERAG_REF_EVENT (xfs_perag_put);DEFINE_PERAG_REF_EVENT (xfs_perag_set_reclaim);DEFINE_PERAG_REF_EVENT (xfs_perag_clear_reclaim); -DEFINE_PERAG_REF_EVENT (xfs_perag_set_eofblocks); -DEFINE_PERAG_REF_EVENT (xfs_perag_clear_eofblocks); -DEFINE_PERAG_REF_EVENT (xfs_perag_set_cowblocks); -DEFINE_PERAG_REF_EVENT (xfs_perag_clear_cowblocks); +DEFINE_PERAG_REF_EVENT (xfs_perag_set_blockgc); +DEFINE_PERAG_REF_EVENT (xfs_perag_clear_blockgc); DECLARE_EVENT_CLASS(xfs_ag_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno),
PATCH v3 7/10 xfs: consolidate the eofblocks and cowblocks workers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove the separate cowblocks work items and knob so that we can control and run everything from a single blockgc work queue. Note that the speculative_prealloc_lifetime sysfs knob retains its historical name even though the functions move to prefix xfs_blockgc_*.
--- fs/xfs/xfs_globals.c | 7 ++-- fs/xfs/xfs_icache.c | 96 ++++++++++++++++---------------------------------- fs/xfs/xfs_icache.h | 6 +-- fs/xfs/xfs_linux.h | 3 +- fs/xfs/xfs_mount.h | 6 +-- fs/xfs/xfs_super.c | 11 +++--- fs/xfs/xfs_sysctl.c | 15 ++------ fs/xfs/xfs_sysctl.h | 3 +- 8 files changed, 48 insertions(+), 99 deletions(-)
fs/xfs/xfs_globals.c +3 -4
@@ -8,8 +8,8 @@/* * Tunable XFS parameters. xfs_params is required even when CONFIG_SYSCTL=n, * other XFS code uses these values. Times are measured in centisecs (i.e. -* 100ths of a second) with the exception of eofb_timer and cowb_timer, which -* are measured in seconds. +* 100ths of a second) with the exception of blockgc_timer, which is measured +* in seconds. */ xfs_param_t xfs_params = {/* MIN DFLT MAX */
@@ -28,8 +28,7 @@ xfs_param_t xfs_params = { .rotorstep = { 1, 1, 255 }, .inherit_nodfrg = { 0, 1, 1 }, .fstrm_timer = { 1, 30*100, 3600*100}, - .eofb_timer = { 1, 300, 3600*24}, - .cowb_timer = { 1, 1800, 3600*24}, + .blockgc_timer = { 1, 300, 3600*24}, }; struct xfs_globals xfs_globals = {
fs/xfs/xfs_icache.c +31 -65
153 lines not on this page · raw message
fs/xfs/xfs_icache.h +2 -4
@@ -63,13 +63,11 @@ int xfs_blockgc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb);void xfs_inode_set_eofblocks_tag (struct xfs_inode *ip);void xfs_inode_clear_eofblocks_tag (struct xfs_inode *ip); -void xfs_eofblocks_worker (struct work_struct *); -void xfs_queue_eofblocks (struct xfs_mount *);void xfs_inode_set_cowblocks_tag (struct xfs_inode *ip);void xfs_inode_clear_cowblocks_tag (struct xfs_inode *ip); -void xfs_cowblocks_worker (struct work_struct *); -void xfs_queue_cowblocks (struct xfs_mount *); + +void xfs_blockgc_worker (struct work_struct *work); int xfs_inode_walk(struct xfs_mount *mp, int iter_flags, int (*execute)(struct xfs_inode *ip, void *args),
fs/xfs/xfs_linux.h +1 -2
@@ -98,8 +98,7 @@ typedef __u32 xfs_nlink_t;#define xfs_rotorstep xfs_params.rotorstep.val#define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val#define xfs_fstrm_centisecs xfs_params.fstrm_timer.val -#define xfs_eofb_secs xfs_params.eofb_timer.val -#define xfs_cowb_secs xfs_params.cowb_timer.val +#define xfs_blockgc_secs xfs_params.blockgc_timer.val#define current_cpu () (raw_smp_processor_id())#define current_set_flags_nested (sp, f) \
fs/xfs/xfs_mount.h +2 -4
@@ -93,7 +93,7 @@ typedef struct xfs_mount {struct workqueue_struct *m_unwritten_workqueue;struct workqueue_struct *m_cil_workqueue;struct workqueue_struct *m_reclaim_workqueue; -struct workqueue_struct *m_eofblocks_workqueue; +struct workqueue_struct *m_blockgc_workqueue;struct workqueue_struct *m_sync_workqueue;int m_bsize;/* fs logical block size */
@@ -177,9 +177,7 @@ typedef struct xfs_mount {uint64_t m_resblks_avail;/* available reserved blocks */ uint64_t m_resblks_save;/* reserved blks @ remount,ro */ struct delayed_work m_reclaim_work;/* background inode reclaim */ -struct delayed_work m_eofblocks_work;/* background eof blocks -trimming */ -struct delayed_work m_cowblocks_work;/* background cow blocks +struct delayed_work m_blockgc_work;/* background prealloc blocks trimming */ struct xfs_kobj m_kobj;struct xfs_kobj m_error_kobj;
fs/xfs/xfs_super.c +5 -6
@@ -515,9 +515,9 @@ xfs_init_mount_workqueues(if (!mp->m_reclaim_workqueue) goto out_destroy_cil; - mp->m_eofblocks_workqueue =alloc_workqueue ("xfs-eofblocks/%s" , + mp->m_blockgc_workqueue =alloc_workqueue ("xfs-blockgc/%s" ,WQ_MEM_RECLAIM |WQ_FREEZABLE ,0 , mp->m_super->s_id); -if (!mp->m_eofblocks_workqueue) +if (!mp->m_blockgc_workqueue) goto out_destroy_reclaim; mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
@@ -528,7 +528,7 @@ xfs_init_mount_workqueues(return 0 ; out_destroy_eofb: -destroy_workqueue (mp->m_eofblocks_workqueue); +destroy_workqueue (mp->m_blockgc_workqueue); out_destroy_reclaim:destroy_workqueue (mp->m_reclaim_workqueue); out_destroy_cil:
@@ -546,7 +546,7 @@ xfs_destroy_mount_workqueues( struct xfs_mount *mp) {destroy_workqueue (mp->m_sync_workqueue); -destroy_workqueue (mp->m_eofblocks_workqueue); +destroy_workqueue (mp->m_blockgc_workqueue);destroy_workqueue (mp->m_reclaim_workqueue);destroy_workqueue (mp->m_cil_workqueue);destroy_workqueue (mp->m_unwritten_workqueue);
@@ -1872,8 +1872,7 @@ static int xfs_init_fs_context(mutex_init (&mp->m_growlock);INIT_WORK (&mp->m_flush_inodes_work, xfs_flush_inodes_worker);INIT_DELAYED_WORK (&mp->m_reclaim_work, xfs_reclaim_worker); -INIT_DELAYED_WORK (&mp->m_eofblocks_work, xfs_eofblocks_worker); -INIT_DELAYED_WORK (&mp->m_cowblocks_work, xfs_cowblocks_worker); +INIT_DELAYED_WORK (&mp->m_blockgc_work, xfs_blockgc_worker); mp->m_kobj.kobject.kset = xfs_kset;/* * We don't create the finobt per-ag space reservation until after log
fs/xfs/xfs_sysctl.c +3 -12
@@ -194,21 +194,12 @@ static struct ctl_table xfs_table[] = { }, { .procname = "speculative_prealloc_lifetime", - .data = &xfs_params.eofb_timer.val, + .data = &xfs_params.blockgc_timer.val, .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec_minmax, - .extra1 = &xfs_params.eofb_timer.min, - .extra2 = &xfs_params.eofb_timer.max, - }, - { - .procname = "speculative_cow_prealloc_lifetime", - .data = &xfs_params.cowb_timer.val, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &xfs_params.cowb_timer.min, - .extra2 = &xfs_params.cowb_timer.max, + .extra1 = &xfs_params.blockgc_timer.min, + .extra2 = &xfs_params.blockgc_timer.max, },/* please keep this the last entry */ #ifdef CONFIG_PROC_FS
fs/xfs/xfs_sysctl.h +1 -2
@@ -35,8 +35,7 @@ typedef struct xfs_param {xfs_sysctl_val_t rotorstep;/* inode32 AG rotoring control knob */ xfs_sysctl_val_t inherit_nodfrg;/* Inherit the "nodefrag" inode flag. */ xfs_sysctl_val_t fstrm_timer;/* Filestream dir-AG assoc'n timeout. */ -xfs_sysctl_val_t eofb_timer;/* Interval between eofb scan wakeups */ -xfs_sysctl_val_t cowb_timer;/* Interval between cowb scan wakeups */ +xfs_sysctl_val_t blockgc_timer;/* Interval between blockgc scans */ } xfs_param_t;/*
Re: [PATCH 07/10] xfs: consolidate the eofblocks and cowblocks workers
Looks good,
PATCH v3 8/10 xfs: only walk the incore inode tree once per blockgc scan
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Perform background block preallocation gc scans more efficiently by walking the incore inode tree once.
--- fs/xfs/xfs_icache.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
fs/xfs/xfs_icache.c +11 -11
@@ -1571,21 +1571,19 @@ xfs_start_block_reaping(xfs_blockgc_queue (mp); } -/* Scan all incore inodes for block preallocations that we can remove. */ -static inline int -xfs_blockgc_scan ( -struct xfs_mount *mp, -struct xfs_eofblocks *eofb) +/* Scan one incore inode for block preallocations that we can remove. */ +static int +xfs_blockgc_scan_inode ( +struct xfs_inode *ip, +void *args) {int error; - error =xfs_inode_walk (mp,0 , xfs_inode_free_eofblocks, eofb, -XFS_ICI_BLOCKGC_TAG ); + error =xfs_inode_free_eofblocks (ip, args);if (error)return error; - error =xfs_inode_walk (mp,0 , xfs_inode_free_cowblocks, eofb, -XFS_ICI_BLOCKGC_TAG ); + error =xfs_inode_free_cowblocks (ip, args);if (error)return error;
@@ -1603,7 +1601,8 @@ xfs_blockgc_worker(if (!sb_start_write_trylock (mp->m_super))return ; - error =xfs_blockgc_scan (mp,NULL ); + error =xfs_inode_walk (mp,0 , xfs_blockgc_scan_inode,NULL , +XFS_ICI_BLOCKGC_TAG );if (error)xfs_info (mp,"preallocation gc worker failed, err=%d" , error);sb_end_write (mp->m_super);
@@ -1620,7 +1619,8 @@ xfs_blockgc_free_space( {trace_xfs_blockgc_free_space (mp, eofb, _RET_IP_); -return xfs_blockgc_scan (mp, eofb); +return xfs_inode_walk (mp,0 , xfs_blockgc_scan_inode, eofb, +XFS_ICI_BLOCKGC_TAG ); }/*
PATCH v3 9/10 xfs: rename block gc start and stop functions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Shorten the names of the two functions that start and stop block preallocation garbage collection and move them up to the other blockgc functions.
--- fs/xfs/scrub/common.c | 4 ++-- fs/xfs/xfs_icache.c | 4 ++-- fs/xfs/xfs_icache.h | 4 ++-- fs/xfs/xfs_mount.c | 2 +- fs/xfs/xfs_super.c | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-)
fs/xfs/scrub/common.c +2 -2
@@ -888,7 +888,7 @@ xchk_stop_reaping( struct xfs_scrub *sc) { sc->flags |=XCHK_REAPING_DISABLED ; -xfs_stop_block_reaping (sc->mp); +xfs_blockgc_stop (sc->mp); }/* Restart background reaping of resources. */
@@ -896,6 +896,6 @@ voidxchk_start_reaping ( struct xfs_scrub *sc) { -xfs_start_block_reaping (sc->mp); +xfs_blockgc_start (sc->mp); sc->flags &= ~XCHK_REAPING_DISABLED ; }
fs/xfs/xfs_icache.c +2 -2
@@ -1557,7 +1557,7 @@ xfs_inode_clear_cowblocks_tag(/* Disable post-EOF and CoW block auto-reclamation. */ void -xfs_stop_block_reaping ( +xfs_blockgc_stop (struct xfs_mount *mp) {cancel_delayed_work_sync (&mp->m_blockgc_work);
@@ -1565,7 +1565,7 @@ xfs_stop_block_reaping(/* Enable post-EOF and CoW block auto-reclamation. */ void -xfs_start_block_reaping ( +xfs_blockgc_start (struct xfs_mount *mp) {xfs_blockgc_queue (mp);
fs/xfs/xfs_icache.h +2 -2
@@ -76,7 +76,7 @@ int xfs_inode_walk(struct xfs_mount *mp, int iter_flags,int xfs_icache_inode_is_allocated (struct xfs_mount *mp,struct xfs_trans *tp,xfs_ino_t ino,bool *inuse); -void xfs_stop_block_reaping (struct xfs_mount *mp); -void xfs_start_block_reaping (struct xfs_mount *mp); +void xfs_blockgc_stop (struct xfs_mount *mp); +void xfs_blockgc_start (struct xfs_mount *mp);#endif
fs/xfs/xfs_mount.c +1 -1
@@ -1054,7 +1054,7 @@ xfs_unmountfs(uint64_t resblks;int error; -xfs_stop_block_reaping (mp); +xfs_blockgc_stop (mp);xfs_fs_unreserve_ag_blocks (mp);xfs_qm_unmount_quotas (mp);xfs_rtunmount_inodes (mp);
fs/xfs/xfs_super.c +4 -4
@@ -920,7 +920,7 @@ xfs_fs_freeze(* set a GFP_NOFS context here to avoid recursion deadlocks. */ flags =memalloc_nofs_save (); -xfs_stop_block_reaping (mp); +xfs_blockgc_stop (mp);xfs_save_resvblks (mp);xfs_quiesce_attr (mp); ret =xfs_sync_sb (mp, true);
@@ -936,7 +936,7 @@ xfs_fs_unfreeze(xfs_restore_resvblks (mp);xfs_log_work_queue (mp); -xfs_start_block_reaping (mp); +xfs_blockgc_start (mp);return 0 ; }
@@ -1720,7 +1720,7 @@ xfs_remount_rw(xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE );return error; } -xfs_start_block_reaping (mp); +xfs_blockgc_start (mp);/* Create the per-AG metadata reservation pool .*/ error =xfs_fs_reserve_ag_blocks (mp);
@@ -1740,7 +1740,7 @@ xfs_remount_ro(* Cancel background eofb scanning so it cannot race with the final * log force+buftarg wait and deadlock the remount. */ -xfs_stop_block_reaping (mp); +xfs_blockgc_stop (mp);/* Get rid of any leftover CoW reservations... */ error =xfs_blockgc_free_space (mp,NULL );
PATCH v3 10/10 xfs: parallelize block preallocation garbage collection
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Split the block preallocation garbage collection work into per-AG work items so that we can take advantage of parallelization.
Note that sysadmins /can/ tweak the max concurrency level of the blockgc workqueue via /sys/bus/workqueue/devices/xfs-conv!${device}/max_active.
--- fs/xfs/xfs_icache.c | 42 ++++++++++++++++++++++++++++++------------ fs/xfs/xfs_mount.c | 3 +++ fs/xfs/xfs_mount.h | 5 +++-- fs/xfs/xfs_super.c | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 16 deletions(-)
fs/xfs/xfs_icache.c +30 -12
@@ -1333,12 +1333,12 @@ xfs_inode_free_eofblocks(*/ static inline void xfs_blockgc_queue ( -struct xfs_mount *mp) +struct xfs_perag *pag) {rcu_read_lock (); -if (radix_tree_tagged (&mp->m_perag_tree,XFS_ICI_BLOCKGC_TAG )) -queue_delayed_work (mp->m_blockgc_workqueue, - &mp->m_blockgc_work, +if (radix_tree_tagged (&pag->pag_ici_root,XFS_ICI_BLOCKGC_TAG )) +queue_delayed_work (pag->pag_mount->m_blockgc_workqueue, + &pag->pag_blockgc_work,msecs_to_jiffies (xfs_blockgc_secs *1000 ));rcu_read_unlock (); }
@@ -1380,7 +1380,7 @@ xfs_blockgc_set_iflag(spin_unlock (&ip->i_mount->m_perag_lock);/* kick off background trimming */ -xfs_blockgc_queue (ip->i_mount); +xfs_blockgc_queue (pag);trace_xfs_perag_set_blockgc (ip->i_mount, pag->pag_agno,-1 , _RET_IP_);
@@ -1555,12 +1555,24 @@ xfs_inode_clear_cowblocks_tag(return xfs_blockgc_clear_iflag (ip,XFS_ICOWBLOCKS ); } +#define for_each_perag_tag (mp, next_agno, pag, tag) \ + for ((next_agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \ + (pag) != NULL; \ + (next_agno) = (pag)->pag_agno + 1, \ + xfs_perag_put(pag), \ + (pag) = xfs_perag_get_tag((mp), (next_agno), (tag))) + +/* Disable post-EOF and CoW block auto-reclamation. */ void xfs_blockgc_stop (struct xfs_mount *mp) { -cancel_delayed_work_sync (&mp->m_blockgc_work); +struct xfs_perag *pag; +xfs_agnumber_t agno; + +for_each_perag_tag (mp, agno, pag,XFS_ICI_BLOCKGC_TAG ) +cancel_delayed_work_sync (&pag->pag_blockgc_work); }/* Enable post-EOF and CoW block auto-reclamation. */
@@ -1568,7 +1580,11 @@ voidxfs_blockgc_start ( struct xfs_mount *mp) { -xfs_blockgc_queue (mp); +struct xfs_perag *pag; +xfs_agnumber_t agno; + +for_each_perag_tag (mp, agno, pag,XFS_ICI_BLOCKGC_TAG ) +xfs_blockgc_queue (pag); }/* Scan one incore inode for block preallocations that we can remove. */
@@ -1595,18 +1611,20 @@ voidxfs_blockgc_worker ( struct work_struct *work) { -struct xfs_mount *mp =container_of (to_delayed_work (work), - struct xfs_mount, m_blockgc_work); +struct xfs_perag *pag =container_of (to_delayed_work (work), + struct xfs_perag, pag_blockgc_work); +struct xfs_mount *mp = pag->pag_mount;int error;if (!sb_start_write_trylock (mp->m_super))return ; - error =xfs_inode_walk (mp,0 , xfs_blockgc_scan_inode,NULL , + error =xfs_inode_walk_ag (pag,0 , xfs_blockgc_scan_inode,NULL ,XFS_ICI_BLOCKGC_TAG );if (error) -xfs_info (mp,"preallocation gc worker failed, err=%d" , error); +xfs_info (mp,"AG %u preallocation gc worker failed, err=%d" , + pag->pag_agno, error);sb_end_write (mp->m_super); -xfs_blockgc_queue (mp); +xfs_blockgc_queue (pag); }/*
fs/xfs/xfs_mount.c +3 -0
@@ -126,6 +126,7 @@ __xfs_free_perag( { struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head); +ASSERT (!delayed_work_pending (&pag->pag_blockgc_work));ASSERT (atomic_read (&pag->pag_ref) ==0 );kmem_free (pag); }
@@ -146,6 +147,7 @@ xfs_free_perag(spin_unlock (&mp->m_perag_lock);ASSERT (pag);ASSERT (atomic_read (&pag->pag_ref) ==0 ); +cancel_delayed_work_sync (&pag->pag_blockgc_work);xfs_iunlink_destroy (pag);xfs_buf_hash_destroy (pag);call_rcu (&pag->rcu_head, __xfs_free_perag);
@@ -201,6 +203,7 @@ xfs_initialize_perag( pag->pag_agno = index; pag->pag_mount = mp;spin_lock_init (&pag->pag_ici_lock); +INIT_DELAYED_WORK (&pag->pag_blockgc_work, xfs_blockgc_worker);INIT_RADIX_TREE (&pag->pag_ici_root,GFP_ATOMIC ); error =xfs_buf_hash_init (pag);
fs/xfs/xfs_mount.h +3 -2
@@ -177,8 +177,6 @@ typedef struct xfs_mount {uint64_t m_resblks_avail;/* available reserved blocks */ uint64_t m_resblks_save;/* reserved blks @ remount,ro */ struct delayed_work m_reclaim_work;/* background inode reclaim */ -struct delayed_work m_blockgc_work;/* background prealloc blocks -trimming */ struct xfs_kobj m_kobj;struct xfs_kobj m_error_kobj;struct xfs_kobj m_error_meta_kobj;
@@ -367,6 +365,9 @@ typedef struct xfs_perag {/* Blocks reserved for the reverse mapping btree. */ struct xfs_ag_resv pag_rmapbt_resv; +/* background prealloc block trimming */ +struct delayed_work pag_blockgc_work; +/* reference count */ uint8_t pagf_refcount_level;
fs/xfs/xfs_super.c +30 -2
@@ -35,6 +35,7 @@#include "xfs_refcount_item.h" #include "xfs_bmap_item.h" #include "xfs_reflink.h" +#include "xfs_pwork.h" #include <linux/magic.h> #include <linux/fs_context.h>
@@ -516,7 +517,8 @@ xfs_init_mount_workqueues( goto out_destroy_cil; mp->m_blockgc_workqueue =alloc_workqueue ("xfs-blockgc/%s" , -WQ_MEM_RECLAIM |WQ_FREEZABLE ,0 , mp->m_super->s_id); +WQ_UNBOUND |WQ_MEM_RECLAIM |WQ_FREEZABLE |WQ_SYSFS , +0 , mp->m_super->s_id);if (!mp->m_blockgc_workqueue) goto out_destroy_reclaim;
@@ -1387,6 +1389,31 @@ xfs_fs_validate_params(return 0 ; } +/* +* Constrain the number of threads that we start for background work. This +* is the estimated parallelism of the filesystem capped to the unbound work +* queue maximum. +* +* We can't set this when we allocate the workqueues because the thread count +* derives from AG count, and we can't know that until we're far enough through +* setup to read the superblock, which requires functioning workqueues. +*/ +static inline void +xfs_configure_background_workqueues ( +struct xfs_mount *mp) +{ +unsigned int threads =xfs_pwork_guess_metadata_threads (mp); +unsigned int max_active; + +/* +* Background garbage collection of speculative preallocations are done +* per-AG, so don't allow more threads than the AG count, the number of +* CPUs, and the estimated parallelism of the storage device. +*/ + max_active = min_t(unsigned int, threads, WQ_UNBOUND_MAX_ACTIVE); +workqueue_set_max_active (mp->m_blockgc_workqueue, max_active); +} + static int xfs_fs_fill_super( struct super_block *sb,
@@ -1452,6 +1479,8 @@ xfs_fs_fill_super(if (error) goto out_free_sb; +xfs_configure_background_workqueues (mp); + error =xfs_setup_devices (mp);if (error) goto out_free_sb;
@@ -1872,7 +1901,6 @@ static int xfs_init_fs_context(mutex_init (&mp->m_growlock);INIT_WORK (&mp->m_flush_inodes_work, xfs_flush_inodes_worker);INIT_DELAYED_WORK (&mp->m_reclaim_work, xfs_reclaim_worker); -INIT_DELAYED_WORK (&mp->m_blockgc_work, xfs_blockgc_worker); mp->m_kobj.kobject.kset = xfs_kset;/* * We don't create the finobt per-ag space reservation until after log