From: "Jan Beulich" <JBeulich@novell.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] x86: adjust Dom0 initial memory allocation strategy
Date: Mon, 15 Mar 2010 08:58:51 +0000 [thread overview]
Message-ID: <4B9E04DB0200007800034CD8@vpn.id2.novell.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1989 bytes --]
Simply trying order-9 allocations until they won't succeed anymore
may consume unnecessarily much memory from the DMA zone (since the
page allocator will try to fulfill the request by using memory from
that zone when only lower order memory blocks are left in all other
zones). To avoid using DMA zone memory, make alloc_chunk() try to
allocate a second smaller chunk and use that one in favor of the
first one if it came from a higher addressed memory. This way, all
memory outside the DMA zone will be consumed before eating into that
zone.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
--- 2010-03-09.orig/xen/arch/x86/domain_build.c 2010-03-12 12:25:18.000000000 +0100
+++ 2010-03-09/xen/arch/x86/domain_build.c 2010-03-12 17:24:11.000000000 +0100
@@ -127,7 +131,8 @@ static struct page_info * __init alloc_c
struct domain *d, unsigned long max_pages)
{
struct page_info *page;
- unsigned int order;
+ unsigned int order, free_order;
+
/*
* Allocate up to 2MB at a time: It prevents allocating very large chunks
* from DMA pools before the >4GB pool is fully depleted.
@@ -140,6 +145,26 @@ static struct page_info * __init alloc_c
while ( (page = alloc_domheap_pages(d, order, 0)) == NULL )
if ( order-- == 0 )
break;
+ /*
+ * Make a reasonable attempt at finding a smaller chunk at a higher
+ * address, to avoid allocating from low memory as much as possible.
+ */
+ for ( free_order = order; page && order--; )
+ {
+ struct page_info *pg2;
+
+ if ( d->tot_pages + (1 << order) > d->max_pages )
+ continue;
+ pg2 = alloc_domheap_pages(d, order, 0);
+ if ( pg2 > page )
+ {
+ free_domheap_pages(page, free_order);
+ page = pg2;
+ free_order = order;
+ }
+ else if ( pg2 )
+ free_domheap_pages(pg2, order);
+ }
return page;
}
[-- Attachment #2: x86-dom0-alloc.patch --]
[-- Type: text/plain, Size: 1983 bytes --]
Simply trying order-9 allocations until they won't succeed anymore
may consume unnecessarily much memory from the DMA zone (since the
page allocator will try to fulfill the request by using memory from
that zone when only lower order memory blocks are left in all other
zones). To avoid using DMA zone memory, make alloc_chunk() try to
allocate a second smaller chunk and use that one in favor of the
first one if it came from a higher addressed memory. This way, all
memory outside the DMA zone will be consumed before eating into that
zone.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
--- 2010-03-09.orig/xen/arch/x86/domain_build.c 2010-03-12 12:25:18.000000000 +0100
+++ 2010-03-09/xen/arch/x86/domain_build.c 2010-03-12 17:24:11.000000000 +0100
@@ -127,7 +131,8 @@ static struct page_info * __init alloc_c
struct domain *d, unsigned long max_pages)
{
struct page_info *page;
- unsigned int order;
+ unsigned int order, free_order;
+
/*
* Allocate up to 2MB at a time: It prevents allocating very large chunks
* from DMA pools before the >4GB pool is fully depleted.
@@ -140,6 +145,26 @@ static struct page_info * __init alloc_c
while ( (page = alloc_domheap_pages(d, order, 0)) == NULL )
if ( order-- == 0 )
break;
+ /*
+ * Make a reasonable attempt at finding a smaller chunk at a higher
+ * address, to avoid allocating from low memory as much as possible.
+ */
+ for ( free_order = order; page && order--; )
+ {
+ struct page_info *pg2;
+
+ if ( d->tot_pages + (1 << order) > d->max_pages )
+ continue;
+ pg2 = alloc_domheap_pages(d, order, 0);
+ if ( pg2 > page )
+ {
+ free_domheap_pages(page, free_order);
+ page = pg2;
+ free_order = order;
+ }
+ else if ( pg2 )
+ free_domheap_pages(pg2, order);
+ }
return page;
}
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2010-03-15 8:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4B9E04DB0200007800034CD8@vpn.id2.novell.com \
--to=jbeulich@novell.com \
--cc=xen-devel@lists.xensource.com \
/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;
as well as URLs for NNTP newsgroup(s).