public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: "Artem S. Tashkinov" <aros@gmx.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: A possible way to reduce free space fragmentation?
Date: Sat, 1 Feb 2025 10:38:17 -0500	[thread overview]
Message-ID: <8539EF46-5166-47EE-AB26-01ACA68D6DE3@dilger.ca> (raw)
In-Reply-To: <8dcf1b6e-633c-4415-9412-6876efc07b50@gmx.com>

It should be possible to run "find $DIR -type f -size -1M | xargs e4defrag" to only defragment files below 1MB (or whatever you consider "small").

However, I don't recall if e4defrag will move a file if the new file has the same number of fragments as the original (presumably both "1") or leave it in place. That would be possible add an option to change. 

Alternately, just run the "find" above to find small files and then "cp $F $F.tmp && mv $F.tmp $F" to rewrite those files into new blocks, and hope mballoc will move them to a better location.

Cheers, Andreas

> On Jan 31, 2025, at 14:02, Artem S. Tashkinov <aros@gmx.com> wrote:
> 
> Hello,
> 
> ext4 has no free space defragmentation and at most you can use e4defrag
> to defragment individual files. I now have a 24GB ext4 filesystem that
> has only 7GB of space occupied however it has small files scattered all
> over it and now bigger files occupy more than one extent and I cannot
> reduce fragmentation to zero. One way to approach that would be to
> shrink the volume and then defragment it but that will involve a ton of
> disk writes and unnecessary tear and wear. Is it possible to modify the
> e4degrag utility to move small defragmented files, so that they were
> placed consecutively instead of being randomly spread all over the disk?
> 
> Regards,
> Artem
> 

  reply	other threads:[~2025-02-01 15:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-31 19:01 A possible way to reduce free space fragmentation? Artem S. Tashkinov
2025-02-01 15:38 ` Andreas Dilger [this message]
2025-02-01 15:48   ` Artem S. Tashkinov
2025-02-02 20:15     ` Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8539EF46-5166-47EE-AB26-01ACA68D6DE3@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=aros@gmx.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox