Re: [PATCH RESEND 0/10] fs: Introduce newflag(FALLOC_FL_COLLAPSE_RANGE) for fallocate

From: Dave Chinner
Date: Sun Feb 02 2014 - 17:03:58 EST


On Sun, Feb 02, 2014 at 08:21:06AM -0700, Matthew Wilcox wrote:
> On Sun, Feb 02, 2014 at 08:16:24AM -0700, Matthew Wilcox wrote:
> > On Sun, Feb 02, 2014 at 02:41:34PM +0900, Namjae Jeon wrote:
> > > The semantics of this flag are following:
> > > 1) It collapses the range lying between offset and length by removing any data
> > > blocks which are present in this range and than updates all the logical
> > > offsets of extents beyond "offset + len" to nullify the hole created by
> > > removing blocks. In short, it does not leave a hole.
> > > 2) It should be used exclusively. No other fallocate flag in combination.
> > > 3) Offset and length supplied to fallocate should be fs block size aligned
> > > in case of xfs and ext4.
> > > 4) Collaspe range does not work beyond i_size.
> >
> > What if the file is mmaped at the time somebody issues this command?
> > Seems to me we should drop pagecache pages that overlap with the
> > removed blocks. If the removed range is not a multiple of PAGE_SIZE,
> > then we should also drop any pagecache pages after the removed range.
>
> Oops, forgot to add "and if it is a multiple of page size, then we need
> to update the offsets of any pages after the removed page".

Yup, that's what the XFS implementation does when it punches the
hole out of the file before shifting the extents down. Check
xfs_free_file_space():

1275 /* wait for the completion of any pending DIOs */
1276 inode_dio_wait(VFS_I(ip));
1277
1278 rounding = max_t(xfs_off_t, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
1279 ioffset = offset & ~(rounding - 1);
1280 error = -filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1281 ioffset, -1);
1282 if (error)
1283 goto out;
1284 truncate_pagecache_range(VFS_I(ip), ioffset, -1);

Bonus points for working out why the XFS code doesn't just use
PAGE_CACHE_SIZE for rounding here....

Cheers,

Dave.
--
Dave Chinner
david@xxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/