Skip to content

Commit 9669f51

Browse files
author
Darrick J. Wong
committed
xfs: consolidate the eofblocks and cowblocks workers
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_*. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent ce2d3bb commit 9669f51

File tree

8 files changed

+48
-99
lines changed

8 files changed

+48
-99
lines changed

fs/xfs/xfs_globals.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
/*
99
* Tunable XFS parameters. xfs_params is required even when CONFIG_SYSCTL=n,
1010
* other XFS code uses these values. Times are measured in centisecs (i.e.
11-
* 100ths of a second) with the exception of eofb_timer and cowb_timer, which
12-
* are measured in seconds.
11+
* 100ths of a second) with the exception of blockgc_timer, which is measured
12+
* in seconds.
1313
*/
1414
xfs_param_t xfs_params = {
1515
/* MIN DFLT MAX */
@@ -28,8 +28,7 @@ xfs_param_t xfs_params = {
2828
.rotorstep = { 1, 1, 255 },
2929
.inherit_nodfrg = { 0, 1, 1 },
3030
.fstrm_timer = { 1, 30*100, 3600*100},
31-
.eofb_timer = { 1, 300, 3600*24},
32-
.cowb_timer = { 1, 1800, 3600*24},
31+
.blockgc_timer = { 1, 300, 3600*24},
3332
};
3433

3534
struct xfs_globals xfs_globals = {

fs/xfs/xfs_icache.c

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,41 +1328,24 @@ xfs_inode_free_eofblocks(
13281328
}
13291329

13301330
/*
1331-
* Background scanning to trim post-EOF preallocated space. This is queued
1332-
* based on the 'speculative_prealloc_lifetime' tunable (5m by default).
1331+
* Background scanning to trim preallocated space. This is queued based on the
1332+
* 'speculative_prealloc_lifetime' tunable (5m by default).
13331333
*/
1334-
void
1335-
xfs_queue_eofblocks(
1336-
struct xfs_mount *mp)
1334+
static inline void
1335+
xfs_blockgc_queue(
1336+
struct xfs_mount *mp)
13371337
{
13381338
rcu_read_lock();
13391339
if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_BLOCKGC_TAG))
1340-
queue_delayed_work(mp->m_eofblocks_workqueue,
1341-
&mp->m_eofblocks_work,
1342-
msecs_to_jiffies(xfs_eofb_secs * 1000));
1340+
queue_delayed_work(mp->m_blockgc_workqueue,
1341+
&mp->m_blockgc_work,
1342+
msecs_to_jiffies(xfs_blockgc_secs * 1000));
13431343
rcu_read_unlock();
13441344
}
13451345

1346-
void
1347-
xfs_eofblocks_worker(
1348-
struct work_struct *work)
1349-
{
1350-
struct xfs_mount *mp = container_of(to_delayed_work(work),
1351-
struct xfs_mount, m_eofblocks_work);
1352-
1353-
if (!sb_start_write_trylock(mp->m_super))
1354-
return;
1355-
xfs_inode_walk(mp, 0, xfs_inode_free_eofblocks, NULL,
1356-
XFS_ICI_BLOCKGC_TAG);
1357-
sb_end_write(mp->m_super);
1358-
1359-
xfs_queue_eofblocks(mp);
1360-
}
1361-
13621346
static void
13631347
xfs_blockgc_set_iflag(
13641348
struct xfs_inode *ip,
1365-
void (*execute)(struct xfs_mount *mp),
13661349
unsigned long iflag)
13671350
{
13681351
struct xfs_mount *mp = ip->i_mount;
@@ -1397,7 +1380,7 @@ xfs_blockgc_set_iflag(
13971380
spin_unlock(&ip->i_mount->m_perag_lock);
13981381

13991382
/* kick off background trimming */
1400-
execute(ip->i_mount);
1383+
xfs_blockgc_queue(ip->i_mount);
14011384

14021385
trace_xfs_perag_set_blockgc(ip->i_mount, pag->pag_agno, -1,
14031386
_RET_IP_);
@@ -1412,7 +1395,7 @@ xfs_inode_set_eofblocks_tag(
14121395
xfs_inode_t *ip)
14131396
{
14141397
trace_xfs_inode_set_eofblocks_tag(ip);
1415-
return xfs_blockgc_set_iflag(ip, xfs_queue_eofblocks, XFS_IEOFBLOCKS);
1398+
return xfs_blockgc_set_iflag(ip, XFS_IEOFBLOCKS);
14161399
}
14171400

14181401
static void
@@ -1556,45 +1539,12 @@ xfs_inode_free_cowblocks(
15561539
return ret;
15571540
}
15581541

1559-
/*
1560-
* Background scanning to trim preallocated CoW space. This is queued
1561-
* based on the 'speculative_cow_prealloc_lifetime' tunable (5m by default).
1562-
* (We'll just piggyback on the post-EOF prealloc space workqueue.)
1563-
*/
1564-
void
1565-
xfs_queue_cowblocks(
1566-
struct xfs_mount *mp)
1567-
{
1568-
rcu_read_lock();
1569-
if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_BLOCKGC_TAG))
1570-
queue_delayed_work(mp->m_eofblocks_workqueue,
1571-
&mp->m_cowblocks_work,
1572-
msecs_to_jiffies(xfs_cowb_secs * 1000));
1573-
rcu_read_unlock();
1574-
}
1575-
1576-
void
1577-
xfs_cowblocks_worker(
1578-
struct work_struct *work)
1579-
{
1580-
struct xfs_mount *mp = container_of(to_delayed_work(work),
1581-
struct xfs_mount, m_cowblocks_work);
1582-
1583-
if (!sb_start_write_trylock(mp->m_super))
1584-
return;
1585-
xfs_inode_walk(mp, 0, xfs_inode_free_cowblocks, NULL,
1586-
XFS_ICI_BLOCKGC_TAG);
1587-
sb_end_write(mp->m_super);
1588-
1589-
xfs_queue_cowblocks(mp);
1590-
}
1591-
15921542
void
15931543
xfs_inode_set_cowblocks_tag(
15941544
xfs_inode_t *ip)
15951545
{
15961546
trace_xfs_inode_set_cowblocks_tag(ip);
1597-
return xfs_blockgc_set_iflag(ip, xfs_queue_cowblocks, XFS_ICOWBLOCKS);
1547+
return xfs_blockgc_set_iflag(ip, XFS_ICOWBLOCKS);
15981548
}
15991549

16001550
void
@@ -1610,17 +1560,15 @@ void
16101560
xfs_stop_block_reaping(
16111561
struct xfs_mount *mp)
16121562
{
1613-
cancel_delayed_work_sync(&mp->m_eofblocks_work);
1614-
cancel_delayed_work_sync(&mp->m_cowblocks_work);
1563+
cancel_delayed_work_sync(&mp->m_blockgc_work);
16151564
}
16161565

16171566
/* Enable post-EOF and CoW block auto-reclamation. */
16181567
void
16191568
xfs_start_block_reaping(
16201569
struct xfs_mount *mp)
16211570
{
1622-
xfs_queue_eofblocks(mp);
1623-
xfs_queue_cowblocks(mp);
1571+
xfs_blockgc_queue(mp);
16241572
}
16251573

16261574
/* Scan all incore inodes for block preallocations that we can remove. */
@@ -1644,6 +1592,24 @@ xfs_blockgc_scan(
16441592
return 0;
16451593
}
16461594

1595+
/* Background worker that trims preallocated space. */
1596+
void
1597+
xfs_blockgc_worker(
1598+
struct work_struct *work)
1599+
{
1600+
struct xfs_mount *mp = container_of(to_delayed_work(work),
1601+
struct xfs_mount, m_blockgc_work);
1602+
int error;
1603+
1604+
if (!sb_start_write_trylock(mp->m_super))
1605+
return;
1606+
error = xfs_blockgc_scan(mp, NULL);
1607+
if (error)
1608+
xfs_info(mp, "preallocation gc worker failed, err=%d", error);
1609+
sb_end_write(mp->m_super);
1610+
xfs_blockgc_queue(mp);
1611+
}
1612+
16471613
/*
16481614
* Try to free space in the filesystem by purging eofblocks and cowblocks.
16491615
*/

fs/xfs/xfs_icache.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ int xfs_blockgc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb);
6262

6363
void xfs_inode_set_eofblocks_tag(struct xfs_inode *ip);
6464
void xfs_inode_clear_eofblocks_tag(struct xfs_inode *ip);
65-
void xfs_eofblocks_worker(struct work_struct *);
66-
void xfs_queue_eofblocks(struct xfs_mount *);
6765

6866
void xfs_inode_set_cowblocks_tag(struct xfs_inode *ip);
6967
void xfs_inode_clear_cowblocks_tag(struct xfs_inode *ip);
70-
void xfs_cowblocks_worker(struct work_struct *);
71-
void xfs_queue_cowblocks(struct xfs_mount *);
68+
69+
void xfs_blockgc_worker(struct work_struct *work);
7270

7371
int xfs_inode_walk(struct xfs_mount *mp, int iter_flags,
7472
int (*execute)(struct xfs_inode *ip, void *args),

fs/xfs/xfs_linux.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ typedef __u32 xfs_nlink_t;
9898
#define xfs_rotorstep xfs_params.rotorstep.val
9999
#define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
100100
#define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
101-
#define xfs_eofb_secs xfs_params.eofb_timer.val
102-
#define xfs_cowb_secs xfs_params.cowb_timer.val
101+
#define xfs_blockgc_secs xfs_params.blockgc_timer.val
103102

104103
#define current_cpu() (raw_smp_processor_id())
105104
#define current_set_flags_nested(sp, f) \

fs/xfs/xfs_mount.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct xfs_mount {
9393
struct workqueue_struct *m_unwritten_workqueue;
9494
struct workqueue_struct *m_cil_workqueue;
9595
struct workqueue_struct *m_reclaim_workqueue;
96-
struct workqueue_struct *m_eofblocks_workqueue;
96+
struct workqueue_struct *m_blockgc_workqueue;
9797
struct workqueue_struct *m_sync_workqueue;
9898

9999
int m_bsize; /* fs logical block size */
@@ -177,9 +177,7 @@ typedef struct xfs_mount {
177177
uint64_t m_resblks_avail;/* available reserved blocks */
178178
uint64_t m_resblks_save; /* reserved blks @ remount,ro */
179179
struct delayed_work m_reclaim_work; /* background inode reclaim */
180-
struct delayed_work m_eofblocks_work; /* background eof blocks
181-
trimming */
182-
struct delayed_work m_cowblocks_work; /* background cow blocks
180+
struct delayed_work m_blockgc_work; /* background prealloc blocks
183181
trimming */
184182
struct xfs_kobj m_kobj;
185183
struct xfs_kobj m_error_kobj;

fs/xfs/xfs_super.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,10 @@ xfs_init_mount_workqueues(
518518
if (!mp->m_reclaim_workqueue)
519519
goto out_destroy_cil;
520520

521-
mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
521+
mp->m_blockgc_workqueue = alloc_workqueue("xfs-blockgc/%s",
522522
XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
523523
0, mp->m_super->s_id);
524-
if (!mp->m_eofblocks_workqueue)
524+
if (!mp->m_blockgc_workqueue)
525525
goto out_destroy_reclaim;
526526

527527
mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
@@ -532,7 +532,7 @@ xfs_init_mount_workqueues(
532532
return 0;
533533

534534
out_destroy_eofb:
535-
destroy_workqueue(mp->m_eofblocks_workqueue);
535+
destroy_workqueue(mp->m_blockgc_workqueue);
536536
out_destroy_reclaim:
537537
destroy_workqueue(mp->m_reclaim_workqueue);
538538
out_destroy_cil:
@@ -550,7 +550,7 @@ xfs_destroy_mount_workqueues(
550550
struct xfs_mount *mp)
551551
{
552552
destroy_workqueue(mp->m_sync_workqueue);
553-
destroy_workqueue(mp->m_eofblocks_workqueue);
553+
destroy_workqueue(mp->m_blockgc_workqueue);
554554
destroy_workqueue(mp->m_reclaim_workqueue);
555555
destroy_workqueue(mp->m_cil_workqueue);
556556
destroy_workqueue(mp->m_unwritten_workqueue);
@@ -1842,8 +1842,7 @@ static int xfs_init_fs_context(
18421842
mutex_init(&mp->m_growlock);
18431843
INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
18441844
INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1845-
INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1846-
INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1845+
INIT_DELAYED_WORK(&mp->m_blockgc_work, xfs_blockgc_worker);
18471846
mp->m_kobj.kobject.kset = xfs_kset;
18481847
/*
18491848
* We don't create the finobt per-ag space reservation until after log

fs/xfs/xfs_sysctl.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,12 @@ static struct ctl_table xfs_table[] = {
194194
},
195195
{
196196
.procname = "speculative_prealloc_lifetime",
197-
.data = &xfs_params.eofb_timer.val,
197+
.data = &xfs_params.blockgc_timer.val,
198198
.maxlen = sizeof(int),
199199
.mode = 0644,
200200
.proc_handler = proc_dointvec_minmax,
201-
.extra1 = &xfs_params.eofb_timer.min,
202-
.extra2 = &xfs_params.eofb_timer.max,
203-
},
204-
{
205-
.procname = "speculative_cow_prealloc_lifetime",
206-
.data = &xfs_params.cowb_timer.val,
207-
.maxlen = sizeof(int),
208-
.mode = 0644,
209-
.proc_handler = proc_dointvec_minmax,
210-
.extra1 = &xfs_params.cowb_timer.min,
211-
.extra2 = &xfs_params.cowb_timer.max,
201+
.extra1 = &xfs_params.blockgc_timer.min,
202+
.extra2 = &xfs_params.blockgc_timer.max,
212203
},
213204
/* please keep this the last entry */
214205
#ifdef CONFIG_PROC_FS

fs/xfs/xfs_sysctl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ typedef struct xfs_param {
3535
xfs_sysctl_val_t rotorstep; /* inode32 AG rotoring control knob */
3636
xfs_sysctl_val_t inherit_nodfrg;/* Inherit the "nodefrag" inode flag. */
3737
xfs_sysctl_val_t fstrm_timer; /* Filestream dir-AG assoc'n timeout. */
38-
xfs_sysctl_val_t eofb_timer; /* Interval between eofb scan wakeups */
39-
xfs_sysctl_val_t cowb_timer; /* Interval between cowb scan wakeups */
38+
xfs_sysctl_val_t blockgc_timer; /* Interval between blockgc scans */
4039
} xfs_param_t;
4140

4241
/*

0 commit comments

Comments
 (0)