Jan Beulich
2009-Jan-27 11:23 UTC
[Xen-devel] [PATCH] don''t blindly use xmalloc() for allocating struct domain instances
At least on x86 these structures are greater than a page anyway, and hence using xmalloc is wasteful here. Signed-off-by: Jan Beulich <jbeulich@novell.com> --- 2009-01-27.orig/xen/common/domain.c 2009-01-08 10:30:05.000000000 +0100 +++ 2009-01-27/xen/common/domain.c 2009-01-27 11:47:22.000000000 +0100 @@ -104,12 +104,17 @@ int current_domain_id(void) static struct domain *alloc_domain_struct(void) { - return xmalloc(struct domain); + if (sizeof(struct domain) < PAGE_SIZE) + return xmalloc(struct domain); + return alloc_xenheap_pages(get_order_from_bytes(sizeof(struct domain))); } static void free_domain_struct(struct domain *d) { - xfree(d); + if (sizeof(*d) < PAGE_SIZE) + xfree(d); + else + free_xenheap_pages(d, get_order_from_bytes(sizeof(*d))); } static void __domain_finalise_shutdown(struct domain *d) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2009-Jan-27 11:30 UTC
Re: [Xen-devel] [PATCH] don''t blindly use xmalloc() for allocating struct domain instances
The xmalloc overhead is tiny. This is only worth it if we''re actually going to pickle the domptr in page_info again. Which actually we might well do, but then we can do something like this as part of that patch. -- Keir On 27/01/2009 11:23, "Jan Beulich" <jbeulich@novell.com> wrote:> At least on x86 these structures are greater than a page anyway, and > hence using xmalloc is wasteful here. > > Signed-off-by: Jan Beulich <jbeulich@novell.com> > > --- 2009-01-27.orig/xen/common/domain.c 2009-01-08 10:30:05.000000000 +0100 > +++ 2009-01-27/xen/common/domain.c 2009-01-27 11:47:22.000000000 +0100 > @@ -104,12 +104,17 @@ int current_domain_id(void) > > static struct domain *alloc_domain_struct(void) > { > - return xmalloc(struct domain); > + if (sizeof(struct domain) < PAGE_SIZE) > + return xmalloc(struct domain); > + return alloc_xenheap_pages(get_order_from_bytes(sizeof(struct domain))); > } > > static void free_domain_struct(struct domain *d) > { > - xfree(d); > + if (sizeof(*d) < PAGE_SIZE) > + xfree(d); > + else > + free_xenheap_pages(d, get_order_from_bytes(sizeof(*d))); > } > > static void __domain_finalise_shutdown(struct domain *d) > > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel