All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: always free inline data before resetting inode fork during ifree
@ 2017-11-23  6:01 Darrick J. Wong
  2017-11-23  8:14 ` Christoph Hellwig
  2018-03-23  1:30 ` Luis R. Rodriguez
  0 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2017-11-23  6:01 UTC (permalink / raw)
  To: xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

In xfs_ifree, we reset the data/attr forks to extents format without
bothering to free any inline data buffer that might still be around
after all the blocks have been truncated off the file.  Prior to commit
43518812d2 ("xfs: remove support for inlining data/extents into the
inode fork") nobody noticed because the leftover inline data after
truncation was small enough to fit inside the inline buffer inside the
fork itself.

However, now that we've removed the inline buffer, we /always/ have to
free the inline data buffer or else we leak them like crazy.  This test
was found by turning on kmemleak for generic/001 or generic/388.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_inode.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 61d1cb7..8012741 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2401,6 +2401,24 @@ xfs_ifree_cluster(
 }
 
 /*
+ * Free any local-format buffers sitting around before we reset to
+ * extents format.
+ */
+static inline void
+xfs_ifree_local_data(
+	struct xfs_inode	*ip,
+	int			whichfork)
+{
+	struct xfs_ifork	*ifp;
+
+	if (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_LOCAL)
+		return;
+
+	ifp = XFS_IFORK_PTR(ip, whichfork);
+	xfs_idata_realloc(ip, -ifp->if_bytes, whichfork);
+}
+
+/*
  * This is called to return an inode to the inode free list.
  * The inode should already be truncated to 0 length and have
  * no pages associated with it.  This routine also assumes that
@@ -2437,6 +2455,9 @@ xfs_ifree(
 	if (error)
 		return error;
 
+	xfs_ifree_local_data(ip, XFS_DATA_FORK);
+	xfs_ifree_local_data(ip, XFS_ATTR_FORK);
+
 	VFS_I(ip)->i_mode = 0;		/* mark incore inode as free */
 	ip->i_d.di_flags = 0;
 	ip->i_d.di_dmevmask = 0;

^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2018-04-03  1:46 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23  6:01 [PATCH] xfs: always free inline data before resetting inode fork during ifree Darrick J. Wong
2017-11-23  8:14 ` Christoph Hellwig
2018-03-23  1:30 ` Luis R. Rodriguez
2018-03-23  3:41   ` Darrick J. Wong
2018-03-23 17:08     ` Luis R. Rodriguez
2018-03-23 17:26       ` Darrick J. Wong
2018-03-23 18:23         ` Luis R. Rodriguez
2018-03-24  9:06           ` Greg Kroah-Hartman
2018-03-24 17:21             ` Darrick J. Wong
2018-03-26  4:54               ` Sasha Levin
2018-03-26  6:48                 ` Darrick J. Wong
2018-03-26 17:39                 ` Luis R. Rodriguez
2018-03-25 22:33           ` Dave Chinner
2018-03-26 23:54             ` Sasha Levin
2018-03-27  7:06               ` Michal Hocko
2018-03-27 19:54                 ` Luis R. Rodriguez
2018-03-28 13:21                   ` Michal Hocko
2018-03-28 19:33                     ` Sasha Levin
2018-03-29  7:01                       ` Michal Hocko
2018-03-28  1:11                 ` Sasha Levin
2018-03-28 13:20                   ` Michal Hocko
2018-03-28  3:32               ` Dave Chinner
2018-03-28 19:30                 ` Sasha Levin
2018-03-28 19:40                   ` Darrick J. Wong
2018-03-28 23:05                   ` Dave Chinner
2018-03-29 18:12                     ` Luis R. Rodriguez
2018-03-29 18:17                       ` Josef Bacik
2018-03-29 18:36                         ` Sasha Levin
2018-03-30  2:47                     ` Sasha Levin
2018-03-30 19:49                       ` Luis R. Rodriguez
2018-04-02  0:35                         ` Sasha Levin
2018-03-31 22:02                       ` Dave Chinner
2018-04-02  0:32                         ` Sasha Levin
2018-04-03  1:46                           ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.