ext4: Separate block bitmap and buddy bitmap freeing in ext4_mb_clear_bb()
authorKemeng Shi <shikemeng@huaweicloud.com>
Thu, 28 Sep 2023 16:04:01 +0000 (00:04 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 6 Oct 2023 02:32:15 +0000 (22:32 -0400)
commit33e728c67db6b7e72fc8d09f7a38f72302b8a98d
treeac4309d1c79a3328b72a02a169b7be373fa85d65
parent2f94711b098bc55285ac74aba2f2b83fd72b555f
ext4: Separate block bitmap and buddy bitmap freeing in ext4_mb_clear_bb()

This patch separates block bitmap and buddy bitmap freeing in order to
update block bitmap with ext4_mb_mark_context in following patch.

Separated freeing is safe with concurrent allocation as long as:
1. Firstly allocate block in buddy bitmap, and then in block bitmap.
2. Firstly free block in block bitmap, and then buddy bitmap.
Then freed block will only be available to allocation when both buddy
bitmap and block bitmap are updated by freeing.
Allocation obeys rule 1 already, just do sperated freeing with rule 2.

Separated freeing has no race with generate_buddy as:
Once ext4_mb_load_buddy_gfp is executed successfully, the update-to-date
buddy page can be found in sbi->s_buddy_cache and no more buddy
initialization of the buddy page will be executed concurrently until
buddy page is unloaded. As we always do free in "load buddy, free,
unload buddy" sequence, separated freeing has no race with generate_buddy.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20230928160407.142069-7-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mballoc.c