Skip to content

Commit 6b6e6e7

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: remove xfs_qm_dqput and optimize dropping dquot references
With the new lockref-based dquot reference counting, there is no need to hold q_qlock for dropping the reference. Make xfs_qm_dqrele the main function to drop dquot references without taking q_qlock and convert all callers of xfs_qm_dqput to unlock q_qlock and call xfs_qm_dqrele instead. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 0c5e80b commit 6b6e6e7

10 files changed

Lines changed: 32 additions & 50 deletions

File tree

fs/xfs/scrub/quota.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ xchk_quota(
330330
xchk_dqiter_init(&cursor, sc, dqtype);
331331
while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
332332
error = xchk_quota_item(&sqi, dq);
333-
xfs_qm_dqput(dq);
333+
mutex_unlock(&dq->q_qlock);
334+
xfs_qm_dqrele(dq);
334335
if (error)
335336
break;
336337
}

fs/xfs/scrub/quota_repair.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ xrep_quota_problems(
513513
xchk_dqiter_init(&cursor, sc, dqtype);
514514
while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
515515
error = xrep_quota_item(&rqi, dq);
516-
xfs_qm_dqput(dq);
516+
mutex_unlock(&dq->q_qlock);
517+
xfs_qm_dqrele(dq);
517518
if (error)
518519
break;
519520
}

fs/xfs/scrub/quotacheck.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ xqcheck_walk_observations(
636636
return error;
637637

638638
error = xqcheck_compare_dquot(xqc, dqtype, dq);
639-
xfs_qm_dqput(dq);
639+
mutex_unlock(&dq->q_qlock);
640+
xfs_qm_dqrele(dq);
640641
if (error)
641642
return error;
642643

@@ -674,7 +675,8 @@ xqcheck_compare_dqtype(
674675
xchk_dqiter_init(&cursor, sc, dqtype);
675676
while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
676677
error = xqcheck_compare_dquot(xqc, dqtype, dq);
677-
xfs_qm_dqput(dq);
678+
mutex_unlock(&dq->q_qlock);
679+
xfs_qm_dqrele(dq);
678680
if (error)
679681
break;
680682
}

fs/xfs/scrub/quotacheck_repair.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ xqcheck_commit_dqtype(
156156
xchk_dqiter_init(&cursor, sc, dqtype);
157157
while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
158158
error = xqcheck_commit_dquot(xqc, dqtype, dq);
159-
xfs_qm_dqput(dq);
159+
mutex_unlock(&dq->q_qlock);
160+
xfs_qm_dqrele(dq);
160161
if (error)
161162
break;
162163
}
@@ -187,7 +188,8 @@ xqcheck_commit_dqtype(
187188
return error;
188189

189190
error = xqcheck_commit_dquot(xqc, dqtype, dq);
190-
xfs_qm_dqput(dq);
191+
mutex_unlock(&dq->q_qlock);
192+
xfs_qm_dqrele(dq);
191193
if (error)
192194
return error;
193195

fs/xfs/xfs_dquot.c

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,62 +1105,35 @@ xfs_qm_dqget_next(
11051105
return 0;
11061106
}
11071107

1108-
xfs_qm_dqput(dqp);
1108+
mutex_unlock(&dqp->q_qlock);
1109+
xfs_qm_dqrele(dqp);
11091110
}
11101111

11111112
return error;
11121113
}
11131114

11141115
/*
1115-
* Release a reference to the dquot (decrement ref-count) and unlock it.
1116-
*
1117-
* If there is a group quota attached to this dquot, carefully release that
1118-
* too without tripping over deadlocks'n'stuff.
1116+
* Release a reference to the dquot.
11191117
*/
11201118
void
1121-
xfs_qm_dqput(
1119+
xfs_qm_dqrele(
11221120
struct xfs_dquot *dqp)
11231121
{
1124-
ASSERT(XFS_DQ_IS_LOCKED(dqp));
1122+
if (!dqp)
1123+
return;
11251124

1126-
trace_xfs_dqput(dqp);
1125+
trace_xfs_dqrele(dqp);
11271126

11281127
if (lockref_put_or_lock(&dqp->q_lockref))
1129-
goto out_unlock;
1130-
1128+
return;
11311129
if (!--dqp->q_lockref.count) {
11321130
struct xfs_quotainfo *qi = dqp->q_mount->m_quotainfo;
1133-
trace_xfs_dqput_free(dqp);
11341131

1132+
trace_xfs_dqrele_free(dqp);
11351133
if (list_lru_add_obj(&qi->qi_lru, &dqp->q_lru))
11361134
XFS_STATS_INC(dqp->q_mount, xs_qm_dquot_unused);
11371135
}
11381136
spin_unlock(&dqp->q_lockref.lock);
1139-
out_unlock:
1140-
mutex_unlock(&dqp->q_qlock);
1141-
}
1142-
1143-
/*
1144-
* Release a dquot. Flush it if dirty, then dqput() it.
1145-
* dquot must not be locked.
1146-
*/
1147-
void
1148-
xfs_qm_dqrele(
1149-
struct xfs_dquot *dqp)
1150-
{
1151-
if (!dqp)
1152-
return;
1153-
1154-
trace_xfs_dqrele(dqp);
1155-
1156-
mutex_lock(&dqp->q_qlock);
1157-
/*
1158-
* We don't care to flush it if the dquot is dirty here.
1159-
* That will create stutters that we want to avoid.
1160-
* Instead we do a delayed write when we try to reclaim
1161-
* a dirty dquot. Also xfs_sync will take part of the burden...
1162-
*/
1163-
xfs_qm_dqput(dqp);
11641137
}
11651138

11661139
/*

fs/xfs/xfs_dquot.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ int xfs_qm_dqget_next(struct xfs_mount *mp, xfs_dqid_t id,
218218
int xfs_qm_dqget_uncached(struct xfs_mount *mp,
219219
xfs_dqid_t id, xfs_dqtype_t type,
220220
struct xfs_dquot **dqpp);
221-
void xfs_qm_dqput(struct xfs_dquot *dqp);
222221

223222
void xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
224223
void xfs_dqlockn(struct xfs_dqtrx *q);

fs/xfs/xfs_qm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,8 @@ xfs_qm_quotacheck_dqadjust(
13461346

13471347
dqp->q_flags |= XFS_DQFLAG_DIRTY;
13481348
out_unlock:
1349-
xfs_qm_dqput(dqp);
1349+
mutex_unlock(&dqp->q_qlock);
1350+
xfs_qm_dqrele(dqp);
13501351
return error;
13511352
}
13521353

@@ -1487,7 +1488,8 @@ xfs_qm_flush_one(
14871488
xfs_buf_delwri_queue(bp, buffer_list);
14881489
xfs_buf_relse(bp);
14891490
out_unlock:
1490-
xfs_qm_dqput(dqp);
1491+
mutex_unlock(&dqp->q_qlock);
1492+
xfs_qm_dqrele(dqp);
14911493
return error;
14921494
}
14931495

fs/xfs/xfs_qm_bhv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ xfs_qm_statvfs(
7474

7575
if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
7676
xfs_fill_statvfs_from_dquot(statp, ip, dqp);
77-
xfs_qm_dqput(dqp);
77+
mutex_unlock(&dqp->q_qlock);
78+
xfs_qm_dqrele(dqp);
7879
}
7980
}
8081

fs/xfs/xfs_qm_syscalls.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ xfs_qm_scall_getquota(
467467
xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst);
468468

469469
out_put:
470-
xfs_qm_dqput(dqp);
470+
mutex_unlock(&dqp->q_qlock);
471+
xfs_qm_dqrele(dqp);
471472
return error;
472473
}
473474

@@ -497,7 +498,8 @@ xfs_qm_scall_getquota_next(
497498
*id = dqp->q_id;
498499

499500
xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst);
501+
mutex_unlock(&dqp->q_qlock);
500502

501-
xfs_qm_dqput(dqp);
503+
xfs_qm_dqrele(dqp);
502504
return error;
503505
}

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,8 @@ DEFINE_DQUOT_EVENT(xfs_dqget_hit);
14091409
DEFINE_DQUOT_EVENT(xfs_dqget_miss);
14101410
DEFINE_DQUOT_EVENT(xfs_dqget_freeing);
14111411
DEFINE_DQUOT_EVENT(xfs_dqget_dup);
1412-
DEFINE_DQUOT_EVENT(xfs_dqput);
1413-
DEFINE_DQUOT_EVENT(xfs_dqput_free);
14141412
DEFINE_DQUOT_EVENT(xfs_dqrele);
1413+
DEFINE_DQUOT_EVENT(xfs_dqrele_free);
14151414
DEFINE_DQUOT_EVENT(xfs_dqflush);
14161415
DEFINE_DQUOT_EVENT(xfs_dqflush_force);
14171416
DEFINE_DQUOT_EVENT(xfs_dqflush_done);

0 commit comments

Comments
 (0)