mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "bibo mao" <bibo.mao@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org
Subject: [patch 1/1] combine two adjacent mtrr region with the same type
Date: Thu, 9 Oct 2008 16:21:40 +0800	[thread overview]
Message-ID: <fbd277f20810090121m41e87a8eg9e6b7a1d4ec62776@mail.gmail.com> (raw)

This patch is to combine two adjacent mtrr region with the same type.

 kernel/cpu/mtrr/main.c          |   17 +++++++++++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

Signed-off-by: bibo mao <bibo.mao@gmail.com>

-------------------------------------------------------------------------------
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
index 6e212f3..c3adf83 100644
--- a/arch/x86/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
@@ -305,7 +305,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,
 {
 	int i, j, replace, error;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase, lsize, newbase;

 	if (!mtrr_if)
 		return -ENXIO;
@@ -344,7 +344,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,
 	mutex_lock(&mtrr_mutex);
 	for (i = 0; i < num_var_ranges; ++i) {
 		mtrr_if->get(i, &lbase, &lsize, &ltype);
-		if (!lsize || base > lbase + lsize - 1 || base + size - 1 < lbase)
+		if (!lsize || base > lbase + lsize || base + size < lbase)
 			continue;
 		/*  At this point we know there is some kind of overlap/enclosure  */
 		if (base < lbase || base + size - 1 > lbase + lsize - 1) {
@@ -356,6 +356,19 @@ int mtrr_add_page(unsigned long base, unsigned long size,
 				}
 				else if (types_compatible(type, ltype))
 					continue;
+			} else if ((base == lbase + lsize) || (lbase ==base + size)) {
+				if (type != ltype)
+					continue;
+				/* New region adjacent with an existing region  */
+				newbase = (base < lbase) ? base : lbase;
+				if (!mtrr_if->validate_add_page(newbase,lsize + size,type) &&
+				   mtrr_if->get_free_region(newbase, lsize + size, replace)>=0) {
+					base = newbase;
+					size += lsize;
+					replace = i;
+					continue;
+				} else
+					continue;
 			}
 			printk(KERN_WARNING
 			       "mtrr: 0x%lx000,0x%lx000 overlaps existing"

             reply	other threads:[~2008-10-09  8:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-09  8:21 bibo mao [this message]
2008-10-09 15:54 ` Yinghai Lu
2008-10-10  3:59   ` bmao

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=fbd277f20810090121m41e87a8eg9e6b7a1d4ec62776@mail.gmail.com \
    --to=bibo.mao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.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®