public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Brian Foster <bfoster@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [RFC PATCH 1/4] xfs: add EOFBLOCKS inode tagging/untagging
Date: Mon, 3 Sep 2012 14:20:33 +1000	[thread overview]
Message-ID: <20120903042033.GQ15292@dastard> (raw)
In-Reply-To: <1346097111-4476-2-git-send-email-bfoster@redhat.com>

On Mon, Aug 27, 2012 at 03:51:48PM -0400, Brian Foster wrote:
> Add the XFS_ICI_EOFBLOCKS_TAG inode tag to identify inodes with
> speculatively preallocated blocks beyond EOF. An inode is tagged
> when speculative preallocation occurs and untagged either via
> truncate down or when post-EOF blocks are freed via release or
> reclaim.
> 
> The tag management is intentionally not aggressive to prefer
> simplicity over the complexity of handling all the corner cases
> under which post-EOF blocks could be freed (i.e., forward
> truncation, fallocate, write error conditions, etc.). This means
> that a tagged inode may or may not have post-EOF blocks after a
> period of time. The tag is eventually cleared when the inode is
> released or reclaimed.
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
.....
> diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
> index 94b32f9..2cd2883 100644
> --- a/fs/xfs/xfs_inode.h
> +++ b/fs/xfs/xfs_inode.h
> @@ -305,10 +305,16 @@ xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
>  }
>  
>  static inline void
> +__xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
> +{
> +	ip->i_flags &= ~flags;
> +}
> +
> +static inline void
>  xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
>  {
>  	spin_lock(&ip->i_flags_lock);
> -	ip->i_flags &= ~flags;
> +	__xfs_iflags_clear(ip, flags);
>  	spin_unlock(&ip->i_flags_lock);
>  }

Left overs from a previous version?

>  
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index 973dff6..2968ee8 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -459,6 +459,13 @@ retry:
>  	if (!(imap[0].br_startblock || XFS_IS_REALTIME_INODE(ip)))
>  		return xfs_alert_fsblock_zero(ip, &imap[0]);
>  
> +	/*
> +	 * Tag the inode as speculatively preallocated so we can reclaim this
> +	 * space on demand, if necessary.
> +	 */
> +	if (prealloc)
> +		xfs_inode_set_eofblocks_tag(ip);
> +
>  	*ret_imap = imap[0];
>  	return 0;
>  }
> diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
> index 4e00cf0..dcd1d5f 100644
> --- a/fs/xfs/xfs_iops.c
> +++ b/fs/xfs/xfs_iops.c
> @@ -854,6 +854,9 @@ xfs_setattr_size(
>  		 * and do not wait the usual (long) time for writeout.
>  		 */
>  		xfs_iflags_set(ip, XFS_ITRUNCATED);
> +
> +		/* A truncate down always removes post-EOF blocks. */
> +		xfs_inode_clear_eofblocks_tag(ip);
>  	}
>  
>  	if (mask & ATTR_CTIME) {
> diff --git a/fs/xfs/xfs_sync.c b/fs/xfs/xfs_sync.c
> index 9654817..5e14741 100644
> --- a/fs/xfs/xfs_sync.c
> +++ b/fs/xfs/xfs_sync.c
> @@ -971,3 +971,79 @@ xfs_reclaim_inodes_count(
>  	return reclaimable;
>  }
>  
> +STATIC void
> +__xfs_inode_set_eofblocks_tag(
> +	struct xfs_perag	*pag,
> +	struct xfs_inode	*ip)
> +{
> +	int tagged = radix_tree_tagged(&pag->pag_ici_root,
> +				       XFS_ICI_EOFBLOCKS_TAG);
> +
> +	radix_tree_tag_set(&pag->pag_ici_root,
> +			   XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino),
> +			   XFS_ICI_EOFBLOCKS_TAG);
> +
> +	if (!tagged) {
> +		/* propagate the eofblocks tag up into the perag radix tree */
> +		spin_lock(&ip->i_mount->m_perag_lock);
> +		radix_tree_tag_set(&ip->i_mount->m_perag_tree,
> +				   XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino),
> +				   XFS_ICI_EOFBLOCKS_TAG);
> +		spin_unlock(&ip->i_mount->m_perag_lock);
> +
> +		trace_xfs_perag_set_eofblocks(ip->i_mount, pag->pag_agno,
> +					      -1, _RET_IP_);
> +	}
> +}
> +
> +void
> +xfs_inode_set_eofblocks_tag(
> +	xfs_inode_t	*ip)
> +{
> +	struct xfs_mount *mp = ip->i_mount;
> +	struct xfs_perag *pag;
> +
> +	pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
> +	spin_lock(&pag->pag_ici_lock);
> +	trace_xfs_set_eofblocks_tag(ip);
> +	__xfs_inode_set_eofblocks_tag(pag, ip);
> +	spin_unlock(&pag->pag_ici_lock);
> +	xfs_perag_put(pag);
> +}

I know the code you copied had this two-function structure, but that
was because it has callers of the __ versions of the functions. I'd
just make these a single function.

> +
> +STATIC void
> +__xfs_inode_clear_eofblocks(
> +	xfs_perag_t	*pag,
> +	xfs_inode_t	*ip)
> +{
> +	radix_tree_tag_clear(&pag->pag_ici_root,
> +			     XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino),
> +			     XFS_ICI_EOFBLOCKS_TAG);
> +
> +	if (!radix_tree_tagged(&pag->pag_ici_root, XFS_ICI_EOFBLOCKS_TAG)) {
> +		/* clear the eofblocks tag from the perag radix tree */
> +		spin_lock(&ip->i_mount->m_perag_lock);
> +		radix_tree_tag_clear(&ip->i_mount->m_perag_tree,
> +				     XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino),
> +				     XFS_ICI_EOFBLOCKS_TAG);
> +		spin_unlock(&ip->i_mount->m_perag_lock);
> +		trace_xfs_perag_clear_eofblocks(ip->i_mount, pag->pag_agno,
> +					       -1, _RET_IP_);
> +	}
> +}
> +
> +void
> +xfs_inode_clear_eofblocks_tag(
> +	xfs_inode_t	*ip)
> +{
> +	struct xfs_mount *mp = ip->i_mount;
> +	struct xfs_perag *pag;
> +
> +	pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
> +	spin_lock(&pag->pag_ici_lock);
> +	trace_xfs_clear_eofblocks_tag(ip);
> +	__xfs_inode_clear_eofblocks(pag, ip);
> +	spin_unlock(&pag->pag_ici_lock);
> +	xfs_perag_put(pag);
> +}

Same here.

> diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
> index 2a5c6373..658ee2e 100644
> --- a/fs/xfs/xfs_vnodeops.c
> +++ b/fs/xfs/xfs_vnodeops.c
> @@ -467,6 +467,8 @@ xfs_release(
>  		if (error)
>  			return error;
>  
> +		xfs_inode_clear_eofblocks_tag(ip);
> +
>  		/* delalloc blocks after truncation means it really is dirty */
>  		if (ip->i_delayed_blks)
>  			xfs_iflags_set(ip, XFS_IDIRTY_RELEASE);
> @@ -523,6 +525,7 @@ xfs_inactive(
>  			error = xfs_free_eofblocks(mp, ip, false);
>  			if (error)
>  				return VN_INACTIVE_CACHE;
> +			xfs_inode_clear_eofblocks_tag(ip);
>  		}
>  		goto out;

I think it's better to call xfs_inode_clear_eofblocks_tag() inside
xfs_free_eofblocks() - that's where the blocks are being freed,
after all.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

  reply	other threads:[~2012-09-03  4:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 19:51 [RFC PATCH 0/4] xfs: add support for tracking inodes with post-EOF speculative preallocation Brian Foster
2012-08-27 19:51 ` [RFC PATCH 1/4] xfs: add EOFBLOCKS inode tagging/untagging Brian Foster
2012-09-03  4:20   ` Dave Chinner [this message]
2012-08-27 19:51 ` [RFC PATCH 2/4] xfs: create function to scan and clear EOFBLOCKS inodes Brian Foster
2012-09-03  5:06   ` Dave Chinner
2012-09-04 14:10     ` Brian Foster
2012-09-05  6:42       ` Dave Chinner
2012-09-05 12:22         ` Brian Foster
2012-08-27 19:51 ` [RFC PATCH 3/4] xfs: add FREE_EOFBLOCKS ioctl Brian Foster
2012-09-03  5:17   ` Dave Chinner
2012-09-04 14:10     ` Brian Foster
2012-09-05  6:49       ` Dave Chinner
2012-09-05 12:22         ` Brian Foster
2012-08-27 19:51 ` [RFC PATCH 4/4] xfs: add background scanning to clear EOFBLOCKS inodes Brian Foster
2012-09-03  5:28   ` Dave Chinner
2012-09-04 14:10     ` Brian Foster
2012-09-05  7:00       ` Dave Chinner
2012-09-05 12:22         ` Brian Foster
2012-09-05 23:43           ` 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=20120903042033.GQ15292@dastard \
    --to=david@fromorbit.com \
    --cc=bfoster@redhat.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