Skip to content

Commit 8ea2e1e

Browse files
rgushchindennisszhou
authored andcommitted
percpu: factor out pcpu_check_block_hint()
Factor out the pcpu_check_block_hint() helper, which will be useful in the future. The new function checks if the allocation can likely fit within the contig hint. Signed-off-by: Roman Gushchin <[email protected]> Signed-off-by: Dennis Zhou <[email protected]> Signed-off-by: Dennis Zhou <[email protected]>
1 parent 67c2669 commit 8ea2e1e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

mm/percpu.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ static unsigned long pcpu_block_off_to_off(int index, int off)
306306
return index * PCPU_BITMAP_BLOCK_BITS + off;
307307
}
308308

309+
/**
310+
* pcpu_check_block_hint - check against the contig hint
311+
* @block: block of interest
312+
* @bits: size of allocation
313+
* @align: alignment of area (max PAGE_SIZE)
314+
*
315+
* Check to see if the allocation can fit in the block's contig hint.
316+
* Note, a chunk uses the same hints as a block so this can also check against
317+
* the chunk's contig hint.
318+
*/
319+
static bool pcpu_check_block_hint(struct pcpu_block_md *block, int bits,
320+
size_t align)
321+
{
322+
int bit_off = ALIGN(block->contig_hint_start, align) -
323+
block->contig_hint_start;
324+
325+
return bit_off + bits <= block->contig_hint;
326+
}
327+
309328
/*
310329
* pcpu_next_hint - determine which hint to use
311330
* @block: block of interest
@@ -1066,14 +1085,11 @@ static int pcpu_find_block_fit(struct pcpu_chunk *chunk, int alloc_bits,
10661085
int bit_off, bits, next_off;
10671086

10681087
/*
1069-
* Check to see if the allocation can fit in the chunk's contig hint.
1070-
* This is an optimization to prevent scanning by assuming if it
1071-
* cannot fit in the global hint, there is memory pressure and creating
1072-
* a new chunk would happen soon.
1088+
* This is an optimization to prevent scanning by assuming if the
1089+
* allocation cannot fit in the global hint, there is memory pressure
1090+
* and creating a new chunk would happen soon.
10731091
*/
1074-
bit_off = ALIGN(chunk_md->contig_hint_start, align) -
1075-
chunk_md->contig_hint_start;
1076-
if (bit_off + alloc_bits > chunk_md->contig_hint)
1092+
if (!pcpu_check_block_hint(chunk_md, alloc_bits, align))
10771093
return -1;
10781094

10791095
bit_off = pcpu_next_hint(chunk_md, alloc_bits);

0 commit comments

Comments
 (0)