Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1741033 > unrolled thread

[PATCH 0/2] percpu: fix block iterators and reserved chunk stats

Started byDennis Zhou <dennisszhou@gmail.com>
First post2017-09-27 23:40 +0200
Last post2017-09-27 23:50 +0200
Articles 7 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/2] percpu: fix block iterators and reserved chunk stats Dennis Zhou <dennisszhou@gmail.com> - 2017-09-27 23:40 +0200
    [PATCH 2/2] percpu: fix iteration to prevent skipping over block Dennis Zhou <dennisszhou@gmail.com> - 2017-09-27 23:40 +0200
      Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block Tejun Heo <tj@kernel.org> - 2017-09-28 00:00 +0200
        Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block Luis Henriques <lhenriques@suse.com> - 2017-09-28 10:40 +0200
      Re: [PATCH 2/2] percpu: fix iteration to prevent skipping over block Tejun Heo <tj@kernel.org> - 2017-09-28 16:50 +0200
    [PATCH 1/2] percpu: fix starting offset for chunk statistics traversal Dennis Zhou <dennisszhou@gmail.com> - 2017-09-27 23:40 +0200
      Re: [PATCH 1/2] percpu: fix starting offset for chunk statistics  traversal Tejun Heo <tj@kernel.org> - 2017-09-27 23:50 +0200

#1741033 — [PATCH 0/2] percpu: fix block iterators and reserved chunk stats

FromDennis Zhou <dennisszhou@gmail.com>
Date2017-09-27 23:40 +0200
Subject[PATCH 0/2] percpu: fix block iterators and reserved chunk stats
Message-ID<uusdH-8rg-1@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1741034 — [PATCH 2/2] percpu: fix iteration to prevent skipping over block

FromDennis Zhou <dennisszhou@gmail.com>
Date2017-09-27 23:40 +0200
Subject[PATCH 2/2] percpu: fix iteration to prevent skipping over block
Message-ID<uusdH-8rg-15@gated-at.bofh.it>
In reply to#1741033
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 <dennisszhou@gmail.com>
Reported-by: Luis Henriques <lhenriques@suse.com>
---
 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

[toc] | [prev] | [next] | [standalone]


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

FromTejun Heo <tj@kernel.org>
Date2017-09-28 00:00 +0200
SubjectRe: [PATCH 2/2] percpu: fix iteration to prevent skipping over block
Message-ID<uusx3-6r-3@gated-at.bofh.it>
In reply to#1741034
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 <dennisszhou@gmail.com>
> Reported-by: Luis Henriques <lhenriques@suse.com>

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

Thanks.

-- 
tejun

[toc] | [prev] | [next] | [standalone]


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

FromLuis Henriques <lhenriques@suse.com>
Date2017-09-28 10:40 +0200
SubjectRe: [PATCH 2/2] percpu: fix iteration to prevent skipping over block
Message-ID<uuCwq-6Fg-3@gated-at.bofh.it>
In reply to#1741047
Tejun Heo <tj@kernel.org> 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 <dennisszhou@gmail.com>
>> Reported-by: Luis Henriques <lhenriques@suse.com>
>
> 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 <lhenriques@suse.com>

Cheers,
-- 
Luis

[toc] | [prev] | [next] | [standalone]


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

FromTejun Heo <tj@kernel.org>
Date2017-09-28 16:50 +0200
SubjectRe: [PATCH 2/2] percpu: fix iteration to prevent skipping over block
Message-ID<uuIit-1KL-3@gated-at.bofh.it>
In reply to#1741034
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 <dennisszhou@gmail.com>
> Reported-by: Luis Henriques <lhenriques@suse.com>

Applied to percpu/for-4.14-fixes.

Thanks!

-- 
tejun

[toc] | [prev] | [next] | [standalone]


#1741035 — [PATCH 1/2] percpu: fix starting offset for chunk statistics traversal

FromDennis Zhou <dennisszhou@gmail.com>
Date2017-09-27 23:40 +0200
Subject[PATCH 1/2] percpu: fix starting offset for chunk statistics traversal
Message-ID<uusdH-8rg-19@gated-at.bofh.it>
In reply to#1741033
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 <dennisszhou@gmail.com>
---
 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

[toc] | [prev] | [next] | [standalone]


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

FromTejun Heo <tj@kernel.org>
Date2017-09-27 23:50 +0200
SubjectRe: [PATCH 1/2] percpu: fix starting offset for chunk statistics traversal
Message-ID<uusnn-8uO-9@gated-at.bofh.it>
In reply to#1741035
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 <dennisszhou@gmail.com>

Applied to percpu/for-4.14-fixes.

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web