Hi everyone,
This patchset includes two bug fixes related to bitmap percpu memory
allocator.
The first is a problem with how the start offset is managed in bytes, but
the bitmaps are traversed in bits. The start offset is maintained to keep
alignment true within the actual allocation area in the chunk. With the
reserved and dynamic chunk, this may unintentionally skip over a portion
proportional to the start offset and PCPU_MIN_ALLOC_SIZE.
The second is an issue reported by Luis in [1]. The allocator was unable
to allocate from the reserved chunk due to the block offset not being
reset within the iterator. This caused subsequently checked blocks to
check against a potentially higher block offset. This may lead the
iterator to believe it had checked this area in the prior iteration. The
fix is to simply reset the block offset to 0 after it is used allowing
the predicate to always evaluate to true for subsequent blocks.
[1] https://lkml.org/lkml/2017/9/26/506
This patchset contains the following 2 patches:
0001-percpu-fix-starting-offset-for-chunk-statistics-trav.patch
0002-percpu-fix-iteration-to-prevent-skipping-over-block.patch
0001 fixes the chunk start offset issue. 0002 fixes the iteration bug.
This patchset is on top of linus#v4.14-rc2 e19b205be4.
diffstats below:
Dennis Zhou (2):
percpu: fix starting offset for chunk statistics traversal
percpu: fix iteration to prevent skipping over block
mm/percpu-stats.c | 2 +-
mm/percpu.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
Thanks,
Dennis
This patch fixes the starting offset used when scanning chunks to
compute the chunk statistics. The value start_offset (and end_offset)
are managed in bytes while the traversal occurs over bits. Thus for the
reserved and dynamic chunk, it may incorrectly skip over the initial
allocations.
Signed-off-by: Dennis Zhou <[email protected]>
---
mm/percpu-stats.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/percpu-stats.c b/mm/percpu-stats.c
index 6142484..7a58460 100644
--- a/mm/percpu-stats.c
+++ b/mm/percpu-stats.c
@@ -73,7 +73,7 @@ static void chunk_map_stats(struct seq_file *m, struct pcpu_chunk *chunk,
last_alloc + 1 : 0;
as_len = 0;
- start = chunk->start_offset;
+ start = chunk->start_offset / PCPU_MIN_ALLOC_SIZE;
/*
* If a bit is set in the allocation map, the bound_map identifies
--
1.8.3.1
The iterator functions pcpu_next_md_free_region and
pcpu_next_fit_region use the block offset to determine if they have
checked the area in the prior iteration. However, this causes an issue
when the block offset is greater than subsequent block contig hints. If
within the iterator it moves to check subsequent blocks, it may fail in
the second predicate due to the block offset not being cleared. Thus,
this causes the allocator to skip over blocks leading to false failures
when allocating from the reserved chunk. While this happens in the
general case as well, it will only fail if it cannot allocate a new
chunk.
This patch resets the block offset to 0 to pass the second predicate
when checking subseqent blocks within the iterator function.
Signed-off-by: Dennis Zhou <[email protected]>
Reported-by: Luis Henriques <[email protected]>
---
mm/percpu.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/percpu.c b/mm/percpu.c
index 59d44d6..aa121ce 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -353,6 +353,8 @@ static void pcpu_next_md_free_region(struct pcpu_chunk *chunk, int *bit_off,
block->contig_hint_start);
return;
}
+ /* reset to satisfy the second predicate above */
+ block_off = 0;
*bits = block->right_free;
*bit_off = (i + 1) * PCPU_BITMAP_BLOCK_BITS - block->right_free;
@@ -407,6 +409,8 @@ static void pcpu_next_fit_region(struct pcpu_chunk *chunk, int alloc_bits,
*bit_off = pcpu_block_off_to_off(i, block->first_free);
return;
}
+ /* reset to satisfy the second predicate above */
+ block_off = 0;
*bit_off = ALIGN(PCPU_BITMAP_BLOCK_BITS - block->right_free,
align);
--
1.8.3.1
On Wed, Sep 27, 2017 at 04:34:59PM -0500, Dennis Zhou wrote:
> This patch fixes the starting offset used when scanning chunks to
> compute the chunk statistics. The value start_offset (and end_offset)
> are managed in bytes while the traversal occurs over bits. Thus for the
> reserved and dynamic chunk, it may incorrectly skip over the initial
> allocations.
>
> Signed-off-by: Dennis Zhou <[email protected]>
Applied to percpu/for-4.14-fixes.
Thanks.
--
tejun
On Wed, Sep 27, 2017 at 04:35:00PM -0500, Dennis Zhou wrote:
> The iterator functions pcpu_next_md_free_region and
> pcpu_next_fit_region use the block offset to determine if they have
> checked the area in the prior iteration. However, this causes an issue
> when the block offset is greater than subsequent block contig hints. If
> within the iterator it moves to check subsequent blocks, it may fail in
> the second predicate due to the block offset not being cleared. Thus,
> this causes the allocator to skip over blocks leading to false failures
> when allocating from the reserved chunk. While this happens in the
> general case as well, it will only fail if it cannot allocate a new
> chunk.
>
> This patch resets the block offset to 0 to pass the second predicate
> when checking subseqent blocks within the iterator function.
>
> Signed-off-by: Dennis Zhou <[email protected]>
> Reported-by: Luis Henriques <[email protected]>
Luis, can you please verify that this fixes the allocaiton failure you
were seeing?
Thanks.
--
tejun
Tejun Heo <[email protected]> writes:
> On Wed, Sep 27, 2017 at 04:35:00PM -0500, Dennis Zhou wrote:
>> The iterator functions pcpu_next_md_free_region and
>> pcpu_next_fit_region use the block offset to determine if they have
>> checked the area in the prior iteration. However, this causes an issue
>> when the block offset is greater than subsequent block contig hints. If
>> within the iterator it moves to check subsequent blocks, it may fail in
>> the second predicate due to the block offset not being cleared. Thus,
>> this causes the allocator to skip over blocks leading to false failures
>> when allocating from the reserved chunk. While this happens in the
>> general case as well, it will only fail if it cannot allocate a new
>> chunk.
>>
>> This patch resets the block offset to 0 to pass the second predicate
>> when checking subseqent blocks within the iterator function.
>>
>> Signed-off-by: Dennis Zhou <[email protected]>
>> Reported-by: Luis Henriques <[email protected]>
>
> Luis, can you please verify that this fixes the allocaiton failure you
> were seeing?
I can confirm that I'm no longer seeing the allocation failure after
applying these patches. Feel free to add my:
Tested-by: Luis Henriques <[email protected]>
Cheers,
--
Luis
On Wed, Sep 27, 2017 at 04:35:00PM -0500, Dennis Zhou wrote:
> The iterator functions pcpu_next_md_free_region and
> pcpu_next_fit_region use the block offset to determine if they have
> checked the area in the prior iteration. However, this causes an issue
> when the block offset is greater than subsequent block contig hints. If
> within the iterator it moves to check subsequent blocks, it may fail in
> the second predicate due to the block offset not being cleared. Thus,
> this causes the allocator to skip over blocks leading to false failures
> when allocating from the reserved chunk. While this happens in the
> general case as well, it will only fail if it cannot allocate a new
> chunk.
>
> This patch resets the block offset to 0 to pass the second predicate
> when checking subseqent blocks within the iterator function.
>
> Signed-off-by: Dennis Zhou <[email protected]>
> Reported-by: Luis Henriques <[email protected]>
Applied to percpu/for-4.14-fixes.
Thanks!
--
tejun