xfs
[Top] [All Lists]

[PATCH 068/102] xfs: avoid taking the ilock unnessecarily in xfs_qm_dqat

To: xfs@xxxxxxxxxxx
Subject: [PATCH 068/102] xfs: avoid taking the ilock unnessecarily in xfs_qm_dqattach
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Thu, 23 Aug 2012 15:02:26 +1000
In-reply-to: <1345698180-13612-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1345698180-13612-1-git-send-email-david@xxxxxxxxxxxxx>
From: Christoph Hellwig <hch@xxxxxxxxxxxxx>

Upstream commit: b4d05e3019692fc5a8c573fbce60de2d48c5b7a1

Check if we actually need to attach a dquot before taking the ilock in
xfs_qm_dqattach.  This avoid superflous lock roundtrips for the common cases
of quota support compiled in but not activated on a filesystem and an
inode that already has the dquots attached.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
Reviewed-by: Mark Tinguely <tinguely@xxxxxxx>
Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx>
Signed-off-by: Ben Myers <bpm@xxxxxxx>
---
 fs/xfs/quota/xfs_qm.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index eacf7e0..fd8ddac 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -777,6 +777,23 @@ xfs_qm_dqattach_grouphint(
        xfs_dqunlock(udq);
 }
 
+static bool
+xfs_qm_need_dqattach(
+       struct xfs_inode        *ip)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+
+       if (!XFS_IS_QUOTA_RUNNING(mp))
+               return false;
+       if (!XFS_IS_QUOTA_ON(mp))
+               return false;
+       if (!XFS_NOT_DQATTACHED(mp, ip))
+               return false;
+       if (ip->i_ino == mp->m_sb.sb_uquotino ||
+           ip->i_ino == mp->m_sb.sb_gquotino)
+               return false;
+       return true;
+}
 
 /*
  * Given a locked inode, attach dquot(s) to it, taking U/G/P-QUOTAON
@@ -794,11 +811,7 @@ xfs_qm_dqattach_locked(
        uint            nquotas = 0;
        int             error = 0;
 
-       if (!XFS_IS_QUOTA_RUNNING(mp) ||
-           !XFS_IS_QUOTA_ON(mp) ||
-           !XFS_NOT_DQATTACHED(mp, ip) ||
-           ip->i_ino == mp->m_sb.sb_uquotino ||
-           ip->i_ino == mp->m_sb.sb_gquotino)
+       if (!xfs_qm_need_dqattach(ip))
                return 0;
 
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
@@ -873,6 +886,9 @@ xfs_qm_dqattach(
 {
        int                     error;
 
+       if (!xfs_qm_need_dqattach(ip))
+               return 0;
+
        xfs_ilock(ip, XFS_ILOCK_EXCL);
        error = xfs_qm_dqattach_locked(ip, flags);
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
-- 
1.7.10

<Prev in Thread] Current Thread [Next in Thread>