Skip to content

Commit 34cf3a6

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: move draining of deferred operations to the generic group structure
Prepare supporting the upcoming realtime groups feature by moving the deferred operation draining to the generic xfs_group structure. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 2ed27a5 commit 34cf3a6

File tree

8 files changed

+66
-55
lines changed

8 files changed

+66
-55
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ xfs_perag_uninit(
112112
#ifdef __KERNEL__
113113
struct xfs_perag *pag = to_perag(xg);
114114

115-
xfs_defer_drain_free(&pag->pag_intents_drain);
116115
cancel_delayed_work_sync(&pag->pag_blockgc_work);
117116
xfs_buf_cache_destroy(&pag->pag_bcache);
118117
#endif
@@ -234,15 +233,14 @@ xfs_perag_alloc(
234233
spin_lock_init(&pag->pagb_lock);
235234
INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker);
236235
INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC);
237-
xfs_defer_drain_init(&pag->pag_intents_drain);
238236
init_waitqueue_head(&pag->pagb_wait);
239237
pag->pagb_tree = RB_ROOT;
240238
xfs_hooks_init(&pag->pag_rmap_update_hooks);
241239
#endif /* __KERNEL__ */
242240

243241
error = xfs_buf_cache_init(&pag->pag_bcache);
244242
if (error)
245-
goto out_defer_drain_free;
243+
goto out_free_perag;
246244

247245
/*
248246
* Pre-calculated geometry
@@ -260,8 +258,7 @@ xfs_perag_alloc(
260258

261259
out_buf_cache_destroy:
262260
xfs_buf_cache_destroy(&pag->pag_bcache);
263-
out_defer_drain_free:
264-
xfs_defer_drain_free(&pag->pag_intents_drain);
261+
out_free_perag:
265262
kfree(pag);
266263
return error;
267264
}

fs/xfs/libxfs/xfs_ag.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ struct xfs_perag {
9797
/* background prealloc block trimming */
9898
struct delayed_work pag_blockgc_work;
9999

100-
/*
101-
* We use xfs_drain to track the number of deferred log intent items
102-
* that have been queued (but not yet processed) so that waiters (e.g.
103-
* scrub) will not lock resources when other threads are in the middle
104-
* of processing a chain of intent items only to find momentary
105-
* inconsistencies.
106-
*/
107-
struct xfs_defer_drain pag_intents_drain;
108-
109100
/* Hook to feed rmapbt updates to an active online repair. */
110101
struct xfs_hooks pag_rmap_update_hooks;
111102
#endif /* __KERNEL__ */

fs/xfs/libxfs/xfs_group.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ xfs_group_free(
160160

161161
XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_ref) != 0);
162162

163+
xfs_defer_drain_free(&xg->xg_intents_drain);
164+
163165
if (uninit)
164166
uninit(xg);
165167

@@ -185,13 +187,15 @@ xfs_group_insert(
185187
#ifdef __KERNEL__
186188
spin_lock_init(&xg->xg_state_lock);
187189
#endif
190+
xfs_defer_drain_init(&xg->xg_intents_drain);
188191

189192
/* Active ref owned by mount indicates group is online. */
190193
atomic_set(&xg->xg_active_ref, 1);
191194

192195
error = xa_insert(&mp->m_groups[type].xa, index, xg, GFP_KERNEL);
193196
if (error) {
194197
WARN_ON_ONCE(error == -EBUSY);
198+
xfs_defer_drain_free(&xg->xg_intents_drain);
195199
return error;
196200
}
197201

fs/xfs/libxfs/xfs_group.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ struct xfs_group {
2222
uint16_t xg_checked;
2323
uint16_t xg_sick;
2424
spinlock_t xg_state_lock;
25+
26+
/*
27+
* We use xfs_drain to track the number of deferred log intent items
28+
* that have been queued (but not yet processed) so that waiters (e.g.
29+
* scrub) will not lock resources when other threads are in the middle
30+
* of processing a chain of intent items only to find momentary
31+
* inconsistencies.
32+
*/
33+
struct xfs_defer_drain xg_intents_drain;
2534
#endif /* __KERNEL__ */
2635
};
2736

fs/xfs/scrub/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ xchk_perag_drain_and_lock(
513513
* Obviously, this should be slanted against scrub and in favor
514514
* of runtime threads.
515515
*/
516-
if (!xfs_perag_intent_busy(sa->pag))
516+
if (!xfs_group_intent_busy(pag_group(sa->pag)))
517517
return 0;
518518

519519
if (sa->agf_bp) {
@@ -528,7 +528,7 @@ xchk_perag_drain_and_lock(
528528

529529
if (!(sc->flags & XCHK_FSGATES_DRAIN))
530530
return -ECHRNG;
531-
error = xfs_perag_intent_drain(sa->pag);
531+
error = xfs_group_intent_drain(pag_group(sa->pag));
532532
if (error == -ERESTARTSYS)
533533
error = -EINTR;
534534
} while (!error);

fs/xfs/xfs_drain.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,26 @@ static inline int xfs_defer_drain_wait(struct xfs_defer_drain *dr)
9494
}
9595

9696
/*
97-
* Declare an intent to update AG metadata. Other threads that need exclusive
98-
* access can decide to back off if they see declared intentions.
97+
* Declare an intent to update group metadata. Other threads that need
98+
* exclusive access can decide to back off if they see declared intentions.
9999
*/
100100
static void
101-
xfs_perag_intent_hold(
102-
struct xfs_perag *pag)
101+
xfs_group_intent_hold(
102+
struct xfs_group *xg)
103103
{
104-
trace_xfs_perag_intent_hold(pag, __return_address);
105-
xfs_defer_drain_grab(&pag->pag_intents_drain);
104+
trace_xfs_group_intent_hold(xg, __return_address);
105+
xfs_defer_drain_grab(&xg->xg_intents_drain);
106106
}
107107

108-
/* Release our intent to update this AG's metadata. */
108+
/*
109+
* Release our intent to update this groups metadata.
110+
*/
109111
static void
110-
xfs_perag_intent_rele(
111-
struct xfs_perag *pag)
112+
xfs_group_intent_rele(
113+
struct xfs_group *xg)
112114
{
113-
trace_xfs_perag_intent_rele(pag, __return_address);
114-
xfs_defer_drain_rele(&pag->pag_intents_drain);
115+
trace_xfs_group_intent_rele(xg, __return_address);
116+
xfs_defer_drain_rele(&xg->xg_intents_drain);
115117
}
116118

117119
/*
@@ -129,7 +131,7 @@ xfs_perag_intent_get(
129131
if (!pag)
130132
return NULL;
131133

132-
xfs_perag_intent_hold(pag);
134+
xfs_group_intent_hold(pag_group(pag));
133135
return pag;
134136
}
135137

@@ -141,7 +143,7 @@ void
141143
xfs_perag_intent_put(
142144
struct xfs_perag *pag)
143145
{
144-
xfs_perag_intent_rele(pag);
146+
xfs_group_intent_rele(pag_group(pag));
145147
xfs_perag_put(pag);
146148
}
147149

@@ -150,17 +152,19 @@ xfs_perag_intent_put(
150152
* Callers must not hold any AG header buffers.
151153
*/
152154
int
153-
xfs_perag_intent_drain(
154-
struct xfs_perag *pag)
155+
xfs_group_intent_drain(
156+
struct xfs_group *xg)
155157
{
156-
trace_xfs_perag_wait_intents(pag, __return_address);
157-
return xfs_defer_drain_wait(&pag->pag_intents_drain);
158+
trace_xfs_group_wait_intents(xg, __return_address);
159+
return xfs_defer_drain_wait(&xg->xg_intents_drain);
158160
}
159161

160-
/* Has anyone declared an intent to update this AG? */
162+
/*
163+
* Has anyone declared an intent to update this group?
164+
*/
161165
bool
162-
xfs_perag_intent_busy(
163-
struct xfs_perag *pag)
166+
xfs_group_intent_busy(
167+
struct xfs_group *xg)
164168
{
165-
return xfs_defer_drain_busy(&pag->pag_intents_drain);
169+
return xfs_defer_drain_busy(&xg->xg_intents_drain);
166170
}

fs/xfs/xfs_drain.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef XFS_DRAIN_H_
77
#define XFS_DRAIN_H_
88

9+
struct xfs_group;
910
struct xfs_perag;
1011

1112
#ifdef CONFIG_XFS_DRAIN_INTENTS
@@ -65,8 +66,9 @@ struct xfs_perag *xfs_perag_intent_get(struct xfs_mount *mp,
6566
xfs_fsblock_t fsbno);
6667
void xfs_perag_intent_put(struct xfs_perag *pag);
6768

68-
int xfs_perag_intent_drain(struct xfs_perag *pag);
69-
bool xfs_perag_intent_busy(struct xfs_perag *pag);
69+
int xfs_group_intent_drain(struct xfs_group *xg);
70+
bool xfs_group_intent_busy(struct xfs_group *xg);
71+
7072
#else
7173
struct xfs_defer_drain { /* empty */ };
7274

fs/xfs/xfs_trace.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,35 +4684,39 @@ TRACE_EVENT(xfs_force_shutdown,
46844684
);
46854685

46864686
#ifdef CONFIG_XFS_DRAIN_INTENTS
4687-
DECLARE_EVENT_CLASS(xfs_perag_intents_class,
4688-
TP_PROTO(const struct xfs_perag *pag, void *caller_ip),
4689-
TP_ARGS(pag, caller_ip),
4687+
DECLARE_EVENT_CLASS(xfs_group_intents_class,
4688+
TP_PROTO(const struct xfs_group *xg, void *caller_ip),
4689+
TP_ARGS(xg, caller_ip),
46904690
TP_STRUCT__entry(
46914691
__field(dev_t, dev)
4692-
__field(xfs_agnumber_t, agno)
4692+
__field(enum xfs_group_type, type)
4693+
__field(uint32_t, index)
46934694
__field(long, nr_intents)
46944695
__field(void *, caller_ip)
46954696
),
46964697
TP_fast_assign(
4697-
__entry->dev = pag_mount(pag)->m_super->s_dev;
4698-
__entry->agno = pag_agno(pag);
4699-
__entry->nr_intents = atomic_read(&pag->pag_intents_drain.dr_count);
4698+
__entry->dev = xg->xg_mount->m_super->s_dev;
4699+
__entry->type = xg->xg_type;
4700+
__entry->index = xg->xg_gno;
4701+
__entry->nr_intents =
4702+
atomic_read(&xg->xg_intents_drain.dr_count);
47004703
__entry->caller_ip = caller_ip;
47014704
),
4702-
TP_printk("dev %d:%d agno 0x%x intents %ld caller %pS",
4705+
TP_printk("dev %d:%d %sno 0x%x intents %ld caller %pS",
47034706
MAJOR(__entry->dev), MINOR(__entry->dev),
4704-
__entry->agno,
4707+
__print_symbolic(__entry->type, XG_TYPE_STRINGS),
4708+
__entry->index,
47054709
__entry->nr_intents,
47064710
__entry->caller_ip)
47074711
);
47084712

4709-
#define DEFINE_PERAG_INTENTS_EVENT(name) \
4710-
DEFINE_EVENT(xfs_perag_intents_class, name, \
4711-
TP_PROTO(const struct xfs_perag *pag, void *caller_ip), \
4712-
TP_ARGS(pag, caller_ip))
4713-
DEFINE_PERAG_INTENTS_EVENT(xfs_perag_intent_hold);
4714-
DEFINE_PERAG_INTENTS_EVENT(xfs_perag_intent_rele);
4715-
DEFINE_PERAG_INTENTS_EVENT(xfs_perag_wait_intents);
4713+
#define DEFINE_GROUP_INTENTS_EVENT(name) \
4714+
DEFINE_EVENT(xfs_group_intents_class, name, \
4715+
TP_PROTO(const struct xfs_group *xg, void *caller_ip), \
4716+
TP_ARGS(xg, caller_ip))
4717+
DEFINE_GROUP_INTENTS_EVENT(xfs_group_intent_hold);
4718+
DEFINE_GROUP_INTENTS_EVENT(xfs_group_intent_rele);
4719+
DEFINE_GROUP_INTENTS_EVENT(xfs_group_wait_intents);
47164720

47174721
#endif /* CONFIG_XFS_DRAIN_INTENTS */
47184722

0 commit comments

Comments
 (0)