Commit d1a3924e authored by Kemeng Shi's avatar Kemeng Shi Committed by Theodore Ts'o

ext4: call ext4_mb_mark_free_simple to free continuous bits in found chunk

In mb_mark_used, we will find free chunk and mark it inuse. For chunk
in mid of passed range, we could simply mark whole chunk inuse. For chunk
at end of range, we may need to mark a continuous bits at end of part of
chunk inuse and keep rest part of chunk free. To only mark a part of
chunk inuse, we firstly mark whole chunk inuse and then mark a continuous
range at end of chunk free.
Function mb_mark_used does several times of "mb_find_buddy; mb_clear_bit;
..." to mark a continuous range free which can be done by simply calling
ext4_mb_mark_free_simple which free continuous bits in a more effective
way.
Just call ext4_mb_mark_free_simple in mb_mark_used to use existing and
effective code to free continuous blocks in chunk at end of passed range.
Signed-off-by: default avatarKemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240424061904.987525-4-shikemeng@huaweicloud.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent d0b88624
...@@ -2044,13 +2044,12 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) ...@@ -2044,13 +2044,12 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
int ord; int ord;
int mlen = 0; int mlen = 0;
int max = 0; int max = 0;
int cur;
int start = ex->fe_start; int start = ex->fe_start;
int len = ex->fe_len; int len = ex->fe_len;
unsigned ret = 0; unsigned ret = 0;
int len0 = len; int len0 = len;
void *buddy; void *buddy;
bool split = false; int ord_start, ord_end;
BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3)); BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3));
BUG_ON(e4b->bd_group != ex->fe_group); BUG_ON(e4b->bd_group != ex->fe_group);
...@@ -2075,16 +2074,12 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) ...@@ -2075,16 +2074,12 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
/* let's maintain buddy itself */ /* let's maintain buddy itself */
while (len) { while (len) {
if (!split) ord = mb_find_order_for_block(e4b, start);
ord = mb_find_order_for_block(e4b, start);
if (((start >> ord) << ord) == start && len >= (1 << ord)) { if (((start >> ord) << ord) == start && len >= (1 << ord)) {
/* the whole chunk may be allocated at once! */ /* the whole chunk may be allocated at once! */
mlen = 1 << ord; mlen = 1 << ord;
if (!split) buddy = mb_find_buddy(e4b, ord, &max);
buddy = mb_find_buddy(e4b, ord, &max);
else
split = false;
BUG_ON((start >> ord) >= max); BUG_ON((start >> ord) >= max);
mb_set_bit(start >> ord, buddy); mb_set_bit(start >> ord, buddy);
e4b->bd_info->bb_counters[ord]--; e4b->bd_info->bb_counters[ord]--;
...@@ -2098,20 +2093,29 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) ...@@ -2098,20 +2093,29 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
if (ret == 0) if (ret == 0)
ret = len | (ord << 16); ret = len | (ord << 16);
/* we have to split large buddy */
BUG_ON(ord <= 0); BUG_ON(ord <= 0);
buddy = mb_find_buddy(e4b, ord, &max); buddy = mb_find_buddy(e4b, ord, &max);
mb_set_bit(start >> ord, buddy); mb_set_bit(start >> ord, buddy);
e4b->bd_info->bb_counters[ord]--; e4b->bd_info->bb_counters[ord]--;
ord--; ord_start = (start >> ord) << ord;
cur = (start >> ord) & ~1U; ord_end = ord_start + (1 << ord);
buddy = mb_find_buddy(e4b, ord, &max); /* first chunk */
mb_clear_bit(cur, buddy); if (start > ord_start)
mb_clear_bit(cur + 1, buddy); ext4_mb_mark_free_simple(e4b->bd_sb, e4b->bd_buddy,
e4b->bd_info->bb_counters[ord]++; ord_start, start - ord_start,
e4b->bd_info->bb_counters[ord]++; e4b->bd_info);
split = true;
/* last chunk */
if (start + len < ord_end) {
ext4_mb_mark_free_simple(e4b->bd_sb, e4b->bd_buddy,
start + len,
ord_end - (start + len),
e4b->bd_info);
break;
}
len = start + len - ord_end;
start = ord_end;
} }
mb_set_largest_free_order(e4b->bd_sb, e4b->bd_info); mb_set_largest_free_order(e4b->bd_sb, e4b->bd_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment