All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request
@ 2022-05-28 11:00 Baokun Li
  2022-05-28 11:00 ` [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Baokun Li @ 2022-05-28 11:00 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, ritesh.list, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, libaokun1

The logical block map reached before the problem stack was 1011.
The estimated location of the size logical block of the inde plus
the required allocation length 7, the size is 1018.

But the i_size of inode is 1299, so the size is 1299,
the aligned size is 2048, and the end is 2048.
Because of the restriction of ar -> pleft, start==648.

EXT4_BLOCKS_PER_GROUP (ac- > ac_sb) is 256,
so the size is 256 and the end is 904.

It is not normal to truncate here, the end is less than 1299 of the
target logical block, that is, the allocated range does not contain
the target logical block.

Then this new scope conflicts with the previous PA, as follows:

        pa_start-506        pa_end-759
 |____________P________V_________P__________V_____________l________|
 0                 start-648             end-904    logical-1299   2048

In this case, start is changed to pa_end, that is, 759.
In this case, a bug_ON is reported in ext4_mb_mark_diskspace_used.

The problem is caused by the truncation introduced in the
cd648b8a8fd5 ("ext4: trim allocation requests to group size").
The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP.
However, the truncation method is incorrect. The group where the
logical is located should be used for allocation. If the value of
EXT4_BLOCKS_PER_GROUP is 256, size 2048 can be divided into eight
groups. If the value of logical is 1299, the value of logical must be
in the sixth group, that is,
	start=1299/256*256=5*256=1280,
	end=size+1280=1536.

Then, the value range can be further narrowed down based on
other restrictions.
                              1024    1280     1536
|_______|_______|_______|_______|_______|__l_____|_______|_______|
0 group1  group2  group3  group4  group5  group6  group7  group8 2048 

At the same time, we fixed earlier assertions that we could find out when
the target logical block was not in the allocated range.

Ritesh Harjani found that flex_bg groups was not considered in
ext4_mb_normalize_request. So we add support for flex_bg to make
the physical blocks of large files contiguous.

I ran xfstests on ext3 and ext4 and found no problems in ext3/4.

V1: https://patchwork.ozlabs.org/project/linux-ext4/cover/20220521134217.312071-1-libaokun1@huawei.com/
V2: https://patchwork.ozlabs.org/project/linux-ext4/cover/20220523141658.2919003-1-libaokun1@huawei.com/

Baokun Li (3):
  ext4: fix bug_on ext4_mb_use_inode_pa
  ext4: correct the judgment of BUG in ext4_mb_normalize_request
  ext4: support flex_bg in ext4_mb_normalize_request

 fs/ext4/mballoc.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa
  2022-05-28 11:00 [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
@ 2022-05-28 11:00 ` Baokun Li
  2022-05-28 15:10   ` Ritesh Harjani
  2022-05-28 11:00 ` [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request Baokun Li
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Baokun Li @ 2022-05-28 11:00 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, ritesh.list, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, libaokun1, Hulk Robot

Hulk Robot reported a BUG_ON:
==================================================================
kernel BUG at fs/ext4/mballoc.c:3211!
[...]
RIP: 0010:ext4_mb_mark_diskspace_used.cold+0x85/0x136f
[...]
Call Trace:
 ext4_mb_new_blocks+0x9df/0x5d30
 ext4_ext_map_blocks+0x1803/0x4d80
 ext4_map_blocks+0x3a4/0x1a10
 ext4_writepages+0x126d/0x2c30
 do_writepages+0x7f/0x1b0
 __filemap_fdatawrite_range+0x285/0x3b0
 file_write_and_wait_range+0xb1/0x140
 ext4_sync_file+0x1aa/0xca0
 vfs_fsync_range+0xfb/0x260
 do_fsync+0x48/0xa0
[...]
==================================================================

Above issue may happen as follows:
-------------------------------------
do_fsync
 vfs_fsync_range
  ext4_sync_file
   file_write_and_wait_range
    __filemap_fdatawrite_range
     do_writepages
      ext4_writepages
       mpage_map_and_submit_extent
        mpage_map_one_extent
         ext4_map_blocks
          ext4_mb_new_blocks
           ext4_mb_normalize_request
            >>> start + size <= ac->ac_o_ex.fe_logical
           ext4_mb_regular_allocator
            ext4_mb_simple_scan_group
             ext4_mb_use_best_found
              ext4_mb_new_preallocation
               ext4_mb_new_inode_pa
                ext4_mb_use_inode_pa
                 >>> set ac->ac_b_ex.fe_len <= 0
           ext4_mb_mark_diskspace_used
            >>> BUG_ON(ac->ac_b_ex.fe_len <= 0);

we can easily reproduce this problem with the following commands:
	`fallocate -l100M disk`
	`mkfs.ext4 -b 1024 -g 256 disk`
	`mount disk /mnt`
	`fsstress -d /mnt -l 0 -n 1000 -p 1`

The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP.
Therefore, "start + size <= ac->ac_o_ex.fe_logical" may occur
when the size is truncated. So start should be the start position of
the group where ac_o_ex.fe_logical is located after alignment.
In addition, when the value of fe_logical or EXT4_BLOCKS_PER_GROUP
is very large, the value calculated by start_off is more accurate.

Fixes: cd648b8a8fd5 ("ext4: trim allocation requests to group size")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
V1->V2:
	Replace round_down() with rounddown().
	Modified comments.
V2->V3:
	Convert EXT4_BLOCKS_PER_GROUP type to ext4_lblk_t
	to avoid compilation warnings.

 fs/ext4/mballoc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 9f12f29bc346..4d3740fdff90 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4104,6 +4104,15 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	size = size >> bsbits;
 	start = start_off >> bsbits;
 
+	/*
+	 * For tiny groups (smaller than 8MB) the chosen allocation
+	 * alignment may be larger than group size. Make sure the
+	 * alignment does not move allocation to a different group which
+	 * makes mballoc fail assertions later.
+	 */
+	start = max(start, rounddown(ac->ac_o_ex.fe_logical,
+			(ext4_lblk_t)EXT4_BLOCKS_PER_GROUP(ac->ac_sb)));
+
 	/* don't cover already allocated blocks in selected range */
 	if (ar->pleft && start <= ar->lleft) {
 		size -= ar->lleft + 1 - start;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request
  2022-05-28 11:00 [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
  2022-05-28 11:00 ` [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
@ 2022-05-28 11:00 ` Baokun Li
  2022-05-28 15:12   ` Ritesh Harjani
  2022-05-28 11:00 ` [PATCH v3 3/3] ext4: support flex_bg " Baokun Li
  2022-06-18  2:12 ` [PATCH v3 0/3] ext4: fix two bugs " Theodore Ts'o
  3 siblings, 1 reply; 12+ messages in thread
From: Baokun Li @ 2022-05-28 11:00 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, ritesh.list, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, libaokun1

ext4_mb_normalize_request() can move logical start of allocated blocks
to reduce fragmentation and better utilize preallocation. However logical
block requested as a start of allocation (ac->ac_o_ex.fe_logical) should
always be covered by allocated blocks so we should check that by
modifying and to or in the assertion.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
V1->V2:
	Change Fixes from dfe076c106f6 to c9de560ded61.
V2->V3:
	Delete Fixes tag.
	Add more comments and commit logs to make the code easier to understand.

 fs/ext4/mballoc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 4d3740fdff90..9e06334771a3 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4185,7 +4185,22 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	}
 	rcu_read_unlock();
 
-	if (start + size <= ac->ac_o_ex.fe_logical &&
+	/*
+	 * In this function "start" and "size" are normalized for better
+	 * alignment and length such that we could preallocate more blocks.
+	 * This normalization is done such that original request of
+	 * ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and
+	 * "size" boundaries.
+	 * (Note fe_len can be relaxed since FS block allocation API does not
+	 * provide gurantee on number of contiguous blocks allocation since that
+	 * depends upon free space left, etc).
+	 * In case of inode pa, later we use the allocated blocks
+	 * [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated
+	 * range of goal/best blocks [start, size] to put it at the
+	 * ac_o_ex.fe_logical extent of this inode.
+	 * (See ext4_mb_use_inode_pa() for more details)
+	 */
+	if (start + size <= ac->ac_o_ex.fe_logical ||
 			start > ac->ac_o_ex.fe_logical) {
 		ext4_msg(ac->ac_sb, KERN_ERR,
 			 "start %lu, size %lu, fe_logical %lu",
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/3] ext4: support flex_bg in ext4_mb_normalize_request
  2022-05-28 11:00 [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
  2022-05-28 11:00 ` [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
  2022-05-28 11:00 ` [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request Baokun Li
@ 2022-05-28 11:00 ` Baokun Li
  2022-05-28 15:09   ` Ritesh Harjani
  2022-06-18  2:12 ` [PATCH v3 0/3] ext4: fix two bugs " Theodore Ts'o
  3 siblings, 1 reply; 12+ messages in thread
From: Baokun Li @ 2022-05-28 11:00 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, ritesh.list, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, libaokun1

In ext4_mb_normalize_request, the size of the allocation request is
limited to no more than EXT4_BLOCKS_PER_GROUP. Ritesh mentions that this
does not take into account the case of flex_bg groups. So we should add
support for flex_bg to make the physical blocks of large files contiguous.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 fs/ext4/mballoc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 9e06334771a3..253fc250e9a0 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4028,6 +4028,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	loff_t size, start_off;
 	loff_t orig_size __maybe_unused;
 	ext4_lblk_t start;
+	ext4_lblk_t bpg;
 	struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
 	struct ext4_prealloc_space *pa;
 
@@ -4051,6 +4052,11 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	}
 
 	bsbits = ac->ac_sb->s_blocksize_bits;
+	bpg = EXT4_BLOCKS_PER_GROUP(ac->ac_sb);
+	if (ext4_has_feature_flex_bg(ac->ac_sb) && sbi->s_log_groups_per_flex) {
+		if (check_shl_overflow(bpg, sbi->s_log_groups_per_flex, &bpg))
+			bpg = EXT_MAX_BLOCKS;
+	}
 
 	/* first, let's learn actual file size
 	 * given current request is allocated */
@@ -4110,8 +4116,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	 * alignment does not move allocation to a different group which
 	 * makes mballoc fail assertions later.
 	 */
-	start = max(start, rounddown(ac->ac_o_ex.fe_logical,
-			(ext4_lblk_t)EXT4_BLOCKS_PER_GROUP(ac->ac_sb)));
+	start = max(start, rounddown(ac->ac_o_ex.fe_logical, bpg));
 
 	/* don't cover already allocated blocks in selected range */
 	if (ar->pleft && start <= ar->lleft) {
@@ -4125,8 +4130,8 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 	 * Trim allocation request for filesystems with artificially small
 	 * groups.
 	 */
-	if (size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb))
-		size = EXT4_BLOCKS_PER_GROUP(ac->ac_sb);
+	if (size > bpg)
+		size = bpg;
 
 	end = start + size;
 
@@ -4208,7 +4213,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
 			 (unsigned long) ac->ac_o_ex.fe_logical);
 		BUG();
 	}
-	BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb));
+	BUG_ON(size <= 0 || size > bpg);
 
 	/* now prepare goal request */
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/3] ext4: support flex_bg in ext4_mb_normalize_request
  2022-05-28 11:00 ` [PATCH v3 3/3] ext4: support flex_bg " Baokun Li
@ 2022-05-28 15:09   ` Ritesh Harjani
  2022-05-30  2:35     ` Baokun Li
  0 siblings, 1 reply; 12+ messages in thread
From: Ritesh Harjani @ 2022-05-28 15:09 UTC (permalink / raw)
  To: Baokun Li
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3

On 22/05/28 07:00PM, Baokun Li wrote:
> In ext4_mb_normalize_request, the size of the allocation request is
> limited to no more than EXT4_BLOCKS_PER_GROUP. Ritesh mentions that this
> does not take into account the case of flex_bg groups. So we should add
> support for flex_bg to make the physical blocks of large files contiguous.

My only concern here was that what if we are at the flex group end boundary and
decide to take the size as of flex group size. How are we detecting that case.

But, I haven't yet looked at this patch of yours (as I am on travel for next few days),
but if this requires further discussion, we can work on this seperately and let
the other two patches go in as those are part of the bug fixes which you
identified (just my thoughts).

-ritesh

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa
  2022-05-28 11:00 ` [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
@ 2022-05-28 15:10   ` Ritesh Harjani
  2022-05-30  2:12     ` Baokun Li
  0 siblings, 1 reply; 12+ messages in thread
From: Ritesh Harjani @ 2022-05-28 15:10 UTC (permalink / raw)
  To: Baokun Li
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, Hulk Robot

On 22/05/28 07:00PM, Baokun Li wrote:
> Hulk Robot reported a BUG_ON:
> ==================================================================
> kernel BUG at fs/ext4/mballoc.c:3211!
> [...]
> RIP: 0010:ext4_mb_mark_diskspace_used.cold+0x85/0x136f
> [...]
> Call Trace:
>  ext4_mb_new_blocks+0x9df/0x5d30
>  ext4_ext_map_blocks+0x1803/0x4d80
>  ext4_map_blocks+0x3a4/0x1a10
>  ext4_writepages+0x126d/0x2c30
>  do_writepages+0x7f/0x1b0
>  __filemap_fdatawrite_range+0x285/0x3b0
>  file_write_and_wait_range+0xb1/0x140
>  ext4_sync_file+0x1aa/0xca0
>  vfs_fsync_range+0xfb/0x260
>  do_fsync+0x48/0xa0
> [...]
> ==================================================================
>
> Above issue may happen as follows:
> -------------------------------------
> do_fsync
>  vfs_fsync_range
>   ext4_sync_file
>    file_write_and_wait_range
>     __filemap_fdatawrite_range
>      do_writepages
>       ext4_writepages
>        mpage_map_and_submit_extent
>         mpage_map_one_extent
>          ext4_map_blocks
>           ext4_mb_new_blocks
>            ext4_mb_normalize_request
>             >>> start + size <= ac->ac_o_ex.fe_logical
>            ext4_mb_regular_allocator
>             ext4_mb_simple_scan_group
>              ext4_mb_use_best_found
>               ext4_mb_new_preallocation
>                ext4_mb_new_inode_pa
>                 ext4_mb_use_inode_pa
>                  >>> set ac->ac_b_ex.fe_len <= 0
>            ext4_mb_mark_diskspace_used
>             >>> BUG_ON(ac->ac_b_ex.fe_len <= 0);
>
> we can easily reproduce this problem with the following commands:
> 	`fallocate -l100M disk`
> 	`mkfs.ext4 -b 1024 -g 256 disk`
> 	`mount disk /mnt`
> 	`fsstress -d /mnt -l 0 -n 1000 -p 1`
>
> The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP.
> Therefore, "start + size <= ac->ac_o_ex.fe_logical" may occur
> when the size is truncated. So start should be the start position of
> the group where ac_o_ex.fe_logical is located after alignment.
> In addition, when the value of fe_logical or EXT4_BLOCKS_PER_GROUP
> is very large, the value calculated by start_off is more accurate.
>
> Fixes: cd648b8a8fd5 ("ext4: trim allocation requests to group size")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> ---
> V1->V2:
> 	Replace round_down() with rounddown().
> 	Modified comments.
> V2->V3:
> 	Convert EXT4_BLOCKS_PER_GROUP type to ext4_lblk_t
> 	to avoid compilation warnings.

Looks good to me. Feel free to add -

Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com>

>
>  fs/ext4/mballoc.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request
  2022-05-28 11:00 ` [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request Baokun Li
@ 2022-05-28 15:12   ` Ritesh Harjani
  2022-05-30  2:13     ` Baokun Li
  0 siblings, 1 reply; 12+ messages in thread
From: Ritesh Harjani @ 2022-05-28 15:12 UTC (permalink / raw)
  To: Baokun Li
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3

On 22/05/28 07:00PM, Baokun Li wrote:
> ext4_mb_normalize_request() can move logical start of allocated blocks
> to reduce fragmentation and better utilize preallocation. However logical
> block requested as a start of allocation (ac->ac_o_ex.fe_logical) should
> always be covered by allocated blocks so we should check that by
> modifying and to or in the assertion.
>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>

Changes looks good to me as we discussed. Feel free to add -

Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com>

> ---
> V1->V2:
> 	Change Fixes from dfe076c106f6 to c9de560ded61.
> V2->V3:
> 	Delete Fixes tag.
> 	Add more comments and commit logs to make the code easier to understand.
>
>  fs/ext4/mballoc.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 4d3740fdff90..9e06334771a3 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4185,7 +4185,22 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
>  	}
>  	rcu_read_unlock();
>
> -	if (start + size <= ac->ac_o_ex.fe_logical &&
> +	/*
> +	 * In this function "start" and "size" are normalized for better
> +	 * alignment and length such that we could preallocate more blocks.
> +	 * This normalization is done such that original request of
> +	 * ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and
> +	 * "size" boundaries.
> +	 * (Note fe_len can be relaxed since FS block allocation API does not
> +	 * provide gurantee on number of contiguous blocks allocation since that
> +	 * depends upon free space left, etc).
> +	 * In case of inode pa, later we use the allocated blocks
> +	 * [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated
> +	 * range of goal/best blocks [start, size] to put it at the
> +	 * ac_o_ex.fe_logical extent of this inode.
> +	 * (See ext4_mb_use_inode_pa() for more details)
> +	 */
> +	if (start + size <= ac->ac_o_ex.fe_logical ||
>  			start > ac->ac_o_ex.fe_logical) {
>  		ext4_msg(ac->ac_sb, KERN_ERR,
>  			 "start %lu, size %lu, fe_logical %lu",
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa
  2022-05-28 15:10   ` Ritesh Harjani
@ 2022-05-30  2:12     ` Baokun Li
  0 siblings, 0 replies; 12+ messages in thread
From: Baokun Li @ 2022-05-30  2:12 UTC (permalink / raw)
  To: Ritesh Harjani
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, Hulk Robot, Baokun Li

在 2022/5/28 23:10, Ritesh Harjani 写道:
> On 22/05/28 07:00PM, Baokun Li wrote:
>> Hulk Robot reported a BUG_ON:
>> ==================================================================
>> kernel BUG at fs/ext4/mballoc.c:3211!
>> [...]
>> RIP: 0010:ext4_mb_mark_diskspace_used.cold+0x85/0x136f
>> [...]
>> Call Trace:
>>   ext4_mb_new_blocks+0x9df/0x5d30
>>   ext4_ext_map_blocks+0x1803/0x4d80
>>   ext4_map_blocks+0x3a4/0x1a10
>>   ext4_writepages+0x126d/0x2c30
>>   do_writepages+0x7f/0x1b0
>>   __filemap_fdatawrite_range+0x285/0x3b0
>>   file_write_and_wait_range+0xb1/0x140
>>   ext4_sync_file+0x1aa/0xca0
>>   vfs_fsync_range+0xfb/0x260
>>   do_fsync+0x48/0xa0
>> [...]
>> ==================================================================
>>
>> Above issue may happen as follows:
>> -------------------------------------
>> do_fsync
>>   vfs_fsync_range
>>    ext4_sync_file
>>     file_write_and_wait_range
>>      __filemap_fdatawrite_range
>>       do_writepages
>>        ext4_writepages
>>         mpage_map_and_submit_extent
>>          mpage_map_one_extent
>>           ext4_map_blocks
>>            ext4_mb_new_blocks
>>             ext4_mb_normalize_request
>>              >>> start + size <= ac->ac_o_ex.fe_logical
>>             ext4_mb_regular_allocator
>>              ext4_mb_simple_scan_group
>>               ext4_mb_use_best_found
>>                ext4_mb_new_preallocation
>>                 ext4_mb_new_inode_pa
>>                  ext4_mb_use_inode_pa
>>                   >>> set ac->ac_b_ex.fe_len <= 0
>>             ext4_mb_mark_diskspace_used
>>              >>> BUG_ON(ac->ac_b_ex.fe_len <= 0);
>>
>> we can easily reproduce this problem with the following commands:
>> 	`fallocate -l100M disk`
>> 	`mkfs.ext4 -b 1024 -g 256 disk`
>> 	`mount disk /mnt`
>> 	`fsstress -d /mnt -l 0 -n 1000 -p 1`
>>
>> The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP.
>> Therefore, "start + size <= ac->ac_o_ex.fe_logical" may occur
>> when the size is truncated. So start should be the start position of
>> the group where ac_o_ex.fe_logical is located after alignment.
>> In addition, when the value of fe_logical or EXT4_BLOCKS_PER_GROUP
>> is very large, the value calculated by start_off is more accurate.
>>
>> Fixes: cd648b8a8fd5 ("ext4: trim allocation requests to group size")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Baokun Li <libaokun1@huawei.com>
>> ---
>> V1->V2:
>> 	Replace round_down() with rounddown().
>> 	Modified comments.
>> V2->V3:
>> 	Convert EXT4_BLOCKS_PER_GROUP type to ext4_lblk_t
>> 	to avoid compilation warnings.
> Looks good to me. Feel free to add -
>
> Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com>
>
>>   fs/ext4/mballoc.c | 9 +++++++++
>>   1 file changed, 9 insertions(+)
>>
> .
>
Thank you for your review!
-- 
With Best Regards,
Baokun Li


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request
  2022-05-28 15:12   ` Ritesh Harjani
@ 2022-05-30  2:13     ` Baokun Li
  0 siblings, 0 replies; 12+ messages in thread
From: Baokun Li @ 2022-05-30  2:13 UTC (permalink / raw)
  To: Ritesh Harjani
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, Baokun Li

在 2022/5/28 23:12, Ritesh Harjani 写道:
> On 22/05/28 07:00PM, Baokun Li wrote:
>> ext4_mb_normalize_request() can move logical start of allocated blocks
>> to reduce fragmentation and better utilize preallocation. However logical
>> block requested as a start of allocation (ac->ac_o_ex.fe_logical) should
>> always be covered by allocated blocks so we should check that by
>> modifying and to or in the assertion.
>>
>> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> Changes looks good to me as we discussed. Feel free to add -
>
> Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com>
>
>> ---
>> V1->V2:
>> 	Change Fixes from dfe076c106f6 to c9de560ded61.
>> V2->V3:
>> 	Delete Fixes tag.
>> 	Add more comments and commit logs to make the code easier to understand.
>>
>>   fs/ext4/mballoc.c | 17 ++++++++++++++++-
>>   1 file changed, 16 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index 4d3740fdff90..9e06334771a3 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -4185,7 +4185,22 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
>>   	}
>>   	rcu_read_unlock();
>>
>> -	if (start + size <= ac->ac_o_ex.fe_logical &&
>> +	/*
>> +	 * In this function "start" and "size" are normalized for better
>> +	 * alignment and length such that we could preallocate more blocks.
>> +	 * This normalization is done such that original request of
>> +	 * ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and
>> +	 * "size" boundaries.
>> +	 * (Note fe_len can be relaxed since FS block allocation API does not
>> +	 * provide gurantee on number of contiguous blocks allocation since that
>> +	 * depends upon free space left, etc).
>> +	 * In case of inode pa, later we use the allocated blocks
>> +	 * [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated
>> +	 * range of goal/best blocks [start, size] to put it at the
>> +	 * ac_o_ex.fe_logical extent of this inode.
>> +	 * (See ext4_mb_use_inode_pa() for more details)
>> +	 */
>> +	if (start + size <= ac->ac_o_ex.fe_logical ||
>>   			start > ac->ac_o_ex.fe_logical) {
>>   		ext4_msg(ac->ac_sb, KERN_ERR,
>>   			 "start %lu, size %lu, fe_logical %lu",
>> --
>> 2.31.1
>>
> .

Thank you for your review!
-- 
With Best Regards,
Baokun Li


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/3] ext4: support flex_bg in ext4_mb_normalize_request
  2022-05-28 15:09   ` Ritesh Harjani
@ 2022-05-30  2:35     ` Baokun Li
  0 siblings, 0 replies; 12+ messages in thread
From: Baokun Li @ 2022-05-30  2:35 UTC (permalink / raw)
  To: Ritesh Harjani
  Cc: linux-ext4, tytso, adilger.kernel, jack, lczerner, linux-kernel,
	yi.zhang, yebin10, yukuai3, Baokun Li

在 2022/5/28 23:09, Ritesh Harjani 写道:
> On 22/05/28 07:00PM, Baokun Li wrote:
>> In ext4_mb_normalize_request, the size of the allocation request is
>> limited to no more than EXT4_BLOCKS_PER_GROUP. Ritesh mentions that this
>> does not take into account the case of flex_bg groups. So we should add
>> support for flex_bg to make the physical blocks of large files contiguous.
> My only concern here was that what if we are at the flex group end boundary and
> decide to take the size as of flex group size. How are we detecting that case.
>
> But, I haven't yet looked at this patch of yours (as I am on travel for next few days),
> but if this requires further discussion, we can work on this seperately and let
> the other two patches go in as those are part of the bug fixes which you
> identified (just my thoughts).
>
> -ritesh
> .

All right, work on this separately.

Have a nice trip!

-- 
With Best Regards,
Baokun Li


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request
  2022-05-28 11:00 [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
                   ` (2 preceding siblings ...)
  2022-05-28 11:00 ` [PATCH v3 3/3] ext4: support flex_bg " Baokun Li
@ 2022-06-18  2:12 ` Theodore Ts'o
  3 siblings, 0 replies; 12+ messages in thread
From: Theodore Ts'o @ 2022-06-18  2:12 UTC (permalink / raw)
  To: linux-ext4, Baokun Li
  Cc: Theodore Ts'o, lczerner, yukuai3, yebin10, linux-kernel,
	adilger.kernel, yi.zhang, jack, ritesh.list

On Sat, 28 May 2022 19:00:14 +0800, Baokun Li wrote:
> The logical block map reached before the problem stack was 1011.
> The estimated location of the size logical block of the inde plus
> the required allocation length 7, the size is 1018.
> 
> But the i_size of inode is 1299, so the size is 1299,
> the aligned size is 2048, and the end is 2048.
> Because of the restriction of ar -> pleft, start==648.
> 
> [...]

I've applied the first two patches, thanks!

[1/3] ext4: fix bug_on ext4_mb_use_inode_pa
      commit: 0fb337007c8cbdaef5bed798c30a82723f97f4cb
[2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request
      commit: d1389cc90702fea565a6efd4d1d0c5c8fe1cc317

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/3] ext4: support flex_bg in ext4_mb_normalize_request
@ 2022-05-29  5:26 kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-29  5:26 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 35464 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220528110017.354175-4-libaokun1@huawei.com>
References: <20220528110017.354175-4-libaokun1@huawei.com>
TO: Baokun Li <libaokun1@huawei.com>
TO: linux-ext4(a)vger.kernel.org
CC: tytso(a)mit.edu
CC: adilger.kernel(a)dilger.ca
CC: jack(a)suse.cz
CC: ritesh.list(a)gmail.com
CC: lczerner(a)redhat.com
CC: linux-kernel(a)vger.kernel.org
CC: yi.zhang(a)huawei.com
CC: yebin10(a)huawei.com
CC: yukuai3(a)huawei.com
CC: libaokun1(a)huawei.com

Hi Baokun,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v5.18 next-20220527]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Baokun-Li/ext4-fix-two-bugs-in-ext4_mb_normalize_request/20220528-184745
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 18 hours ago
:::::: commit date: 18 hours ago
config: i386-randconfig-c001 (https://download.01.org/0day-ci/archive/20220529/202205291323.QpmoZoIc-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 0fbe3f3f486e01448121f7931a4ca29fac1504ab)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/24640234aaeae85de0c1b9eadec0fa29eee5927a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Baokun-Li/ext4-fix-two-bugs-in-ext4_mb_normalize_request/20220528-184745
        git checkout 24640234aaeae85de0c1b9eadec0fa29eee5927a
        # save the config file
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^                    ~~~~
   fs/ext4/mballoc.c:1295:4: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           memset(grinfo->bb_counters, 0,
                           ^
   arch/x86/include/asm/string_32.h:195:29: note: expanded from macro 'memset'
   #define memset(s, c, count) __builtin_memset(s, c, count)
                               ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:1295:4: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
                           memset(grinfo->bb_counters, 0,
                           ^
   arch/x86/include/asm/string_32.h:195:29: note: expanded from macro 'memset'
   #define memset(s, c, count) __builtin_memset(s, c, count)
                               ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:1303:4: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           memset(data, 0xff, blocksize);
                           ^
   arch/x86/include/asm/string_32.h:195:29: note: expanded from macro 'memset'
   #define memset(s, c, count) __builtin_memset(s, c, count)
                               ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:1303:4: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11
                           memset(data, 0xff, blocksize);
                           ^
   arch/x86/include/asm/string_32.h:195:29: note: expanded from macro 'memset'
   #define memset(s, c, count) __builtin_memset(s, c, count)
                               ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:1316:4: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           memcpy(data, bitmap, blocksize);
                           ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:1316:4: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                           memcpy(data, bitmap, blocksize);
                           ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:2612:27: warning: Value stored to 'grp' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
                   struct ext4_group_info *grp = ext4_get_group_info(sb, group);
                                           ^~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:2612:27: note: Value stored to 'grp' during its initialization is never read
                   struct ext4_group_info *grp = ext4_get_group_info(sb, group);
                                           ^~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:2891:2: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           memcpy(&sg, ext4_get_group_info(sb, group), i);
           ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:2891:2: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
           memcpy(&sg, ext4_get_group_info(sb, group), i);
           ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:3103:3: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   memcpy(new_groupinfo, old_groupinfo,
                   ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:3103:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                   memcpy(new_groupinfo, old_groupinfo,
                   ^
   arch/x86/include/asm/string_32.h:150:25: note: expanded from macro 'memcpy'
   #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                           ^~~~~~~~~~~~~~~~
   fs/ext4/mballoc.c:3994:2: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
           if (err)
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^                    ~~~~
   fs/ext4/mballoc.c:3899:9: note: 'err' declared without an initial value
           int i, err;
                  ^~~
   fs/ext4/mballoc.c:3903:9: note: Assuming 'len' is <= 0
           while (len > 0) {
                  ^~~~~~~
   fs/ext4/mballoc.c:3903:2: note: Loop condition is false. Execution continues on line 3994
           while (len > 0) {
           ^
   fs/ext4/mballoc.c:3994:2: note: 1st function call argument is an uninitialized value
           if (err)
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^                    ~~~~
>> fs/ext4/mballoc.c:4119:21: warning: Division by zero [clang-analyzer-core.DivideZero]
           start = max(start, rounddown(ac->ac_o_ex.fe_logical, bpg));
                              ^
   include/linux/math.h:76:13: note: expanded from macro 'rounddown'
           __x - (__x % (y));                              \
                      ^
   include/linux/minmax.h:52:36: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(x, y, >)
                           ~~~~~~~~~~~~~~~~~^~~~~
   include/linux/minmax.h:38:17: note: expanded from macro '__careful_cmp'
                   __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:32:25: note: expanded from macro '__cmp_once'
                   typeof(y) unique_y = (y);               \
                                         ^
   fs/ext4/mballoc.c:4037:6: note: Assuming the condition is false
           if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
               ^
   include/linux/compiler.h:56:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                      ^~~~
   fs/ext4/mballoc.c:4037:2: note: '?' condition is false
           if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   fs/ext4/mballoc.c:4037:2: note: '?' condition is false
           if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                       ^
   include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value'
           (cond) ?                                        \
           ^
   fs/ext4/mballoc.c:4037:2: note: Taking false branch
           if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
           ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   fs/ext4/mballoc.c:4041:6: note: Assuming the condition is true
           if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
               ^
   include/linux/compiler.h:48:24: note: expanded from macro 'unlikely'
   #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
                            ^
   include/linux/compiler.h:33:32: note: expanded from macro '__branch_check__'
                           ______r = __builtin_expect(!!(x), expect);      \
                                                       ^
   include/linux/compiler.h:56:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                      ^~~~
   fs/ext4/mballoc.c:4041:2: note: '?' condition is false
           if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   fs/ext4/mballoc.c:4041:2: note: '?' condition is false
           if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                       ^
   include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value'
           (cond) ?                                        \
           ^
   fs/ext4/mballoc.c:4041:2: note: Taking false branch
           if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
           ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   fs/ext4/mballoc.c:4046:2: note: Assuming the condition is true
           if (ac->ac_flags & EXT4_MB_HINT_NOPREALLOC)
           ^
   include/linux/compiler.h:56:45: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))

vim +4119 fs/ext4/mballoc.c

c9de560ded61fa Alex Tomas       2008-01-29  4016  
c9de560ded61fa Alex Tomas       2008-01-29  4017  /*
c9de560ded61fa Alex Tomas       2008-01-29  4018   * Normalization means making request better in terms of
c9de560ded61fa Alex Tomas       2008-01-29  4019   * size and alignment
c9de560ded61fa Alex Tomas       2008-01-29  4020   */
4ddfef7b41aebb Eric Sandeen     2008-04-29  4021  static noinline_for_stack void
4ddfef7b41aebb Eric Sandeen     2008-04-29  4022  ext4_mb_normalize_request(struct ext4_allocation_context *ac,
c9de560ded61fa Alex Tomas       2008-01-29  4023  				struct ext4_allocation_request *ar)
c9de560ded61fa Alex Tomas       2008-01-29  4024  {
53accfa9f819c8 Theodore Ts'o    2011-09-09  4025  	struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
c9de560ded61fa Alex Tomas       2008-01-29  4026  	int bsbits, max;
c9de560ded61fa Alex Tomas       2008-01-29  4027  	ext4_lblk_t end;
1592d2c5574eda Curt Wohlgemuth  2012-02-20  4028  	loff_t size, start_off;
1592d2c5574eda Curt Wohlgemuth  2012-02-20  4029  	loff_t orig_size __maybe_unused;
5a0790c2c4a184 Andi Kleen       2010-06-14  4030  	ext4_lblk_t start;
24640234aaeae8 Baokun Li        2022-05-28  4031  	ext4_lblk_t bpg;
c9de560ded61fa Alex Tomas       2008-01-29  4032  	struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
9a0762c5af40e4 Aneesh Kumar K.V 2008-04-17  4033  	struct ext4_prealloc_space *pa;
c9de560ded61fa Alex Tomas       2008-01-29  4034  
c9de560ded61fa Alex Tomas       2008-01-29  4035  	/* do normalize only data requests, metadata requests
c9de560ded61fa Alex Tomas       2008-01-29  4036  	   do not need preallocation */
c9de560ded61fa Alex Tomas       2008-01-29  4037  	if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
c9de560ded61fa Alex Tomas       2008-01-29  4038  		return;
c9de560ded61fa Alex Tomas       2008-01-29  4039  
c9de560ded61fa Alex Tomas       2008-01-29  4040  	/* sometime caller may want exact blocks */
c9de560ded61fa Alex Tomas       2008-01-29  4041  	if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
c9de560ded61fa Alex Tomas       2008-01-29  4042  		return;
c9de560ded61fa Alex Tomas       2008-01-29  4043  
c9de560ded61fa Alex Tomas       2008-01-29  4044  	/* caller may indicate that preallocation isn't
c9de560ded61fa Alex Tomas       2008-01-29  4045  	 * required (it's a tail, for example) */
c9de560ded61fa Alex Tomas       2008-01-29  4046  	if (ac->ac_flags & EXT4_MB_HINT_NOPREALLOC)
c9de560ded61fa Alex Tomas       2008-01-29  4047  		return;
c9de560ded61fa Alex Tomas       2008-01-29  4048  
c9de560ded61fa Alex Tomas       2008-01-29  4049  	if (ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC) {
c9de560ded61fa Alex Tomas       2008-01-29  4050  		ext4_mb_normalize_group_request(ac);
c9de560ded61fa Alex Tomas       2008-01-29  4051  		return ;
c9de560ded61fa Alex Tomas       2008-01-29  4052  	}
c9de560ded61fa Alex Tomas       2008-01-29  4053  
c9de560ded61fa Alex Tomas       2008-01-29  4054  	bsbits = ac->ac_sb->s_blocksize_bits;
24640234aaeae8 Baokun Li        2022-05-28  4055  	bpg = EXT4_BLOCKS_PER_GROUP(ac->ac_sb);
24640234aaeae8 Baokun Li        2022-05-28  4056  	if (ext4_has_feature_flex_bg(ac->ac_sb) && sbi->s_log_groups_per_flex) {
24640234aaeae8 Baokun Li        2022-05-28  4057  		if (check_shl_overflow(bpg, sbi->s_log_groups_per_flex, &bpg))
24640234aaeae8 Baokun Li        2022-05-28  4058  			bpg = EXT_MAX_BLOCKS;
24640234aaeae8 Baokun Li        2022-05-28  4059  	}
c9de560ded61fa Alex Tomas       2008-01-29  4060  
c9de560ded61fa Alex Tomas       2008-01-29  4061  	/* first, let's learn actual file size
c9de560ded61fa Alex Tomas       2008-01-29  4062  	 * given current request is allocated */
53accfa9f819c8 Theodore Ts'o    2011-09-09  4063  	size = ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len);
c9de560ded61fa Alex Tomas       2008-01-29  4064  	size = size << bsbits;
c9de560ded61fa Alex Tomas       2008-01-29  4065  	if (size < i_size_read(ac->ac_inode))
c9de560ded61fa Alex Tomas       2008-01-29  4066  		size = i_size_read(ac->ac_inode);
5a0790c2c4a184 Andi Kleen       2010-06-14  4067  	orig_size = size;
c9de560ded61fa Alex Tomas       2008-01-29  4068  
1930479c4b6bbc Valerie Clement  2008-05-13  4069  	/* max size of free chunks */
1930479c4b6bbc Valerie Clement  2008-05-13  4070  	max = 2 << bsbits;
c9de560ded61fa Alex Tomas       2008-01-29  4071  
1930479c4b6bbc Valerie Clement  2008-05-13  4072  #define NRL_CHECK_SIZE(req, size, max, chunk_size)	\
1930479c4b6bbc Valerie Clement  2008-05-13  4073  		(req <= (size) || max <= (chunk_size))
c9de560ded61fa Alex Tomas       2008-01-29  4074  
c9de560ded61fa Alex Tomas       2008-01-29  4075  	/* first, try to predict filesize */
c9de560ded61fa Alex Tomas       2008-01-29  4076  	/* XXX: should this table be tunable? */
c9de560ded61fa Alex Tomas       2008-01-29  4077  	start_off = 0;
c9de560ded61fa Alex Tomas       2008-01-29  4078  	if (size <= 16 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4079  		size = 16 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4080  	} else if (size <= 32 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4081  		size = 32 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4082  	} else if (size <= 64 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4083  		size = 64 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4084  	} else if (size <= 128 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4085  		size = 128 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4086  	} else if (size <= 256 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4087  		size = 256 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4088  	} else if (size <= 512 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4089  		size = 512 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4090  	} else if (size <= 1024 * 1024) {
c9de560ded61fa Alex Tomas       2008-01-29  4091  		size = 1024 * 1024;
1930479c4b6bbc Valerie Clement  2008-05-13  4092  	} else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
c9de560ded61fa Alex Tomas       2008-01-29  4093  		start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
1930479c4b6bbc Valerie Clement  2008-05-13  4094  						(21 - bsbits)) << 21;
1930479c4b6bbc Valerie Clement  2008-05-13  4095  		size = 2 * 1024 * 1024;
1930479c4b6bbc Valerie Clement  2008-05-13  4096  	} else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
c9de560ded61fa Alex Tomas       2008-01-29  4097  		start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
c9de560ded61fa Alex Tomas       2008-01-29  4098  							(22 - bsbits)) << 22;
c9de560ded61fa Alex Tomas       2008-01-29  4099  		size = 4 * 1024 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4100  	} else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len,
1930479c4b6bbc Valerie Clement  2008-05-13  4101  					(8<<20)>>bsbits, max, 8 * 1024)) {
c9de560ded61fa Alex Tomas       2008-01-29  4102  		start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
c9de560ded61fa Alex Tomas       2008-01-29  4103  							(23 - bsbits)) << 23;
c9de560ded61fa Alex Tomas       2008-01-29  4104  		size = 8 * 1024 * 1024;
c9de560ded61fa Alex Tomas       2008-01-29  4105  	} else {
c9de560ded61fa Alex Tomas       2008-01-29  4106  		start_off = (loff_t) ac->ac_o_ex.fe_logical << bsbits;
b27b1535acc0e9 Xiaoguang Wang   2014-07-27  4107  		size	  = (loff_t) EXT4_C2B(EXT4_SB(ac->ac_sb),
b27b1535acc0e9 Xiaoguang Wang   2014-07-27  4108  					      ac->ac_o_ex.fe_len) << bsbits;
c9de560ded61fa Alex Tomas       2008-01-29  4109  	}
5a0790c2c4a184 Andi Kleen       2010-06-14  4110  	size = size >> bsbits;
5a0790c2c4a184 Andi Kleen       2010-06-14  4111  	start = start_off >> bsbits;
c9de560ded61fa Alex Tomas       2008-01-29  4112  
b0c3a326d0bc0b Baokun Li        2022-05-28  4113  	/*
b0c3a326d0bc0b Baokun Li        2022-05-28  4114  	 * For tiny groups (smaller than 8MB) the chosen allocation
b0c3a326d0bc0b Baokun Li        2022-05-28  4115  	 * alignment may be larger than group size. Make sure the
b0c3a326d0bc0b Baokun Li        2022-05-28  4116  	 * alignment does not move allocation to a different group which
b0c3a326d0bc0b Baokun Li        2022-05-28  4117  	 * makes mballoc fail assertions later.
b0c3a326d0bc0b Baokun Li        2022-05-28  4118  	 */
24640234aaeae8 Baokun Li        2022-05-28 @4119  	start = max(start, rounddown(ac->ac_o_ex.fe_logical, bpg));
b0c3a326d0bc0b Baokun Li        2022-05-28  4120  
c9de560ded61fa Alex Tomas       2008-01-29  4121  	/* don't cover already allocated blocks in selected range */
c9de560ded61fa Alex Tomas       2008-01-29  4122  	if (ar->pleft && start <= ar->lleft) {
c9de560ded61fa Alex Tomas       2008-01-29  4123  		size -= ar->lleft + 1 - start;
c9de560ded61fa Alex Tomas       2008-01-29  4124  		start = ar->lleft + 1;
c9de560ded61fa Alex Tomas       2008-01-29  4125  	}
c9de560ded61fa Alex Tomas       2008-01-29  4126  	if (ar->pright && start + size - 1 >= ar->lright)
c9de560ded61fa Alex Tomas       2008-01-29  4127  		size -= start + size - ar->lright;
c9de560ded61fa Alex Tomas       2008-01-29  4128  
cd648b8a8fd507 Jan Kara         2017-01-27  4129  	/*
cd648b8a8fd507 Jan Kara         2017-01-27  4130  	 * Trim allocation request for filesystems with artificially small
cd648b8a8fd507 Jan Kara         2017-01-27  4131  	 * groups.
cd648b8a8fd507 Jan Kara         2017-01-27  4132  	 */
24640234aaeae8 Baokun Li        2022-05-28  4133  	if (size > bpg)
24640234aaeae8 Baokun Li        2022-05-28  4134  		size = bpg;
cd648b8a8fd507 Jan Kara         2017-01-27  4135  
c9de560ded61fa Alex Tomas       2008-01-29  4136  	end = start + size;
c9de560ded61fa Alex Tomas       2008-01-29  4137  
c9de560ded61fa Alex Tomas       2008-01-29  4138  	/* check we don't cross already preallocated blocks */
c9de560ded61fa Alex Tomas       2008-01-29  4139  	rcu_read_lock();
9a0762c5af40e4 Aneesh Kumar K.V 2008-04-17  4140  	list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
498e5f24158da7 Theodore Ts'o    2008-11-05  4141  		ext4_lblk_t pa_end;
c9de560ded61fa Alex Tomas       2008-01-29  4142  
c9de560ded61fa Alex Tomas       2008-01-29  4143  		if (pa->pa_deleted)
c9de560ded61fa Alex Tomas       2008-01-29  4144  			continue;
c9de560ded61fa Alex Tomas       2008-01-29  4145  		spin_lock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4146  		if (pa->pa_deleted) {
c9de560ded61fa Alex Tomas       2008-01-29  4147  			spin_unlock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4148  			continue;
c9de560ded61fa Alex Tomas       2008-01-29  4149  		}
c9de560ded61fa Alex Tomas       2008-01-29  4150  
53accfa9f819c8 Theodore Ts'o    2011-09-09  4151  		pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb),
53accfa9f819c8 Theodore Ts'o    2011-09-09  4152  						  pa->pa_len);
c9de560ded61fa Alex Tomas       2008-01-29  4153  
c9de560ded61fa Alex Tomas       2008-01-29  4154  		/* PA must not overlap original request */
c9de560ded61fa Alex Tomas       2008-01-29  4155  		BUG_ON(!(ac->ac_o_ex.fe_logical >= pa_end ||
c9de560ded61fa Alex Tomas       2008-01-29  4156  			ac->ac_o_ex.fe_logical < pa->pa_lstart));
c9de560ded61fa Alex Tomas       2008-01-29  4157  
38877f4e8dbbec Eric Sandeen     2009-08-17  4158  		/* skip PAs this normalized request doesn't overlap with */
38877f4e8dbbec Eric Sandeen     2009-08-17  4159  		if (pa->pa_lstart >= end || pa_end <= start) {
c9de560ded61fa Alex Tomas       2008-01-29  4160  			spin_unlock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4161  			continue;
c9de560ded61fa Alex Tomas       2008-01-29  4162  		}
c9de560ded61fa Alex Tomas       2008-01-29  4163  		BUG_ON(pa->pa_lstart <= start && pa_end >= end);
c9de560ded61fa Alex Tomas       2008-01-29  4164  
38877f4e8dbbec Eric Sandeen     2009-08-17  4165  		/* adjust start or end to be adjacent to this pa */
c9de560ded61fa Alex Tomas       2008-01-29  4166  		if (pa_end <= ac->ac_o_ex.fe_logical) {
c9de560ded61fa Alex Tomas       2008-01-29  4167  			BUG_ON(pa_end < start);
c9de560ded61fa Alex Tomas       2008-01-29  4168  			start = pa_end;
38877f4e8dbbec Eric Sandeen     2009-08-17  4169  		} else if (pa->pa_lstart > ac->ac_o_ex.fe_logical) {
c9de560ded61fa Alex Tomas       2008-01-29  4170  			BUG_ON(pa->pa_lstart > end);
c9de560ded61fa Alex Tomas       2008-01-29  4171  			end = pa->pa_lstart;
c9de560ded61fa Alex Tomas       2008-01-29  4172  		}
c9de560ded61fa Alex Tomas       2008-01-29  4173  		spin_unlock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4174  	}
c9de560ded61fa Alex Tomas       2008-01-29  4175  	rcu_read_unlock();
c9de560ded61fa Alex Tomas       2008-01-29  4176  	size = end - start;
c9de560ded61fa Alex Tomas       2008-01-29  4177  
c9de560ded61fa Alex Tomas       2008-01-29  4178  	/* XXX: extra loop to check we really don't overlap preallocations */
c9de560ded61fa Alex Tomas       2008-01-29  4179  	rcu_read_lock();
9a0762c5af40e4 Aneesh Kumar K.V 2008-04-17  4180  	list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
498e5f24158da7 Theodore Ts'o    2008-11-05  4181  		ext4_lblk_t pa_end;
53accfa9f819c8 Theodore Ts'o    2011-09-09  4182  
c9de560ded61fa Alex Tomas       2008-01-29  4183  		spin_lock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4184  		if (pa->pa_deleted == 0) {
53accfa9f819c8 Theodore Ts'o    2011-09-09  4185  			pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb),
53accfa9f819c8 Theodore Ts'o    2011-09-09  4186  							  pa->pa_len);
c9de560ded61fa Alex Tomas       2008-01-29  4187  			BUG_ON(!(start >= pa_end || end <= pa->pa_lstart));
c9de560ded61fa Alex Tomas       2008-01-29  4188  		}
c9de560ded61fa Alex Tomas       2008-01-29  4189  		spin_unlock(&pa->pa_lock);
c9de560ded61fa Alex Tomas       2008-01-29  4190  	}
c9de560ded61fa Alex Tomas       2008-01-29  4191  	rcu_read_unlock();
c9de560ded61fa Alex Tomas       2008-01-29  4192  
7354605bc16dc1 Baokun Li        2022-05-28  4193  	/*
7354605bc16dc1 Baokun Li        2022-05-28  4194  	 * In this function "start" and "size" are normalized for better
7354605bc16dc1 Baokun Li        2022-05-28  4195  	 * alignment and length such that we could preallocate more blocks.
7354605bc16dc1 Baokun Li        2022-05-28  4196  	 * This normalization is done such that original request of
7354605bc16dc1 Baokun Li        2022-05-28  4197  	 * ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and
7354605bc16dc1 Baokun Li        2022-05-28  4198  	 * "size" boundaries.
7354605bc16dc1 Baokun Li        2022-05-28  4199  	 * (Note fe_len can be relaxed since FS block allocation API does not
7354605bc16dc1 Baokun Li        2022-05-28  4200  	 * provide gurantee on number of contiguous blocks allocation since that
7354605bc16dc1 Baokun Li        2022-05-28  4201  	 * depends upon free space left, etc).
7354605bc16dc1 Baokun Li        2022-05-28  4202  	 * In case of inode pa, later we use the allocated blocks
7354605bc16dc1 Baokun Li        2022-05-28  4203  	 * [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated
7354605bc16dc1 Baokun Li        2022-05-28  4204  	 * range of goal/best blocks [start, size] to put it at the
7354605bc16dc1 Baokun Li        2022-05-28  4205  	 * ac_o_ex.fe_logical extent of this inode.
7354605bc16dc1 Baokun Li        2022-05-28  4206  	 * (See ext4_mb_use_inode_pa() for more details)
7354605bc16dc1 Baokun Li        2022-05-28  4207  	 */
7354605bc16dc1 Baokun Li        2022-05-28  4208  	if (start + size <= ac->ac_o_ex.fe_logical ||
c9de560ded61fa Alex Tomas       2008-01-29  4209  			start > ac->ac_o_ex.fe_logical) {
9d8b9ec44234b2 Theodore Ts'o    2011-08-01  4210  		ext4_msg(ac->ac_sb, KERN_ERR,
9d8b9ec44234b2 Theodore Ts'o    2011-08-01  4211  			 "start %lu, size %lu, fe_logical %lu",
c9de560ded61fa Alex Tomas       2008-01-29  4212  			 (unsigned long) start, (unsigned long) size,
c9de560ded61fa Alex Tomas       2008-01-29  4213  			 (unsigned long) ac->ac_o_ex.fe_logical);
dfe076c106f63c Dmitry Monakhov  2014-10-01  4214  		BUG();
c9de560ded61fa Alex Tomas       2008-01-29  4215  	}
24640234aaeae8 Baokun Li        2022-05-28  4216  	BUG_ON(size <= 0 || size > bpg);
c9de560ded61fa Alex Tomas       2008-01-29  4217  
c9de560ded61fa Alex Tomas       2008-01-29  4218  	/* now prepare goal request */
c9de560ded61fa Alex Tomas       2008-01-29  4219  
c9de560ded61fa Alex Tomas       2008-01-29  4220  	/* XXX: is it better to align blocks WRT to logical
c9de560ded61fa Alex Tomas       2008-01-29  4221  	 * placement or satisfy big request as is */
c9de560ded61fa Alex Tomas       2008-01-29  4222  	ac->ac_g_ex.fe_logical = start;
53accfa9f819c8 Theodore Ts'o    2011-09-09  4223  	ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size);
c9de560ded61fa Alex Tomas       2008-01-29  4224  
c9de560ded61fa Alex Tomas       2008-01-29  4225  	/* define goal start in order to merge */
c9de560ded61fa Alex Tomas       2008-01-29  4226  	if (ar->pright && (ar->lright == (start + size))) {
c9de560ded61fa Alex Tomas       2008-01-29  4227  		/* merge to the right */
c9de560ded61fa Alex Tomas       2008-01-29  4228  		ext4_get_group_no_and_offset(ac->ac_sb, ar->pright - size,
c9de560ded61fa Alex Tomas       2008-01-29  4229  						&ac->ac_f_ex.fe_group,
c9de560ded61fa Alex Tomas       2008-01-29  4230  						&ac->ac_f_ex.fe_start);
c9de560ded61fa Alex Tomas       2008-01-29  4231  		ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
c9de560ded61fa Alex Tomas       2008-01-29  4232  	}
c9de560ded61fa Alex Tomas       2008-01-29  4233  	if (ar->pleft && (ar->lleft + 1 == start)) {
c9de560ded61fa Alex Tomas       2008-01-29  4234  		/* merge to the left */
c9de560ded61fa Alex Tomas       2008-01-29  4235  		ext4_get_group_no_and_offset(ac->ac_sb, ar->pleft + 1,
c9de560ded61fa Alex Tomas       2008-01-29  4236  						&ac->ac_f_ex.fe_group,
c9de560ded61fa Alex Tomas       2008-01-29  4237  						&ac->ac_f_ex.fe_start);
c9de560ded61fa Alex Tomas       2008-01-29  4238  		ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
c9de560ded61fa Alex Tomas       2008-01-29  4239  	}
c9de560ded61fa Alex Tomas       2008-01-29  4240  
d3df14535f4a5b Ritesh Harjani   2020-05-10  4241  	mb_debug(ac->ac_sb, "goal: %lld(was %lld) blocks at %u\n", size,
d3df14535f4a5b Ritesh Harjani   2020-05-10  4242  		 orig_size, start);
c9de560ded61fa Alex Tomas       2008-01-29  4243  }
c9de560ded61fa Alex Tomas       2008-01-29  4244  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-06-18  2:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 11:00 [PATCH v3 0/3] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
2022-05-28 11:00 ` [PATCH v3 1/3] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
2022-05-28 15:10   ` Ritesh Harjani
2022-05-30  2:12     ` Baokun Li
2022-05-28 11:00 ` [PATCH v3 2/3] ext4: correct the judgment of BUG in ext4_mb_normalize_request Baokun Li
2022-05-28 15:12   ` Ritesh Harjani
2022-05-30  2:13     ` Baokun Li
2022-05-28 11:00 ` [PATCH v3 3/3] ext4: support flex_bg " Baokun Li
2022-05-28 15:09   ` Ritesh Harjani
2022-05-30  2:35     ` Baokun Li
2022-06-18  2:12 ` [PATCH v3 0/3] ext4: fix two bugs " Theodore Ts'o
2022-05-29  5:26 [PATCH v3 3/3] ext4: support flex_bg " kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.