linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Mikhail Morfikov <mmorfikov@gmail.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: Question about ext4 extents and file fragmentation
Date: Wed, 20 Mar 2019 23:18:33 -0400	[thread overview]
Message-ID: <20190321031833.GB32021@mit.edu> (raw)
In-Reply-To: <aad2611a-9640-9ec1-108a-f67ba662c301@gmail.com>

On Wed, Mar 20, 2019 at 11:44:19PM +0100, Mikhail Morfikov wrote:
> When we have a big file on an ext4 partition, and filefrag shows
> the following:
> 
> filefrag -ve /bigfile
> Filesystem type is: ef53
> File size of /bigfile is 1439201280 (351368 blocks of 4096 bytes)
>  ext:     logical_offset:        physical_offset: length:   expected: flags:
>    0:        0..   32767:      34816..     67583:  32768:            
>    1:    32768..   63487:      67584..     98303:  30720:            
>    2:    63488..   96255:     100352..    133119:  32768:      98304:
>    3:    96256..  126975:     133120..    163839:  30720:            
>    4:   126976..  159743:     165888..    198655:  32768:     163840:
>    5:   159744..  190463:     198656..    229375:  30720:            
>    6:   190464..  223231:     231424..    264191:  32768:     229376:
>    7:   223232..  253951:     264192..    294911:  30720:            
>    8:   253952..  286719:     296960..    329727:  32768:     294912:
>    9:   286720..  319487:     329728..    362495:  32768:            
>   10:   319488..  351367:     362496..    394375:  31880:             last,eof
> /bigfile: 5 extents found
> 
> 1. How many fragments does this file really have? 11 or 5? 
> 2. Should the extents 0 and 1 be treated as one fragment or two 
>    separate ones? I know they could be one from the human 
>    perspective, but is it really one for ext4 filesystem?

They are encoded as two separate physical extents on disk.  Logically,
extents 0, 1, and 2 are contiguous regions on idks.

> 3. What does actually happen during the read in the case of 
>    some HDD and its magnetic heads? If the head finishes reading 
>    the whole extent (ext 0), will it be able to read the data of 
>    the next extent (ext 1) without any delays like in the case of
>    raw read (for instance dd if=/dev/sda ...), or will it be 
>    delayed because of the filesystem layer, and the head will 
>    have to spend some time to be positioned again in order to 
>    read the next extent?

The delay won't be because of the file system layer, as the
information about these first three extents will all be stored on the
same block on disk.  In addition, ext4 has an in-memory "extent cache"
which stores the logical->physical block mapping, and in memory, it
will be stored as a single entry in the extent cache.

It takes *time* to read 128 megabytes (32768 4k blocks), and from a
hard drive perspective, you are doing a streaming sequential read, how
the file system metadata is stored is not going to be the limiting
factor.  In fact, it's likely that they won't be issued to the hard
drive as a single I/O request anyway.  But that doesn't matter; the
hard drive has an I/O request queue, and so the right thing will
happen.

					- Ted

  reply	other threads:[~2019-03-21  3:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 22:44 Question about ext4 extents and file fragmentation Mikhail Morfikov
2019-03-21  3:18 ` Theodore Ts'o [this message]
2019-03-21  9:29   ` Mikhail Morfikov
2019-03-21 15:05     ` Theodore Ts'o
2019-03-21 15:59       ` Mikhail Morfikov

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=20190321031833.GB32021@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=mmorfikov@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).