Ext4 has quite complicated block allocation optimisation subsystem – buddy allocator. Let’s research what is it.
Buddy allocator is used only if:
- File size is bigger then s_mb_stream_request or group preallocation can’t find required blocks
- Required blocks are not found in inode preallocation list
- Required blocks are not found in locality group realloc space
Buddy allocator structures are not stored on disk. Only in memory. Destructed during unmount.
Regular allocator uses buddy allocator if request size is power of 2 and its order > sbi->s_mb_order2_reqs (/sys/fs/ext4/<partition>/mb_order2_req). Buddy allocator will not allocate block less then stripe size if ski->s_stripe is set. There are to buddy allocator tunables:
- /sys/fs/ext4/<partition>/mb_min_to_scan – how long allocator must find
- * /sys/fs/ext4/<partition>/mb_max_to_scan – how long allocator is allowed to find
Search is started from goal (in ac_g_ex). Every group decision is mad in ext4_mb_good_group (some thoughts about this function).