All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fstrim: prefer earlier mounted filesystems
@ 2017-06-15  8:26 Alex Ivanov
  2017-06-15 10:09 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Ivanov @ 2017-06-15  8:26 UTC (permalink / raw)
  To: util-linux

fstrim --all is broken in a way that if there is a bind mount for some filesystem, 
that filesystem will not be trimmed. This is especially critical for e.g. 
NixOS distribution, which needs bind mount within root fs: 
https://github.com/NixOS/nixos/blob/master/modules/system/boot/stage-2-init.sh#L55

Currently for a given filesystem during "de-duplication by source and root" phase,
an early mounted fs path is filtered (e.g. "/"), while later mounted fs path is kept 
(e.g. "/nix/store") though anyway discarded later (since it's an overlaying mount). 
This leads to skipped trimming.

So flip this behaviour. Should also help for other types of overlaying mounts.

Reference: 
https://github.com/karelzak/util-linux/blob/stable/v2.29/libmount/src/tab.c#L715

Signed-off-by: Alex Ivanov <yourbestfriend@openmailbox.org>
---
 sys-utils/fstrim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index b884af6d0..be3cd34a3 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -194,7 +194,7 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose)
 	mnt_table_uniq_fs(tab, 0, uniq_fs_target_cmp);
 
 	/* de-duplicate by source and root */
-	mnt_table_uniq_fs(tab, 0, uniq_fs_source_cmp);
+	mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
 
 	while (mnt_table_next_fs(tab, itr, &fs) == 0) {
 		const char *src = mnt_fs_get_srcpath(fs),
-- 
2.12.2


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

* Re: [PATCH] fstrim: prefer earlier mounted filesystems
  2017-06-15  8:26 [PATCH] fstrim: prefer earlier mounted filesystems Alex Ivanov
@ 2017-06-15 10:09 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2017-06-15 10:09 UTC (permalink / raw)
  To: Alex Ivanov; +Cc: util-linux

On Thu, Jun 15, 2017 at 11:26:25AM +0300, Alex Ivanov wrote:
> fstrim --all is broken in a way that if there is a bind mount for some filesystem, 
> that filesystem will not be trimmed. This is especially critical for e.g. 
> NixOS distribution, which needs bind mount within root fs: 
> https://github.com/NixOS/nixos/blob/master/modules/system/boot/stage-2-init.sh#L55
> 
> Currently for a given filesystem during "de-duplication by source and root" phase,
> an early mounted fs path is filtered (e.g. "/"), while later mounted fs path is kept 
> (e.g. "/nix/store") though anyway discarded later (since it's an overlaying mount). 
> This leads to skipped trimming.
> 
> So flip this behaviour. Should also help for other types of overlaying mounts.

Seems good (for mountpoints we need de-duplication in backward way,
but for sources it seems like a good solution). Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2017-06-15 10:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-15  8:26 [PATCH] fstrim: prefer earlier mounted filesystems Alex Ivanov
2017-06-15 10:09 ` Karel Zak

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.