From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Brian Bloniarz <phunge0@hotmail.com>,
Charles Butterfield <charles.butterfield@nextcentury.com>,
Denys Vlasenko <dvlasenk@redhat.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Stefan Becker <chemobejk@gmail.com>,
"H. Peter Anvin" <hpa@zytor.com>, Yinghai Lu <yinghai@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 2/3] resources: allocate space within a region from the top down
Date: Wed, 15 Sep 2010 15:09:07 -0600 [thread overview]
Message-ID: <20100915210907.12365.81888.stgit@bob.kio> (raw)
In-Reply-To: <20100915210818.12365.58732.stgit@bob.kio>
Allocate space from the top of a region first, then work downward.
When we allocate space from a resource, we look for gaps between children
of the resource. Previously, we looked at gaps from the bottom up. For
example, given this:
[mem 0xbff00000-0xf7ffffff] PCI Bus 0000:00
[mem 0xc0000000-0xdfffffff] PCI Bus 0000:02
we attempted to allocate from the [mem 0xbff00000-0xbfffffff] gap first,
then the [mem 0xe0000000-0xf7ffffff] gap.
With this patch, we allocate from [mem 0xe0000000-0xf7ffffff] first.
Low addresses are generally scarce, so it's better to use high addresses
when possible. This follows Windows practice for PCI allocation.
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=16228#c42
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
---
kernel/resource.c | 40 ++++++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/kernel/resource.c b/kernel/resource.c
index 7b36976..e83ff7c 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -358,6 +358,20 @@ int __weak page_is_ram(unsigned long pfn)
}
/*
+ * Find the resource before "child" in the sibling list of "root" children.
+ */
+static struct resource *find_sibling_prev(struct resource *root, struct resource *child)
+{
+ struct resource *this;
+
+ for (this = root->child; this; this = this->sibling)
+ if (this->sibling == child)
+ return this;
+
+ return NULL;
+}
+
+/*
* Find empty slot in the resource tree given range and alignment.
*/
static int find_resource(struct resource *root, struct resource *new,
@@ -369,23 +383,17 @@ static int find_resource(struct resource *root, struct resource *new,
resource_size_t),
void *alignf_data)
{
- struct resource *this = root->child;
+ struct resource *this;
struct resource tmp = *new;
- tmp.start = root->start;
- /*
- * Skip past an allocated resource that starts at 0, since the assignment
- * of this->start - 1 to tmp->end below would cause an underflow.
- */
- if (this && this->start == 0) {
- tmp.start = this->end + 1;
- this = this->sibling;
- }
- for(;;) {
+ tmp.end = root->end;
+
+ this = find_sibling_prev(root, NULL);
+ for (;;) {
if (this)
- tmp.end = this->start - 1;
+ tmp.start = this->end + 1;
else
- tmp.end = root->end;
+ tmp.start = root->start;
if (tmp.start < min)
tmp.start = min;
if (tmp.end > max)
@@ -398,10 +406,10 @@ static int find_resource(struct resource *root, struct resource *new,
new->end = tmp.start + size - 1;
return 0;
}
- if (!this)
+ if (!this || this->start == root->start)
break;
- tmp.start = this->end + 1;
- this = this->sibling;
+ tmp.end = this->start - 1;
+ this = find_sibling_prev(root, this);
}
return -EBUSY;
}
next prev parent reply other threads:[~2010-09-15 21:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20100915210818.12365.58732.stgit@bob.kio>
2010-09-15 21:09 ` [PATCH 1/3] x86/PCI: allocate space from the end of a region, not the beginning Bjorn Helgaas
2010-09-15 21:09 ` Bjorn Helgaas [this message]
2010-09-15 21:09 ` [PATCH 3/3] PCI: allocate bus resources from the top down Bjorn Helgaas
2010-09-15 21:50 ` H. Peter Anvin
2010-09-15 22:44 ` Bjorn Helgaas
2010-09-15 23:45 ` H. Peter Anvin
2010-09-16 17:04 ` Bjorn Helgaas
2010-09-16 17:44 ` H. Peter Anvin
2010-09-16 19:33 ` Yinghai Lu
2010-09-16 20:02 ` H. Peter Anvin
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=20100915210907.12365.81888.stgit@bob.kio \
--to=bjorn.helgaas@hp.com \
--cc=charles.butterfield@nextcentury.com \
--cc=chemobejk@gmail.com \
--cc=dvlasenk@redhat.com \
--cc=hpa@zytor.com \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=phunge0@hotmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
Powered by JetHome