Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.

Commit 268625a

Browse files
dennisszhouhtejun
authored andcommitted
percpu: keep track of the best offset for contig hints
This patch makes the contig hint starting offset optimization from the previous patch as honest as it can be. For both chunk and block starting offsets, make sure it keeps the starting offset with the best alignment. The block skip optimization is added in a later patch when the pcpu_find_block_fit iterator is swapped in. Signed-off-by: Dennis Zhou <dennisszhou@gmail.com> Reviewed-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 13f9663 commit 268625a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mm/percpu.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,18 @@ static inline int pcpu_cnt_pop_pages(struct pcpu_chunk *chunk, int bit_off,
401401
* @bits: size of free area
402402
*
403403
* This updates the chunk's contig hint and starting offset given a free area.
404+
* Choose the best starting offset if the contig hint is equal.
404405
*/
405406
static void pcpu_chunk_update(struct pcpu_chunk *chunk, int bit_off, int bits)
406407
{
407408
if (bits > chunk->contig_bits) {
408409
chunk->contig_bits_start = bit_off;
409410
chunk->contig_bits = bits;
411+
} else if (bits == chunk->contig_bits && chunk->contig_bits_start &&
412+
(!bit_off ||
413+
__ffs(bit_off) > __ffs(chunk->contig_bits_start))) {
414+
/* use the start with the best alignment */
415+
chunk->contig_bits_start = bit_off;
410416
}
411417
}
412418

@@ -461,7 +467,8 @@ static void pcpu_chunk_refresh_hint(struct pcpu_chunk *chunk)
461467
* @end: end offset in block
462468
*
463469
* Updates a block given a known free area. The region [start, end) is
464-
* expected to be the entirety of the free area within a block.
470+
* expected to be the entirety of the free area within a block. Chooses
471+
* the best starting offset if the contig hints are equal.
465472
*/
466473
static void pcpu_block_update(struct pcpu_block_md *block, int start, int end)
467474
{
@@ -477,6 +484,10 @@ static void pcpu_block_update(struct pcpu_block_md *block, int start, int end)
477484
if (contig > block->contig_hint) {
478485
block->contig_hint_start = start;
479486
block->contig_hint = contig;
487+
} else if (block->contig_hint_start && contig == block->contig_hint &&
488+
(!start || __ffs(start) > __ffs(block->contig_hint_start))) {
489+
/* use the start with the best alignment */
490+
block->contig_hint_start = start;
480491
}
481492
}
482493

0 commit comments

Comments
 (0)