diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2016-02-08 22:32:43 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-03-01 17:06:16 -0500 |
commit | 5c3c7ede2bdcb85fa2fd51c8147cdf70ebc17fcb (patch) | |
tree | 53b8530977350f92bf76ac0373eb7023a18839a3 /arch/powerpc/mm/hash_utils_64.c | |
parent | 1dace6c665ec59bdc4eeafa4db7228c1a673e2e2 (diff) |
powerpc/mm: Split hash page table sizing heuristic into a helper
htab_get_table_size() either retrieve the size of the hash page table (HPT)
from the device tree - if the HPT size is determined by firmware - or
uses a heuristic to determine a good size based on RAM size if the kernel
is responsible for allocating the HPT.
To support a PAPR extension allowing resizing of the HPT, we're going to
want the memory size -> HPT size logic elsewhere, so split it out into a
helper function.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch/powerpc/mm/hash_utils_64.c')
-rw-r--r-- | arch/powerpc/mm/hash_utils_64.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c index 335cd4115646..90dd9280894f 100644 --- a/arch/powerpc/mm/hash_utils_64.c +++ b/arch/powerpc/mm/hash_utils_64.c | |||
@@ -609,10 +609,28 @@ static int __init htab_dt_scan_pftsize(unsigned long node, | |||
609 | return 0; | 609 | return 0; |
610 | } | 610 | } |
611 | 611 | ||
612 | static unsigned long __init htab_get_table_size(void) | 612 | unsigned htab_shift_for_mem_size(unsigned long mem_size) |
613 | { | 613 | { |
614 | unsigned long mem_size, rnd_mem_size, pteg_count, psize; | 614 | unsigned memshift = __ilog2(mem_size); |
615 | unsigned pshift = mmu_psize_defs[mmu_virtual_psize].shift; | ||
616 | unsigned pteg_shift; | ||
617 | |||
618 | /* round mem_size up to next power of 2 */ | ||
619 | if ((1UL << memshift) < mem_size) | ||
620 | memshift += 1; | ||
621 | |||
622 | /* aim for 2 pages / pteg */ | ||
623 | pteg_shift = memshift - (pshift + 1); | ||
615 | 624 | ||
625 | /* | ||
626 | * 2^11 PTEGS of 128 bytes each, ie. 2^18 bytes is the minimum htab | ||
627 | * size permitted by the architecture. | ||
628 | */ | ||
629 | return max(pteg_shift + 7, 18U); | ||
630 | } | ||
631 | |||
632 | static unsigned long __init htab_get_table_size(void) | ||
633 | { | ||
616 | /* If hash size isn't already provided by the platform, we try to | 634 | /* If hash size isn't already provided by the platform, we try to |
617 | * retrieve it from the device-tree. If it's not there neither, we | 635 | * retrieve it from the device-tree. If it's not there neither, we |
618 | * calculate it now based on the total RAM size | 636 | * calculate it now based on the total RAM size |
@@ -622,17 +640,7 @@ static unsigned long __init htab_get_table_size(void) | |||
622 | if (ppc64_pft_size) | 640 | if (ppc64_pft_size) |
623 | return 1UL << ppc64_pft_size; | 641 | return 1UL << ppc64_pft_size; |
624 | 642 | ||
625 | /* round mem_size up to next power of 2 */ | 643 | return 1UL << htab_shift_for_mem_size(memblock_phys_mem_size()); |
626 | mem_size = memblock_phys_mem_size(); | ||
627 | rnd_mem_size = 1UL << __ilog2(mem_size); | ||
628 | if (rnd_mem_size < mem_size) | ||
629 | rnd_mem_size <<= 1; | ||
630 | |||
631 | /* # pages / 2 */ | ||
632 | psize = mmu_psize_defs[mmu_virtual_psize].shift; | ||
633 | pteg_count = max(rnd_mem_size >> (psize + 1), 1UL << 11); | ||
634 | |||
635 | return pteg_count << 7; | ||
636 | } | 644 | } |
637 | 645 | ||
638 | #ifdef CONFIG_MEMORY_HOTPLUG | 646 | #ifdef CONFIG_MEMORY_HOTPLUG |