Re: [PATCH 12/25] ext4: support large block size in ext4_mb_get_buddy_page_lock()

From: Baokun Li

Date: Wed Nov 05 2025 - 04:44:34 EST


On 2025-11-05 17:13, Jan Kara wrote:
> On Sat 25-10-25 11:22:08, libaokun@xxxxxxxxxxxxxxx wrote:
>> From: Baokun Li <libaokun1@xxxxxxxxxx>
>>
>> Currently, ext4_mb_get_buddy_page_lock() uses blocks_per_page to calculate
>> folio index and offset. However, when blocksize is larger than PAGE_SIZE,
>> blocks_per_page becomes zero, leading to a potential division-by-zero bug.
>>
>> To support BS > PS, use bytes to compute folio index and offset within
>> folio to get rid of blocks_per_page.
>>
>> Also, since ext4_mb_get_buddy_page_lock() already fully supports folio,
>> rename it to ext4_mb_get_buddy_folio_lock().
>>
>> Signed-off-by: Baokun Li <libaokun1@xxxxxxxxxx>
>> Reviewed-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
> Looks good, just two typo fixes below. Feel free to add:
>
> Reviewed-by: Jan Kara <jack@xxxxxxx>
>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index 3494c6fe5bfb..d42d768a705a 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -1510,50 +1510,52 @@ static int ext4_mb_init_cache(struct folio *folio, char *incore, gfp_t gfp)
>> }
>>
> Let's fix some typos when updating the comment:

I’ll fix these typos in the next update.

Thank you for your review!


Regards,
Baokun

>
>> /*
>> - * Lock the buddy and bitmap pages. This make sure other parallel init_group
>> - * on the same buddy page doesn't happen whild holding the buddy page lock.
>> - * Return locked buddy and bitmap pages on e4b struct. If buddy and bitmap
>> - * are on the same page e4b->bd_buddy_folio is NULL and return value is 0.
>> + * Lock the buddy and bitmap folios. This make sure other parallel init_group
> ^^^ makes
>
>> + * on the same buddy folio doesn't happen whild holding the buddy folio lock.
> ^^ while
>
>> + * Return locked buddy and bitmap folios on e4b struct. If buddy and bitmap
>> + * are on the same folio e4b->bd_buddy_folio is NULL and return value is 0.
>> */
> Honza