lkml.org 
[lkml]   [2017]   [Jul]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 10/10] percpu: add optimizations on allocation path for the bitmap allocator
Date
From: "Dennis Zhou (Facebook)" <dennisszhou@gmail.com>

This patch adds two optimizations to the allocation path. The first is
to not consider a chunk if the requested allocation cannot fit in the
chunk's contig_hint. The benefit is that this avoids unncessary scanning
over a chunk as the assumption is memory pressure is high and creating a
new chunk has minimal consequences. This may fail when the contig_hint
has poor alignment, but again we fall back on the high memory pressure
argument.

The second is just a fail-fast mechanism. When allocating, a offset is
identified within a block and then scanning is used to see if it will
fit. An offset should never be returned unless it is known to fit, so
here we just bind the scanning to the size of a block.

Signed-off-by: Dennis Zhou <dennisszhou@gmail.com>
---
mm/percpu.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index 569df63..7496571 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -885,6 +885,12 @@ static int pcpu_find_block_fit(struct pcpu_chunk *chunk, int bit_size,

lockdep_assert_held(&pcpu_lock);

+ /* check chunk->contig_hint to see if alloc can fit - see note above */
+ block_off = ALIGN(chunk->contig_hint_start, align) -
+ chunk->contig_hint_start;
+ if (block_off + bit_size > chunk->contig_hint)
+ return -1;
+
cur_free = block_off = 0;
s_index = chunk->first_free_block;
for (i = chunk->first_free_block; i < pcpu_nr_pages_to_blocks(chunk);
@@ -973,19 +979,23 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int bit_size,
size_t align, int start)
{
size_t align_mask = (align) ? (align - 1) : 0;
- int i, bit_off, oslot;
+ int i, bit_off, end, oslot;
struct pcpu_bitmap_md *block;

lockdep_assert_held(&pcpu_lock);

oslot = pcpu_chunk_slot(chunk);

- /* search to find fit */
- bit_off = bitmap_find_next_zero_area(chunk->alloc_map,
- pcpu_nr_pages_to_bits(chunk),
- start, bit_size, align_mask);
+ /*
+ * Search to find fit. The search for the start is limited to
+ * be within a block_size, but should in reality never be hit
+ * as the contig_hint should be a valid placement.
+ */
+ end = start + bit_size + PCPU_BITMAP_BLOCK_SIZE;
+ bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start,
+ bit_size, align_mask);

- if (bit_off >= pcpu_nr_pages_to_bits(chunk))
+ if (bit_off >= end)
return -1;

/* update alloc map */
--
2.9.3
\
 
 \ /
  Last update: 2017-07-16 04:26    [W:0.241 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site