Merge branch 'x86/vdso' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip...
[firefly-linux-kernel-4.4.55.git] / arch / x86 / mm / init_64.c
index bdcde58ca9ed0191343c3b856c2257e4e3e54673..df1a9927ad29ef9aa727851e775badb0f43a5416 100644 (file)
@@ -1229,17 +1229,43 @@ int in_gate_area_no_mm(unsigned long addr)
        return (addr & PAGE_MASK) == VSYSCALL_ADDR;
 }
 
-#ifdef CONFIG_X86_UV
-unsigned long memory_block_size_bytes(void)
+static unsigned long probe_memory_block_size(void)
 {
+       /* start from 2g */
+       unsigned long bz = 1UL<<31;
+
+#ifdef CONFIG_X86_UV
        if (is_uv_system()) {
                printk(KERN_INFO "UV: memory block size 2GB\n");
                return 2UL * 1024 * 1024 * 1024;
        }
-       return MIN_MEMORY_BLOCK_SIZE;
-}
 #endif
 
+       /* less than 64g installed */
+       if ((max_pfn << PAGE_SHIFT) < (16UL << 32))
+               return MIN_MEMORY_BLOCK_SIZE;
+
+       /* get the tail size */
+       while (bz > MIN_MEMORY_BLOCK_SIZE) {
+               if (!((max_pfn << PAGE_SHIFT) & (bz - 1)))
+                       break;
+               bz >>= 1;
+       }
+
+       printk(KERN_DEBUG "memory block size : %ldMB\n", bz >> 20);
+
+       return bz;
+}
+
+static unsigned long memory_block_size_probed;
+unsigned long memory_block_size_bytes(void)
+{
+       if (!memory_block_size_probed)
+               memory_block_size_probed = probe_memory_block_size();
+
+       return memory_block_size_probed;
+}
+
 #ifdef CONFIG_SPARSEMEM_VMEMMAP
 /*
  * Initialise the sparsemem vmemmap using huge-pages at the PMD level.