Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3301411imj; Mon, 11 Feb 2019 18:14:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IaZvRSI+fcpkPUKvbzE83HfhyGEY11HSB6wskb+iEaiXORvtpmgQiREoR+avCZylH3jHjwp X-Received: by 2002:aa7:808a:: with SMTP id v10mr1556162pff.8.1549937679577; Mon, 11 Feb 2019 18:14:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549937679; cv=none; d=google.com; s=arc-20160816; b=E3MNB/Y/q6nSs/hM/RyJhRNiniq1CMFhZIGLAjqTmDT3MPV38u8f02NrxoCaCwIDQr kkODJz1dvyMEvgBxzeQuDGl+bxi9SBwDyFCNS0qWhcYOUo77FaE7LpSDf7hqICgfop5s Rlc0sLmVJ5Rg4s2cBti02BfxR+CVlp7g9s8WUZN5sulJQPuL9ouOfjl8rd8YhHSSwNYX aUtvSBC1881xLbnXKW6Y20UtRjLUlLv9JYQSnwiY7YBNOfJNjICO9lDIx51qkmvCYHfg 1WRsfKo6FMbt246hZ75OESHMuM7jmBx/lJZ8AD69Wqvw5sTXWXAQbDitO+YXN2PFY5Zr A9+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=b+0raj8Vt/l4rIzWFPgubWE8D4cb5fxfU3G56cvLmhs=; b=WS9xR0kjen17HCPP65EmHVIt8EYiviR09F335gxPYSuyNX7KJeq/oUExH5JjJASoi0 pLKS1YxaANAxkiRHdCV4mnuyRCQKKiCcXXSB2SLYvj6wvIPbbRgZmuJhOBeDeRqhOu5Q kF1FQQJrDWuAyUQbYOZ2P07gzgniVi0y6MjY7B1qdX1EVOnaPIIYOazfi2z07L5P9ie2 ZBaZ+RTu0o9jooVNpihX+sRh3DfprLOxDXD3e5W7Ju41T/52nO3iyqe8OWzWVYIebpNt kwNBWyPZezt8j3iKWOCBMSp9ZWKHObjo+TPt/L9eObJNN1NPsqoP8a3gDZUijJZqJfqs Ld5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si12166101plv.258.2019.02.11.18.14.23; Mon, 11 Feb 2019 18:14:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728033AbfBLCND (ORCPT + 99 others); Mon, 11 Feb 2019 21:13:03 -0500 Received: from mga09.intel.com ([134.134.136.24]:26869 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726699AbfBLCM4 (ORCPT ); Mon, 11 Feb 2019 21:12:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2019 18:12:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,361,1544515200"; d="scan'208";a="146057856" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga001.fm.intel.com with ESMTP; 11 Feb 2019 18:12:54 -0800 From: Wei Yang To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.or, tglx@linutronix.de, Wei Yang Subject: [PATCH 3/6] x86, mm: add comment for split_mem_range to help understanding Date: Tue, 12 Feb 2019 10:12:12 +0800 Message-Id: <20190212021215.13247-4-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190212021215.13247-1-richardw.yang@linux.intel.com> References: <20190212021215.13247-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Describing the possible ranges in split and marking ranges with name to help audience understand the logic. Also this prepares to illustrate a code refine next. Signed-off-by: Wei Yang --- arch/x86/mm/init.c | 51 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 6fb84be79c7c..2b782dcd6d71 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -328,6 +328,31 @@ static const char *page_size_string(struct map_range *mr) return str_4k; } +/* + * There are 3 types of ranges: + * + * k : 4K size + * m : 2M size + * G : 1G size + * + * 1G size is only valid when CONFIG_X86_64 is set. + * + * So we can describe the possible ranges like below: + * + * kkkmmmGGGmmmkkk + * (A)(B)(C)(D)(E) + * + * This means there are at most: + * + * 3 ranges when CONFIG_X86_32 is set + * 5 ranges when CONFIG_X86_64 is set + * + * which corresponds to the definition of NR_RANGE_MR. + * + * split_mem_range() does the split from low to high. By naming these ranges + * to A, B, C, D, E respectively and marking the name in following comment, it + * may help you to understand how ranges are split. + */ static int __meminit split_mem_range(struct map_range *mr, unsigned long start, unsigned long end) @@ -338,7 +363,10 @@ static int __meminit split_mem_range(struct map_range *mr, limit_pfn = PFN_DOWN(end); - /* head if not big page alignment ? */ + /* + * Range (A): + * head if not big page alignment ? + */ pfn = start_pfn = PFN_DOWN(start); #ifdef CONFIG_X86_32 /* @@ -361,7 +389,10 @@ static int __meminit split_mem_range(struct map_range *mr, pfn = end_pfn; } - /* big page (2M) range */ + /* + * Range (B): + * big page (2M) range + */ start_pfn = round_up(pfn, PFN_DOWN(PMD_SIZE)); #ifdef CONFIG_X86_32 end_pfn = round_down(limit_pfn, PFN_DOWN(PMD_SIZE)); @@ -370,7 +401,6 @@ static int __meminit split_mem_range(struct map_range *mr, if (end_pfn > round_down(limit_pfn, PFN_DOWN(PMD_SIZE))) end_pfn = round_down(limit_pfn, PFN_DOWN(PMD_SIZE)); #endif - if (start_pfn < end_pfn) { nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, page_size_mask & (1<