mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: <linux-kernel@vger.kernel.org>
Cc: <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Yinghai Lu <yinghai@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	David Vrabel <david.vrabel@citrix.com>
Subject: [PATCH] x86,mm: fix init_mem_mapping() when the first memory chunk is small
Date: Fri, 8 Mar 2013 18:47:14 +0000	[thread overview]
Message-ID: <1362768434-30525-1-git-send-email-david.vrabel@citrix.com> (raw)

In init_mem_mapping(), if the first chunk of memory that is mapped is
small, there will not be enough mapped pages to allocate page table
pages for the next (larger) chunk.

Estimate how many pages are used for the mappings so far and how many
are needed for a larger chunk, and only increase step_size if there
are enough free pages.

This fixes a boot failure on a system where the first chunk of memory
mapped only had 3 pages in it.

init_memory_mapping: [mem 0x00000000-0x000fffff]
init_memory_mapping: [mem 0x20d000000-0x20d002fff]
init_memory_mapping: [mem 0x20c000000-0x20cffffff]
Kernel panic - not syncing: alloc_low_page: can not alloc memory

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 arch/x86/mm/init.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 4903a03..0cc7afb 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -389,6 +389,12 @@ static unsigned long __init init_range_memory_mapping(
 	return mapped_ram_size;
 }
 
+/* Estimate of the number of pages needed to page 'size' bytes. */
+static unsigned long __init nr_pages_to_map(unsigned long size)
+{
+	return DIV_ROUND_UP(size, PMD_SIZE) + DIV_ROUND_UP(size, PUD_SIZE);
+}
+
 /* (PUD_SHIFT-PMD_SHIFT)/2 */
 #define STEP_SIZE_SHIFT 5
 void __init init_mem_mapping(void)
@@ -397,7 +403,7 @@ void __init init_mem_mapping(void)
 	unsigned long step_size;
 	unsigned long addr;
 	unsigned long mapped_ram_size = 0;
-	unsigned long new_mapped_ram_size;
+	unsigned long mapped_pages;
 
 	probe_page_size_mask();
 
@@ -427,14 +433,17 @@ void __init init_mem_mapping(void)
 				start = ISA_END_ADDRESS;
 		} else
 			start = ISA_END_ADDRESS;
-		new_mapped_ram_size = init_range_memory_mapping(start,
-							last_start);
+		mapped_ram_size += init_range_memory_mapping(start,
+							     last_start);
+		mapped_pages = mapped_ram_size >> PAGE_SHIFT;
 		last_start = start;
 		min_pfn_mapped = last_start >> PAGE_SHIFT;
-		/* only increase step_size after big range get mapped */
-		if (new_mapped_ram_size > mapped_ram_size)
+
+		/* Only increase step_size if there is enough mapped
+		   ram to map the larger block. */
+		if (nr_pages_to_map(step_size << STEP_SIZE_SHIFT)
+		    < mapped_pages - nr_pages_to_map(mapped_ram_size))
 			step_size <<= STEP_SIZE_SHIFT;
-		mapped_ram_size += new_mapped_ram_size;
 	}
 
 	if (real_end < end)
-- 
1.7.2.5


             reply	other threads:[~2013-03-08 18:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08 18:47 David Vrabel [this message]
2013-03-08 19:01 ` Yinghai Lu
2013-03-08 19:37   ` David Vrabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362768434-30525-1-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®