On Mon, 30 May 2022, Matthew Wilcox wrote: > On Mon, May 30, 2022 at 08:00:12AM -0400, Mikulas Patocka wrote: > > The ntfs3 filesystem lacks the 'invalidate_folio' method and it causes > > memory leak. If you write to the filesystem and then unmount it, the > > cached written data are not freed and they are permanently leaked. > > > > Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx> > > Reported-by: José Luis Lara Carrascal <manualinux@xxxxxxxx> > > Fixes: 7ba13abbd31e ("fs: Turn block_invalidatepage into block_invalidate_folio") > > That commit is innocent here. Rather, this should be: > > Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") 82cae269cfa9 is included in the 5.15 kernel - and this bug only happens in 5.18. So, how could 82cae269cfa9 cause it? > Yes, trees before 7ba13abbd31e will need to change the patch to add > invalidate_page instead of invalidate_folio, but that's a normal part > of the process. In the kernel 5.17 and before, if the "invalidatepage" method is NULL, the kernel will use block_invalidatepage (see do_invalidatepage). So, we don't have to provide explicit "invalidatepage" in 5.17 and before and we don't have to backport this bugfix there. Note that the commit 7ba13abbd31e contains this piece of code: -#ifdef CONFIG_BLOCK - if (!invalidatepage) - invalidatepage = block_invalidatepage; -#endif So, it explicitly breaks filesystems that have NULL invalidatepage and NULL invalidate_folio and that relied on block_invalidatepage being called implicitly. So, I believe this commit is the root cause of this bug. I grepped the kernel for "dirty_folio" and it seems that ntfs3 is the only filesystem that provides "dirty_folio" and doesn't provide "invalidate_folio". Mikulas > > Cc: stable@xxxxxxxxxxxxxxx # v5.18 > > > > --- > > fs/ntfs3/inode.c | 1 + > > 1 file changed, 1 insertion(+) > > > > Index: linux-2.6/fs/ntfs3/inode.c > > =================================================================== > > --- linux-2.6.orig/fs/ntfs3/inode.c 2022-05-16 16:57:24.000000000 +0200 > > +++ linux-2.6/fs/ntfs3/inode.c 2022-05-30 13:36:45.000000000 +0200 > > @@ -1951,6 +1951,7 @@ const struct address_space_operations nt > > .direct_IO = ntfs_direct_IO, > > .bmap = ntfs_bmap, > > .dirty_folio = block_dirty_folio, > > + .invalidate_folio = block_invalidate_folio, > > }; > > > > const struct address_space_operations ntfs_aops_cmpr = { >