public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Myers <bpm@sgi.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: xfs@oss.sgi.com
Subject: Re: [patch 13/19] xfs: nest qm_dqfrlist_lock inside the dquot qlock
Date: Wed, 14 Dec 2011 21:02:37 -0600	[thread overview]
Message-ID: <20111215030237.GF29840@sgi.com> (raw)
In-Reply-To: <20111206215854.945624913@bombadil.infradead.org>

On Tue, Dec 06, 2011 at 04:58:19PM -0500, Christoph Hellwig wrote:
> Allow xfs_qm_dqput to work without trylock loops by nesting the freelist lock
> inside the dquot qlock.  In turn that requires trylocks in the reclaim path
> instead, but given it's a classic tradeoff between fast and slow path, and
> we follow the model of the inode and dentry caches.
> 
> Document our new lock order now that it has settled.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Dave Chinner <dchinner@redhat.com>

Looks good.
Reviewed-by: Ben Myers <bpm@sgi.com>

> ---
>  fs/xfs/xfs_dquot.c |   99 ++++++++++++++++++++---------------------------------
>  fs/xfs/xfs_qm.c    |    4 +-
>  2 files changed, 42 insertions(+), 61 deletions(-)
> 
> Index: xfs/fs/xfs/xfs_dquot.c
> ===================================================================
> --- xfs.orig/fs/xfs/xfs_dquot.c	2011-12-06 15:46:19.730356139 +0100
> +++ xfs/fs/xfs/xfs_dquot.c	2011-12-06 15:51:23.630361773 +0100
> @@ -39,20 +39,19 @@
>  #include "xfs_qm.h"
>  #include "xfs_trace.h"
>  
> -
>  /*
> -   LOCK ORDER
> -
> -   inode lock		    (ilock)
> -   dquot hash-chain lock    (hashlock)
> -   xqm dquot freelist lock  (freelistlock
> -   mount's dquot list lock  (mplistlock)
> -   user dquot lock - lock ordering among dquots is based on the uid or gid
> -   group dquot lock - similar to udquots. Between the two dquots, the udquot
> -		      has to be locked first.
> -   pin lock - the dquot lock must be held to take this lock.
> -   flush lock - ditto.
> -*/
> + * Lock order:
> + *
> + * ip->i_lock
> + *   qh->qh_lock
> + *     qi->qi_dqlist_lock
> + *       dquot->q_qlock (xfs_dqlock() and friends)
> + *         dquot->q_flush (xfs_dqflock() and friends)
> + *         xfs_Gqm->qm_dqfrlist_lock
> + *
> + * If two dquots need to be locked the order is user before group/project,
> + * otherwise by the lowest id first, see xfs_dqlock2.
> + */
>  
>  #ifdef DEBUG
>  xfs_buftarg_t *xfs_dqerror_target;
> @@ -984,69 +983,49 @@ restart:
>   */
>  void
>  xfs_qm_dqput(
> -	xfs_dquot_t	*dqp)
> +	struct xfs_dquot	*dqp)
>  {
> -	xfs_dquot_t	*gdqp;
> +	struct xfs_dquot	*gdqp;
>  
>  	ASSERT(dqp->q_nrefs > 0);
>  	ASSERT(XFS_DQ_IS_LOCKED(dqp));
>  
>  	trace_xfs_dqput(dqp);
>  
> -	if (dqp->q_nrefs != 1) {
> -		dqp->q_nrefs--;
> +recurse:
> +	if (--dqp->q_nrefs > 0) {
>  		xfs_dqunlock(dqp);
>  		return;
>  	}
>  
> -	/*
> -	 * drop the dqlock and acquire the freelist and dqlock
> -	 * in the right order; but try to get it out-of-order first
> -	 */
> -	if (!mutex_trylock(&xfs_Gqm->qm_dqfrlist_lock)) {
> -		trace_xfs_dqput_wait(dqp);
> -		xfs_dqunlock(dqp);
> -		mutex_lock(&xfs_Gqm->qm_dqfrlist_lock);
> -		xfs_dqlock(dqp);
> -	}
> -
> -	while (1) {
> -		gdqp = NULL;
> +	trace_xfs_dqput_free(dqp);
>  
> -		/* We can't depend on nrefs being == 1 here */
> -		if (--dqp->q_nrefs == 0) {
> -			trace_xfs_dqput_free(dqp);
> -
> -			if (list_empty(&dqp->q_freelist)) {
> -				list_add_tail(&dqp->q_freelist, &xfs_Gqm->qm_dqfrlist);
> -				xfs_Gqm->qm_dqfrlist_cnt++;
> -			}
> +	mutex_lock(&xfs_Gqm->qm_dqfrlist_lock);
> +	if (list_empty(&dqp->q_freelist)) {
> +		list_add_tail(&dqp->q_freelist, &xfs_Gqm->qm_dqfrlist);
> +		xfs_Gqm->qm_dqfrlist_cnt++;
> +	}
> +	mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock);
>  
> -			/*
> -			 * If we just added a udquot to the freelist, then
> -			 * we want to release the gdquot reference that
> -			 * it (probably) has. Otherwise it'll keep the
> -			 * gdquot from getting reclaimed.
> -			 */
> -			if ((gdqp = dqp->q_gdquot)) {
> -				/*
> -				 * Avoid a recursive dqput call
> -				 */
> -				xfs_dqlock(gdqp);
> -				dqp->q_gdquot = NULL;
> -			}
> -		}
> -		xfs_dqunlock(dqp);
> +	/*
> +	 * If we just added a udquot to the freelist, then we want to release
> +	 * the gdquot reference that it (probably) has. Otherwise it'll keep
> +	 * the gdquot from getting reclaimed.
> +	 */
> +	gdqp = dqp->q_gdquot;
> +	if (gdqp) {
> +		xfs_dqlock(gdqp);
> +		dqp->q_gdquot = NULL;
> +	}
> +	xfs_dqunlock(dqp);
>  
> -		/*
> -		 * If we had a group quota inside the user quota as a hint,
> -		 * release it now.
> -		 */
> -		if (! gdqp)
> -			break;
> +	/*
> +	 * If we had a group quota hint, release it now.
> +	 */
> +	if (gdqp) {
>  		dqp = gdqp;
> +		goto recurse;
>  	}
> -	mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock);
>  }
>  
>  /*
> Index: xfs/fs/xfs/xfs_qm.c
> ===================================================================
> --- xfs.orig/fs/xfs/xfs_qm.c	2011-12-06 15:48:38.753692050 +0100
> +++ xfs/fs/xfs/xfs_qm.c	2011-12-06 15:49:31.303693024 +0100
> @@ -1668,7 +1668,9 @@ xfs_qm_dqreclaim_one(void)
>  restart:
>  	list_for_each_entry(dqp, &xfs_Gqm->qm_dqfrlist, q_freelist) {
>  		struct xfs_mount *mp = dqp->q_mount;
> -		xfs_dqlock(dqp);
> +
> +		if (!xfs_dqlock_nowait(dqp))
> +			continue;
>  
>  		/*
>  		 * This dquot has already been grabbed by dqlookup.
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2011-12-15  3:02 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 21:58 [patch 00/19] Linux 3.3 patchqueue Christoph Hellwig
2011-12-06 21:58 ` [patch 01/19] xfs: remove the deprecated nodelaylog option Christoph Hellwig
2011-12-07 21:44   ` Ben Myers
2011-12-08 16:12     ` Christoph Hellwig
2011-12-08 16:14       ` Ben Myers
2011-12-06 21:58 ` [patch 02/19] xfs: cleanup the transaction commit path a bit Christoph Hellwig
2011-12-08 17:44   ` Ben Myers
2011-12-06 21:58 ` [patch 03/19] xfs: remove the lid_size field in struct log_item_desc Christoph Hellwig
2011-12-08 18:35   ` Ben Myers
2011-12-06 21:58 ` [patch 04/19] xfs: untange SYNC_WAIT and SYNC_TRYLOCK meanings for xfs_qm_dqflush Christoph Hellwig
2011-12-08 21:10   ` Ben Myers
2011-12-06 21:58 ` [patch 05/19] xfs: make sure to really flush all dquots in xfs_qm_quotacheck Christoph Hellwig
2011-12-08 21:36   ` Ben Myers
2011-12-06 21:58 ` [patch 06/19] xfs: remove xfs_qm_sync Christoph Hellwig
2011-12-12 18:25   ` Ben Myers
2011-12-06 21:58 ` [patch 07/19] xfs: remove the sync_mode argument to xfs_qm_dqflush_all Christoph Hellwig
2011-12-12 22:33   ` Ben Myers
2011-12-06 21:58 ` [patch 08/19] xfs: cleanup dquot locking helpers Christoph Hellwig
2011-12-12 23:12   ` Ben Myers
2011-12-06 21:58 ` [patch 09/19] xfs: cleanup xfs_qm_dqlookup Christoph Hellwig
2011-12-13 17:30   ` Ben Myers
2011-12-06 21:58 ` [patch 10/19] xfs: remove XFS_DQ_INACTIVE Christoph Hellwig
2011-12-13 20:26   ` Ben Myers
2011-12-06 21:58 ` [patch 11/19] xfs: implement lazy removal for the dquot freelist Christoph Hellwig
2011-12-14 22:13   ` Ben Myers
2011-12-06 21:58 ` [patch 12/19] xfs: flatten the dquot lock ordering Christoph Hellwig
2011-12-13 19:44   ` Dave Chinner
2011-12-14 22:18   ` Ben Myers
2011-12-15  3:13   ` Ben Myers
2011-12-06 21:58 ` [patch 13/19] xfs: nest qm_dqfrlist_lock inside the dquot qlock Christoph Hellwig
2011-12-15  3:02   ` Ben Myers [this message]
2011-12-06 21:58 ` [patch 14/19] xfs: simplify xfs_qm_dqattach_grouphint Christoph Hellwig
2011-12-15  4:55   ` Ben Myers
2011-12-06 21:58 ` [patch 15/19] xfs: simplify xfs_qm_detach_gdquots Christoph Hellwig
2011-12-15 16:43   ` Ben Myers
2011-12-16  0:48     ` Dave Chinner
2011-12-16 21:33       ` Ben Myers
2011-12-06 21:58 ` [patch 16/19] xfs: add a xfs_dqhold helper Christoph Hellwig
2011-12-15 16:56   ` Ben Myers
2011-12-06 21:58 ` [patch 17/19] xfs: merge xfs_qm_dqinit_core into the only caller Christoph Hellwig
2011-12-15 17:00   ` Ben Myers
2011-12-06 21:58 ` [patch 18/19] xfs: kill xfs_qm_idtodq Christoph Hellwig
2011-12-15 20:07   ` Ben Myers
2011-12-06 21:58 ` [patch 19/19] xfs: remove XFS_QMOPT_DQSUSER Christoph Hellwig
2011-12-15 20:22   ` Ben Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111215030237.GF29840@sgi.com \
    --to=bpm@sgi.com \
    --cc=hch@infradead.org \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox