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 v2 3/4] resources: allocate space within a region from the top down
Date: Fri, 17 Sep 2010 16:32:22 -0600 [thread overview]
Message-ID: <20100917223222.24687.6486.stgit@bob.kio> (raw)
In-Reply-To: <20100917223109.24687.17697.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 ace2269..1a2a40e 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,24 +383,18 @@ 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;
resource_size_t start;
- 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)
@@ -404,10 +412,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-17 22:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-17 22:32 [PATCH v2 0/4] PCI: allocate space top-down, not bottom-up Bjorn Helgaas
2010-09-17 22:32 ` [PATCH v2 1/4] resources: ensure alignment callback doesn't allocate below available start Bjorn Helgaas
2010-09-24 17:07 ` Jesse Barnes
2010-09-24 18:15 ` Linus Torvalds
2010-09-24 18:27 ` Jesse Barnes
2010-09-17 22:32 ` [PATCH v2 2/4] x86/PCI: allocate space from the end of a region, not the beginning Bjorn Helgaas
2010-09-17 22:32 ` Bjorn Helgaas [this message]
2010-09-17 22:32 ` [PATCH v2 4/4] PCI: allocate bus resources from the top down Bjorn Helgaas
2010-09-17 23:46 ` [PATCH v2 0/4] PCI: allocate space top-down, not bottom-up H. Peter Anvin
2010-09-24 22:41 ` Bjorn Helgaas
2010-09-24 23:40 ` [stable] " Greg KH
2010-09-25 0:52 ` Jesse Barnes
2010-09-25 16:30 ` Bjorn Helgaas
2010-09-25 17:29 ` Greg KH
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=20100917223222.24687.6486.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