]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: remove xfs_qm_dqput and optimize dropping dquot references
authorChristoph Hellwig <hch@lst.de>
Mon, 10 Nov 2025 13:22:58 +0000 (14:22 +0100)
committerCarlos Maiolino <cem@kernel.org>
Tue, 11 Nov 2025 10:45:58 +0000 (11:45 +0100)
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>
fs/xfs/scrub/quota.c
fs/xfs/scrub/quota_repair.c
fs/xfs/scrub/quotacheck.c
fs/xfs/scrub/quotacheck_repair.c
fs/xfs/xfs_dquot.c
fs/xfs/xfs_dquot.h
fs/xfs/xfs_qm.c
fs/xfs/xfs_qm_bhv.c
fs/xfs/xfs_qm_syscalls.c
fs/xfs/xfs_trace.h

index c78cf9f96cf6361c55e01f907af1f78697eef9a0..cfcd0fb66845df581ce24856a15f96cc32aa6614 100644 (file)
@@ -330,7 +330,8 @@ xchk_quota(
        xchk_dqiter_init(&cursor, sc, dqtype);
        while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
                error = xchk_quota_item(&sqi, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        break;
        }
index 8c89c6cc2950ab937ae014f32bac3b826c4bd4eb..d4ce9e56d3ef688d2a59db1e0efb66f6c7004a62 100644 (file)
@@ -513,7 +513,8 @@ xrep_quota_problems(
        xchk_dqiter_init(&cursor, sc, dqtype);
        while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
                error = xrep_quota_item(&rqi, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        break;
        }
index e4105aaafe8454d16fe3304631af692ef8ab64f2..180449f654f68f0c0f2a3d5ce32a359ff332efa3 100644 (file)
@@ -636,7 +636,8 @@ xqcheck_walk_observations(
                        return error;
 
                error = xqcheck_compare_dquot(xqc, dqtype, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        return error;
 
@@ -674,7 +675,8 @@ xqcheck_compare_dqtype(
        xchk_dqiter_init(&cursor, sc, dqtype);
        while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
                error = xqcheck_compare_dquot(xqc, dqtype, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        break;
        }
index 415314911499bd63583b2fc884c8f223244d0d95..11153e24b565dc9ceb1e7a23aa02052ccc03a258 100644 (file)
@@ -156,7 +156,8 @@ xqcheck_commit_dqtype(
        xchk_dqiter_init(&cursor, sc, dqtype);
        while ((error = xchk_dquot_iter(&cursor, &dq)) == 1) {
                error = xqcheck_commit_dquot(xqc, dqtype, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        break;
        }
@@ -187,7 +188,8 @@ xqcheck_commit_dqtype(
                        return error;
 
                error = xqcheck_commit_dquot(xqc, dqtype, dq);
-               xfs_qm_dqput(dq);
+               mutex_unlock(&dq->q_qlock);
+               xfs_qm_dqrele(dq);
                if (error)
                        return error;
 
index 34c325524ab9da85572d6f2de6a619029700814d..52c521a1402d7e6ffb863063f64d4710362b339a 100644 (file)
@@ -1105,62 +1105,35 @@ xfs_qm_dqget_next(
                        return 0;
                }
 
-               xfs_qm_dqput(dqp);
+               mutex_unlock(&dqp->q_qlock);
+               xfs_qm_dqrele(dqp);
        }
 
        return error;
 }
 
 /*
- * Release a reference to the dquot (decrement ref-count) and unlock it.
- *
- * If there is a group quota attached to this dquot, carefully release that
- * too without tripping over deadlocks'n'stuff.
+ * Release a reference to the dquot.
  */
 void
-xfs_qm_dqput(
+xfs_qm_dqrele(
        struct xfs_dquot        *dqp)
 {
-       ASSERT(XFS_DQ_IS_LOCKED(dqp));
+       if (!dqp)
+               return;
 
-       trace_xfs_dqput(dqp);
+       trace_xfs_dqrele(dqp);
 
        if (lockref_put_or_lock(&dqp->q_lockref))
-               goto out_unlock;
-
+               return;
        if (!--dqp->q_lockref.count) {
                struct xfs_quotainfo    *qi = dqp->q_mount->m_quotainfo;
-               trace_xfs_dqput_free(dqp);
 
+               trace_xfs_dqrele_free(dqp);
                if (list_lru_add_obj(&qi->qi_lru, &dqp->q_lru))
                        XFS_STATS_INC(dqp->q_mount, xs_qm_dquot_unused);
        }
        spin_unlock(&dqp->q_lockref.lock);
-out_unlock:
-       mutex_unlock(&dqp->q_qlock);
-}
-
-/*
- * Release a dquot. Flush it if dirty, then dqput() it.
- * dquot must not be locked.
- */
-void
-xfs_qm_dqrele(
-       struct xfs_dquot        *dqp)
-{
-       if (!dqp)
-               return;
-
-       trace_xfs_dqrele(dqp);
-
-       mutex_lock(&dqp->q_qlock);
-       /*
-        * We don't care to flush it if the dquot is dirty here.
-        * That will create stutters that we want to avoid.
-        * Instead we do a delayed write when we try to reclaim
-        * a dirty dquot. Also xfs_sync will take part of the burden...
-        */
-       xfs_qm_dqput(dqp);
 }
 
 /*
index c56fbc39d0890bcf96beb87507e1e488e5f4db50..bbb824adca82cef08250c67c45ffdb184e4fcb2e 100644 (file)
@@ -218,7 +218,6 @@ int         xfs_qm_dqget_next(struct xfs_mount *mp, xfs_dqid_t id,
 int            xfs_qm_dqget_uncached(struct xfs_mount *mp,
                                xfs_dqid_t id, xfs_dqtype_t type,
                                struct xfs_dquot **dqpp);
-void           xfs_qm_dqput(struct xfs_dquot *dqp);
 
 void           xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
 void           xfs_dqlockn(struct xfs_dqtrx *q);
index f98f9fdac0b5d007f1e0b64c36fd167df06a578e..5e6aefb17f19a81bcbc7e85a4b0e2e9b79780240 100644 (file)
@@ -1346,7 +1346,8 @@ xfs_qm_quotacheck_dqadjust(
 
        dqp->q_flags |= XFS_DQFLAG_DIRTY;
 out_unlock:
-       xfs_qm_dqput(dqp);
+       mutex_unlock(&dqp->q_qlock);
+       xfs_qm_dqrele(dqp);
        return error;
 }
 
@@ -1487,7 +1488,8 @@ xfs_qm_flush_one(
                xfs_buf_delwri_queue(bp, buffer_list);
        xfs_buf_relse(bp);
 out_unlock:
-       xfs_qm_dqput(dqp);
+       mutex_unlock(&dqp->q_qlock);
+       xfs_qm_dqrele(dqp);
        return error;
 }
 
index 245d754f382a721df0a868d9a59facc59da703e8..e5a30b12253c65e0a49658b6b7da3ef02bf30bb1 100644 (file)
@@ -74,7 +74,8 @@ xfs_qm_statvfs(
 
        if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
                xfs_fill_statvfs_from_dquot(statp, ip, dqp);
-               xfs_qm_dqput(dqp);
+               mutex_unlock(&dqp->q_qlock);
+               xfs_qm_dqrele(dqp);
        }
 }
 
index 59ef382900fe00d2d97cf4857c8931eed3737d33..441f9806cddb1aad0d736e74976e809f97ebd758 100644 (file)
@@ -467,7 +467,8 @@ xfs_qm_scall_getquota(
        xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst);
 
 out_put:
-       xfs_qm_dqput(dqp);
+       mutex_unlock(&dqp->q_qlock);
+       xfs_qm_dqrele(dqp);
        return error;
 }
 
@@ -497,7 +498,8 @@ xfs_qm_scall_getquota_next(
        *id = dqp->q_id;
 
        xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst);
+       mutex_unlock(&dqp->q_qlock);
 
-       xfs_qm_dqput(dqp);
+       xfs_qm_dqrele(dqp);
        return error;
 }
index 46d21eb11ccbf42f76bdaf320bf437f0606c415b..fccc032b3c6ce9e4827e5efbc41bb2d94ee00ea5 100644 (file)
@@ -1409,9 +1409,8 @@ DEFINE_DQUOT_EVENT(xfs_dqget_hit);
 DEFINE_DQUOT_EVENT(xfs_dqget_miss);
 DEFINE_DQUOT_EVENT(xfs_dqget_freeing);
 DEFINE_DQUOT_EVENT(xfs_dqget_dup);
-DEFINE_DQUOT_EVENT(xfs_dqput);
-DEFINE_DQUOT_EVENT(xfs_dqput_free);
 DEFINE_DQUOT_EVENT(xfs_dqrele);
+DEFINE_DQUOT_EVENT(xfs_dqrele_free);
 DEFINE_DQUOT_EVENT(xfs_dqflush);
 DEFINE_DQUOT_EVENT(xfs_dqflush_force);
 DEFINE_DQUOT_EVENT(xfs_dqflush_done);