Skip to content

Commit 9372dce

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: reclaim speculative preallocations for append only files
The XFS XFS_DIFLAG_APPEND maps to the VFS S_APPEND flag, which forbids writes that don't append at the current EOF. But the commit originally adding XFS_DIFLAG_APPEND support (commit a23321e766d in xfs xfs-import repository) also checked it to skip releasing speculative preallocations, which doesn't make any sense. Another commit (dd9f438 in the xfs-import repository) later extended that flag to also report these speculation preallocations which should not exist in getbmap. Remove these checks as nothing XFS_DIFLAG_APPEND implies that preallocations beyond EOF should exist, but explicitly check for XFS_DIFLAG_APPEND in xfs_file_release to bypass the algorithm that discard preallocations on the first close as append only files aren't expected to be written to only once. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent 11f4c3a commit 9372dce

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ xfs_getbmap(
331331
}
332332

333333
if (xfs_get_extsz_hint(ip) ||
334-
(ip->i_diflags &
335-
(XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)))
334+
(ip->i_diflags & XFS_DIFLAG_PREALLOC))
336335
max_len = mp->m_super->s_maxbytes;
337336
else
338337
max_len = XFS_ISIZE(ip);
@@ -524,12 +523,11 @@ xfs_can_free_eofblocks(
524523
return false;
525524

526525
/*
527-
* Only free real extents for inodes with persistent preallocations or
528-
* the append-only flag.
526+
* Do not free real extents in preallocated files unless the file has
527+
* delalloc blocks and we are forced to remove them.
529528
*/
530-
if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND))
531-
if (ip->i_delayed_blks == 0)
532-
return false;
529+
if ((ip->i_diflags & XFS_DIFLAG_PREALLOC) && !ip->i_delayed_blks)
530+
return false;
533531

534532
/*
535533
* Do not try to free post-EOF blocks if EOF is beyond the end of the

fs/xfs/xfs_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,9 @@ xfs_file_release(
12201220
* one file after another without going back to it while keeping the
12211221
* preallocation for files that have recurring open/write/close cycles.
12221222
*
1223+
* This heuristic is skipped for inodes with the append-only flag as
1224+
* that flag is rather pointless for inodes written only once.
1225+
*
12231226
* There is no point in freeing blocks here for open but unlinked files
12241227
* as they will be taken care of by the inactivation path soon.
12251228
*
@@ -1234,6 +1237,7 @@ xfs_file_release(
12341237
*/
12351238
if (inode->i_nlink &&
12361239
(file->f_mode & FMODE_WRITE) &&
1240+
!(ip->i_diflags & XFS_DIFLAG_APPEND) &&
12371241
!xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED) &&
12381242
xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) {
12391243
if (xfs_can_free_eofblocks(ip) &&

fs/xfs/xfs_icache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ xfs_inode_free_eofblocks(
11591159
if (xfs_can_free_eofblocks(ip))
11601160
return xfs_free_eofblocks(ip);
11611161

1162-
/* inode could be preallocated or append-only */
1162+
/* inode could be preallocated */
11631163
trace_xfs_inode_free_eofblocks_invalid(ip);
11641164
xfs_inode_clear_eofblocks_tag(ip);
11651165
return 0;

0 commit comments

Comments
 (0)