2

TLDR;

In EXT4 terminology, are "block groups" and "extents" the same thing ?

[EDIT] The suggested What do "extents" feature do in ext4 filesystem in linux? discussion doesn't answer that question. While it explains clearly what "extents" are, it doesn't talk about "block groups", and whether it's the same thing or not (it's not : see answer below).

DETAILS

In this post they discuss the structure of a block group :

block group

According to Wikipedia, an extent is a range of blocks.

Are those two concepts the same thing, just using different names ?

ChennyStar
  • 1,743
  • 1
  • From the Wikipedia link you included: "extent is a contiguous area of storage (= range of blocks) reserved for a file." This means, for a single file. Each extent represents a range of blocks for one file. – aviro Nov 12 '23 at 12:22
  • Thanks. I knew about extents before, its purpose, and its importance in keeping the drive less fragmented. But then I heard those "block groups", which I believe are usually called "cylinder groups". There are lot of infos about what "cylinder groups" are (https://opensource.com/article/17/5/introduction-ext4-filesystem and https://docs.oracle.com/cd/E18752_01/html/817-5093/fsfilesysappx-23724.html, among others), but I have yet to find an explanation of its purpose. If extents are for a single file, can a cylinder group contain multiple files ? – ChennyStar Nov 12 '23 at 13:01
  • From the fact that part of the block group is inode table, you can infer that the answer is yes. Each inode represents a file, so if a block group has an inode table, and it could contains multiple inodes, it means it contains multiple files. – aviro Nov 12 '23 at 13:06
  • OK thanks, so that answers my question : cylinder groups and extents are 2 different things. I guess I'll have to rephrase my question then : what's the purpose of cylinder groups ? Maybe to keep files from a same directory close together, in the same group ? So that the head stays in the same region when reading those files ? – ChennyStar Nov 12 '23 at 13:11
  • Yup, that seems to be the case. From https://unix.stackexchange.com/questions/703876/difference-between-fragment-and-extent-in-ext4 : The ext4fs algorithms also attempt to minimize external fragmentation by attempting to allocate blocks for files in the same cylinder group as other files in the same directory. – ChennyStar Nov 12 '23 at 13:13
  • So, basically, extents help to minimize internal fragmentation (e.g., fragmentation of a single file), and cylinder groups help to minimize external fragmentation (e.g., fragmentation of related files). At least that's what I think I understand... – ChennyStar Nov 12 '23 at 13:16

1 Answers1

5

The ext4 block groups are how ext4 is managing block allocation. There is a bitmap to manage the allocated/freed blocks for every group.

In archaic terminology this is a "cylinder group", but it has been a very long time since this related to a cylinder on a physical disk. In XFS this is an Allocation Group (AG).

An extent is a unit of block allocation for a single file, which represents a range of physically and logically contiguous blocks allocated to that file.

LustreOne
  • 1,774
  • Thanks for clarifying that "block group" and "cylinder group" are the same thing, and are different from extents, and that "cylinder group" is an obsolete term. AFAIK, the main purpose of "block groups" is to reduce external fragmentation (e.g., to try and keep files from a same directory in the same group, physically close to each other on the drive). Are there other reasons why block groups exist ? – ChennyStar Nov 13 '23 at 11:07