From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750900Ab3IGCHi (ORCPT ); Fri, 6 Sep 2013 22:07:38 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:26198 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750837Ab3IGCHh (ORCPT ); Fri, 6 Sep 2013 22:07:37 -0400 From: Yinghai Lu To: "H. Peter Anvin" Cc: Ingo Molnar , Pekka Enberg , Jacob Shin , linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH] x86, mm: Add comments for step_size Date: Fri, 6 Sep 2013 19:07:09 -0700 Message-Id: <1378519629-10433-1-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.1.4 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current code use MACRO to have shift to set to 5, but there is not explanation about selection. Add comment about why we are using 5. Also add explanation that we don't need to worry about overflow on 32bit. -v3: According to Ingo, update changelog and comments. Signed-off-by: Yinghai Lu --- arch/x86/mm/init.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) Index: linux-2.6/arch/x86/mm/init.c =================================================================== --- linux-2.6.orig/arch/x86/mm/init.c +++ linux-2.6/arch/x86/mm/init.c @@ -399,8 +399,22 @@ static unsigned long __init init_range_m 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) +{ + /* + * 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() return 0 for + * start, and that make that 0 just like 0x100000000ULL. + */ + return step_size << 5; +} + void __init init_mem_mapping(void) { unsigned long end, real_end, start, last_start; @@ -449,7 +463,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; }