public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 4/5] xfs: use generic percpu counters for free block counter
Date: Mon, 2 Feb 2015 08:48:47 -0800	[thread overview]
Message-ID: <20150202164847.GB695@infradead.org> (raw)
In-Reply-To: <1422826983-29570-5-git-send-email-david@fromorbit.com>

>  	case XFS_SBS_FDBLOCKS:
>  
>  		if (delta > 0) {		/* Putting blocks back */
> +			if (mp->m_resblks == mp->m_resblks_avail) {
> +				percpu_counter_add(&mp->m_sb.sb_fdblocks, delta);
> +				return 0;
> +			}
> +
> +			/* put blocks back into reserve pool first */
> +			spin_lock(&mp->m_sb_lock);
> +			res_used = (long long)
> +					(mp->m_resblks - mp->m_resblks_avail);
> +
>  			if (res_used > delta) {
>  				mp->m_resblks_avail += delta;
>  			} else {
> +				delta -= res_used;
>  				mp->m_resblks_avail = mp->m_resblks;
> +				percpu_counter_add(&mp->m_sb.sb_fdblocks, delta);
>  			}
> +			spin_unlock(&mp->m_sb_lock);
> +			return 0;
>  
> +		}

>  
> +		/*
> +		 * Taking blocks away, need to be more accurate the closer we
> +		 * are to zero.
> +		 *
> +		 * batch size is set to a maximum of 1024 blocks - if we are
> +		 * allocating of freeing extents larger than this then we aren't
> +		 * going to be hammering the counter lock so a lock per update
> +		 * is not a problem.
> +		 *
> +		 * If the counter has a value of less than 2 * max batch size,
> +		 * then make everything serialise as we are real close to
> +		 * ENOSPC.
> +		 */
> +#define __BATCH	1024
> +		if (percpu_counter_compare(&mp->m_sb.sb_fdblocks,
> +					   2 * __BATCH) < 0)
> +			batch = 1;
> +		else
> +			batch = __BATCH;
> +
> +		__percpu_counter_add(&mp->m_sb.sb_fdblocks, delta, batch);
> +		if (percpu_counter_compare(&mp->m_sb.sb_fdblocks,
> +					   XFS_ALLOC_SET_ASIDE(mp)) >= 0) {
> +			/* we had space! */
> +			return 0;
>  		}
>  
> +		/*
> +		 * lock up the sb for dipping into reserves before releasing
> +		 * the space that took us to ENOSPC.
> +		 */
> +		spin_lock(&mp->m_sb_lock);
> +		percpu_counter_add(&mp->m_sb.sb_fdblocks, -delta);
> +		if (!rsvd)
> +			goto fdblocks_enospc;
> +
> +		lcounter = (long long)mp->m_resblks_avail + delta;
> +		if (lcounter >= 0) {
> +			mp->m_resblks_avail = lcounter;
> +			spin_unlock(&mp->m_sb_lock);
> +			return 0;
> +		}
> +		printk_once(KERN_WARNING
> +			"Filesystem \"%s\": reserve blocks depleted! "
> +			"Consider increasing reserve pool size.",
> +			mp->m_fsname);
> +fdblocks_enospc:
> +		spin_unlock(&mp->m_sb_lock);
> +		return -ENOSPC;
> +

This screams for having two different helpers for removing vs adding back
reserved blocks.

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

  reply	other threads:[~2015-02-02 16:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-01 21:42 [RFC PATCH 0/5] xfs: use generic percpu counters for icsb Dave Chinner
2015-02-01 21:42 ` [PATCH 1/5] xfs: struct xfs_sb is no longer tied to the on-disk format Dave Chinner
2015-02-02  8:41   ` Christoph Hellwig
2015-02-02 19:30     ` Dave Chinner
2015-02-03 21:37       ` Christoph Hellwig
2015-02-03 21:46         ` Dave Chinner
2015-02-03 23:34           ` Dave Chinner
2015-02-01 21:43 ` [PATCH 2/5] xfs: use generic percpu counters for inode counter Dave Chinner
2015-02-02 16:44   ` Christoph Hellwig
2015-02-02 19:33     ` Dave Chinner
2015-02-03 21:38       ` Christoph Hellwig
2015-02-01 21:43 ` [PATCH 3/5] xfs: use generic percpu counters for free " Dave Chinner
2015-02-02 17:10   ` Brian Foster
2015-02-01 21:43 ` [PATCH 4/5] xfs: use generic percpu counters for free block counter Dave Chinner
2015-02-02 16:48   ` Christoph Hellwig [this message]
2015-02-02 19:34     ` Dave Chinner
2015-02-02 17:11   ` Brian Foster
2015-02-02 19:39     ` Dave Chinner
2015-02-01 21:43 ` [PATCH 5/5] xfs: Remove icsb infrastructure Dave Chinner
2015-02-02 17:11   ` Brian Foster
2015-02-03 21:50 ` [RFC PATCH 0/5] xfs: use generic percpu counters for icsb Christoph Hellwig
2015-02-03 21:58   ` Dave Chinner
2015-02-03 22:02     ` Christoph Hellwig
2015-02-03 22:13       ` Dave Chinner

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=20150202164847.GB695@infradead.org \
    --to=hch@infradead.org \
    --cc=david@fromorbit.com \
    --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