Skip to content

Commit

Permalink
x86/mm: Add 'step_size' comments to init_mem_mapping()
Browse files Browse the repository at this point in the history
Current code uses macro to shift by 5, but there is no explanation
why there's no worry about an overflow there.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Jacob Shin <jacob.shin@amd.com>
Link: http://lkml.kernel.org/r/1378519629-10433-1-git-send-email-yinghai@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Yinghai Lu authored and Ingo Molnar committed Sep 10, 2013
1 parent 816434e commit 6979287
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions arch/x86/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,25 @@ static unsigned long __init init_range_memory_mapping(
return mapped_ram_size;
}

/* (PUD_SHIFT-PMD_SHIFT)/2 */
#define STEP_SIZE_SHIFT 5
static unsigned long __init get_new_step_size(unsigned long step_size)
{
/*
* Explain why we shift by 5 and why we don't have to worry about
* 'step_size << 5' overflowing:
*
* initial mapped size is PMD_SIZE (2M).
* We can not set step_size to be PUD_SIZE (1G) yet.
* In worse case, when we cross the 1G boundary, and
* PG_LEVEL_2M is not set, we will need 1+1+512 pages (2M + 8k)
* to map 1G range with PTE. Use 5 as shift for now.
*
* Don't need to worry about overflow, on 32bit, when step_size
* is 0, round_down() returns 0 for start, and that turns it
* into 0x100000000ULL.
*/
return step_size << 5;
}

void __init init_mem_mapping(void)
{
unsigned long end, real_end, start, last_start;
Expand Down Expand Up @@ -449,7 +466,7 @@ void __init init_mem_mapping(void)
min_pfn_mapped = last_start >> PAGE_SHIFT;
/* only increase step_size after big range get mapped */
if (new_mapped_ram_size > mapped_ram_size)
step_size <<= STEP_SIZE_SHIFT;
step_size = get_new_step_size(step_size);
mapped_ram_size += new_mapped_ram_size;
}

Expand Down

0 comments on commit 6979287

Please sign in to comment.