From: Dan Magenheimer <dan.magenheimer@oracle.com>
To: dan.magenheimer@oracle.com,
Keir Fraser <keir.fraser@eu.citrix.com>,
xen-devel@lists.xensource.com
Subject: RE: RE: Xenheap disappearance: (was: xen_phys_start for 32b)
Date: Thu, 15 Jan 2009 01:48:06 +0000 (GMT) [thread overview]
Message-ID: <d08c3fdf-dbb9-488e-a05a-eca23ba2e576@default> (raw)
In-Reply-To: <284f216c-47fd-47e6-ace0-1131b0c60d78@default>
[-- Attachment #1: Type: text/plain, Size: 630 bytes --]
Oops, accidentally sent a stale patch. This is the correct one
(and should compile on 64-bit :-)
Also, if you need a signed-off-by line
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
> -----Original Message-----
> From: Dan Magenheimer
> Sent: Wednesday, January 14, 2009 5:27 PM
> To: Dan Magenheimer; Keir Fraser; xen-devel@lists.xensource.com
> Subject: RE: [Xen-devel] RE: Xenheap disappearance: (was:
> xen_phys_start
> for 32b)
>
>
> > If this sounds sensible, I will spin a patch as I'm the one keen
> > to get this settled.
>
> Here's the patch I had in mind (compile-tested only).
[-- Attachment #2: xmalloc.patch --]
[-- Type: application/octet-stream, Size: 4270 bytes --]
diff -r 4f6a2bbdff3f xen/common/xmalloc_tlsf.c
--- a/xen/common/xmalloc_tlsf.c Tue Jan 13 15:53:47 2009 +0000
+++ b/xen/common/xmalloc_tlsf.c Wed Jan 14 18:44:08 2009 -0700
@@ -294,15 +294,24 @@ struct xmem_pool *xmem_pool_create(
struct xmem_pool *pool;
void *region;
int pool_bytes, pool_order;
+#ifdef __x86_64__
+ struct page_info *pi = 0;
+#endif
BUG_ON(max_size && (max_size < init_size));
pool_bytes = ROUNDUP_SIZE(sizeof(*pool));
pool_order = get_order_from_bytes(pool_bytes);
+#ifdef __x86_64__
+ if ((pi = alloc_domheap_pages(0,0,0)) == NULL)
+ return NULL;
+ pool = mfn_to_virt(page_to_mfn(pi));
+#else
pool = (void *)alloc_xenheap_pages(pool_order);
if ( pool == NULL )
return NULL;
+#endif
memset(pool, 0, pool_bytes);
/* Round to next page boundary */
@@ -334,7 +343,11 @@ struct xmem_pool *xmem_pool_create(
return pool;
out_region:
+#ifdef __x86_64__
+ free_domheap_pages(pi, pool_order);
+#else
free_xenheap_pages(pool, pool_order);
+#endif
return NULL;
}
@@ -496,6 +509,119 @@ void xmem_pool_free(void *ptr, struct xm
spin_unlock(&pool->lock);
}
+#ifdef __x86_64__
+/*
+ * Glue for 64-bit-only admalloc().
+ */
+
+static struct xmem_pool *adpool;
+
+static void *admalloc_pool_get(unsigned long size)
+{
+ struct page_info *pi;
+
+ ASSERT(size == PAGE_SIZE);
+
+ if ((pi = alloc_domheap_pages(0,0,0)) == NULL)
+ return NULL;
+ return mfn_to_virt(page_to_mfn(pi));
+}
+
+static void admalloc_pool_put(void *p)
+{
+ free_domheap_pages(mfn_to_page(virt_to_mfn(p)),0);
+}
+
+static void *admalloc_whole_pages(unsigned long size)
+{
+ struct bhdr *b;
+ struct page_info *pi;
+ unsigned int pageorder = get_order_from_bytes(size + BHDR_OVERHEAD);
+
+ pi = alloc_domheap_pages(0,0,0);
+ if (pi == NULL)
+ return NULL;
+ b = mfn_to_virt(page_to_mfn(pi));
+
+ b->size = (1 << (pageorder + PAGE_SHIFT));
+ return (void *)b->ptr.buffer;
+}
+
+static void tlsf_init(void)
+{
+ INIT_LIST_HEAD(&pool_list_head);
+ spin_lock_init(&pool_list_lock);
+ adpool = xmem_pool_create(
+ "admalloc", admalloc_pool_get, admalloc_pool_put,
+ PAGE_SIZE, 0, PAGE_SIZE);
+ BUG_ON(!adpool);
+}
+
+/*
+ * admalloc()
+ */
+
+void *_admalloc(unsigned long size, unsigned long align)
+{
+ void *p;
+ u32 pad;
+
+ ASSERT(!in_irq());
+
+ ASSERT((align & (align - 1)) == 0);
+ if ( align < MEM_ALIGN )
+ align = MEM_ALIGN;
+ size += align - MEM_ALIGN;
+
+ if ( !adpool )
+ tlsf_init();
+
+ if ( size >= (PAGE_SIZE - (2*BHDR_OVERHEAD)) )
+ p = admalloc_whole_pages(size);
+ else
+ p = xmem_pool_alloc(size, adpool);
+
+ /* Add alignment padding. */
+ if ( (pad = -(long)p & (align - 1)) != 0 )
+ {
+ char *q = (char *)p + pad;
+ struct bhdr *b = (struct bhdr *)(q - BHDR_OVERHEAD);
+ ASSERT(q > (char *)p);
+ b->size = pad | 1;
+ p = q;
+ }
+
+ ASSERT(((unsigned long)p & (align - 1)) == 0);
+ return p;
+}
+
+void adfree(void *p)
+{
+ struct bhdr *b;
+
+ ASSERT(!in_irq());
+
+ if ( p == NULL )
+ return;
+
+ /* Strip alignment padding. */
+ b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
+ if ( b->size & 1 )
+ {
+ p = (char *)p - (b->size & ~1u);
+ b = (struct bhdr *)((char *)p - BHDR_OVERHEAD);
+ ASSERT(!(b->size & 1));
+ }
+
+ if ( b->size >= (PAGE_SIZE - (2*BHDR_OVERHEAD)) )
+ free_domheap_pages(mfn_to_page(virt_to_mfn(p)),
+ get_order_from_bytes(b->size));
+ else
+ xmem_pool_free(p, adpool);
+}
+
+#else
+
/*
* Glue for xmalloc().
*/
@@ -597,3 +723,5 @@ void xfree(void *p)
else
xmem_pool_free(p, xenpool);
}
+
+#endif
diff -r 4f6a2bbdff3f xen/include/xen/xmalloc.h
--- a/xen/include/xen/xmalloc.h Tue Jan 13 15:53:47 2009 +0000
+++ b/xen/include/xen/xmalloc.h Wed Jan 14 18:44:08 2009 -0700
@@ -5,6 +5,11 @@
/*
* Xen malloc/free-style interface.
*/
+
+#ifdef __x86_64__
+#define _xmalloc _admalloc
+#define xfree adfree
+#endif
/* Allocate space for typed object. */
#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2009-01-15 1:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-06 6:36 xen_phys_start for 32b Cihula, Joseph
2009-01-06 8:42 ` Keir Fraser
2009-01-06 18:29 ` Cihula, Joseph
2009-01-06 22:12 ` Keir Fraser
2009-01-06 22:19 ` Cihula, Joseph
2009-01-07 8:54 ` Keir Fraser
2009-01-07 15:13 ` Cihula, Joseph
2009-01-07 15:40 ` Keir Fraser
2009-01-07 21:37 ` Cihula, Joseph
2009-01-07 23:27 ` Keir Fraser
2009-01-08 0:17 ` Xenheap disappearance: (was: xen_phys_start for 32b) Dan Magenheimer
2009-01-08 9:04 ` Keir Fraser
2009-01-08 17:53 ` Dan Magenheimer
2009-01-14 22:45 ` Dan Magenheimer
2009-01-15 0:27 ` Dan Magenheimer
2009-01-15 1:48 ` Dan Magenheimer [this message]
2009-01-15 8:38 ` Keir Fraser
2009-01-15 8:41 ` Keir Fraser
2009-01-15 18:15 ` Dan Magenheimer
2009-01-15 18:51 ` Keir Fraser
2009-01-16 8:11 ` Re: Xenheap disappearance: (was: xen_phys_start for32b) Jan Beulich
2009-01-16 23:16 ` Dan Magenheimer
2009-01-19 8:22 ` Re: Xenheap disappearance: (was: xen_phys_startfor32b) Jan Beulich
2009-01-19 20:04 ` Dan Magenheimer
2009-01-20 9:11 ` Re: Xenheap disappearance: (was:xen_phys_startfor32b) Jan Beulich
2009-01-20 9:16 ` Keir Fraser
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=d08c3fdf-dbb9-488e-a05a-eca23ba2e576@default \
--to=dan.magenheimer@oracle.com \
--cc=keir.fraser@eu.citrix.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.