Skip to contentSkip to conversation

percpu: fix block iterators and reserved chunk stats

PATCH Applied Dennis Zhou 3 participants 7 messages Sep 27, 2017 – Sep 28, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover percpu: fix block iterators and reserved chunk stats

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/2 percpu: fix starting offset for chunk statistics traversal

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.

---
 mm/percpu-stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/percpu-stats.c +1 -1
index 6142484..7a58460 100644
@@ -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
Signature · 7 lines
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH 2/2 percpu: fix iteration to prevent skipping over block

In reply to Dennis Zhou

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.

---
 mm/percpu.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/percpu.c +4 -0
index 59d44d6..aa121ce 100644
@@ -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);
Signature · 7 lines
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer Applied
#2 lore raw

Re: [PATCH 1/2] percpu: fix starting offset for chunk statistics traversal

In reply to Dennis Zhou
Quoted 7 lines · Dennis Zhou

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.

Applied to percpu/for-4.14-fixes.

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#4 lore raw

Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block

In reply to Dennis Zhou
Quoted 11 lines · Dennis Zhou

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.

Quoted 5 lines

This patch resets the block offset to 0 to pass the second predicate when checking subseqent blocks within the iterator function.

Luis, can you please verify that this fixes the allocaiton failure you were seeing?

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Tested-by
#5 lore raw

Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block

Quoted 12 lines · Tejun Heo
Quoted 11 lines · Dennis Zhou

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.

Quoted 8 lines
Quoted 5 lines

This patch resets the block offset to 0 to pass the second predicate when checking subseqent blocks within the iterator function.

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:

Cheers,

Signature · 7 lines
Luis

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer Applied
#6 lore raw

Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block

In reply to Dennis Zhou
Quoted 11 lines · Dennis Zhou

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.

Quoted 5 lines

This patch resets the block offset to 0 to pass the second predicate when checking subseqent blocks within the iterator function.

Applied to percpu/for-4.14-fixes.

Thanks!

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>