All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Magenheimer <dan.magenheimer@oracle.com>
To: xen-devel mailing list <xen-devel@lists.xensource.com>
Subject: [PATCH][RFC] sub-page anonymous domain memory allocator
Date: Fri, 29 Aug 2008 10:12:27 -0700 (PDT)	[thread overview]
Message-ID: <2dac25a9-af17-445b-8a45-e055d8ebf71c@default> (raw)

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

This patch uses some #define-and-Makefile trickery to completely
leverage common/xmalloc.c to provide a sub-page memory
allocator that takes memory from anonymous domain heap instead
of xen heap.  Note that it is useful only on a 64-bit hypervisor.
(Some other #define trickery can be used so that 32-bit
hypervisor uses xenheap and 64-bit hypervisor uses adheap.)

Keir says that a goal for 3.4 is to combine xen heap and
domain heap on 64-bit hypervisors.  This is a step in that
direction that I am using today in some work that requires
more memory than xenheap can provide (which I'll hopefully
post sometime in the next few weeks).

Comments?

[-- Attachment #2: admalloc.patch --]
[-- Type: application/octet-stream, Size: 2933 bytes --]

diff -r 566ee473fc27 xen/common/Makefile
--- a/xen/common/Makefile	Fri Aug 22 10:45:30 2008 +0100
+++ b/xen/common/Makefile	Fri Aug 29 11:00:31 2008 -0600
@@ -27,6 +27,7 @@ obj-y += vsprintf.o
 obj-y += vsprintf.o
 obj-y += xmalloc.o
 obj-y += rcupdate.o
+obj-$(x86_64) += admalloc.o
 
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
@@ -42,6 +43,9 @@ subdir-$(ia64) += hvm
 
 subdir-y += libelf
 
+admalloc.o: xmalloc.c $(HDRS) Makefile
+	$(CC) -DANON_DOMAIN $(CFLAGS) -c $< -o $@
+
 # Object file contains changeset and compiler information.
 version.o: $(BASEDIR)/include/xen/compile.h
 
diff -r 566ee473fc27 xen/common/xmalloc.c
--- a/xen/common/xmalloc.c	Fri Aug 22 10:45:30 2008 +0100
+++ b/xen/common/xmalloc.c	Fri Aug 29 11:00:31 2008 -0600
@@ -35,6 +35,21 @@
 #include <xen/prefetch.h>
 #include <xen/irq.h>
 #include <xen/smp.h>
+
+/*
+ * combined with Makefile trickery, creates xmalloc-equivalent routines
+ * (e.g. admalloc/adfree) that use anonymous domain heap instead
+ * of xen heap... useful only on x86_64
+ */
+#ifdef ANON_DOMAIN
+#include <xen/admalloc.h>
+#define alloc_xenheap_pages(order) alloc_adheap_pages(order)
+#undef alloc_xenheap_page
+#define alloc_xenheap_page() alloc_adheap_pages(0)
+#define xfree adfree
+#define _xmalloc _admalloc
+#define free_xenheap_pages free_adheap_pages
+#endif
 
 /*
  * XMALLOC_DEBUG:
diff -r 566ee473fc27 xen/include/xen/admalloc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xen/include/xen/admalloc.h	Fri Aug 29 11:00:31 2008 -0600
@@ -0,0 +1,48 @@
+
+#ifndef __ADMALLOC_H__
+#define __ADMALLOC_H__
+
+/* Allocate space for typed object. */
+#define admalloc(_type) ((_type *)_admalloc(sizeof(_type), __alignof__(_type)))
+
+/* Allocate space for array of typed objects. */
+#define admalloc_array(_type, _num) ((_type *)_admalloc_array(sizeof(_type), __alignof__(_type), _num))
+
+/* Allocate untyped storage. */
+#define admalloc_bytes(_bytes) (_admalloc(_bytes, SMP_CACHE_BYTES))
+
+/* Free any of the above. */
+extern void adfree(void *);
+
+/* Underlying functions */
+extern void *_admalloc(size_t size, size_t align);
+static inline void *_admalloc_array(size_t size, size_t align, size_t num)
+{
+	/* Check for overflow. */
+	if (size && num > UINT_MAX / size)
+		return NULL;
+ 	return _admalloc(size * num, align);
+}
+
+static inline void free_adheap_pages(void *v, unsigned int order)
+{
+    struct page_info *pg = virt_to_page(v);
+
+    page_set_owner(pg, NULL);
+    free_domheap_pages(virt_to_page(v), order);
+}
+
+static inline struct xmalloc_hdr *alloc_adheap_pages(unsigned int order)
+{
+    struct page_info *pg = alloc_domheap_pages(NULL, order, 0);
+
+    if (pg == NULL)
+        return NULL;
+    /* FIXME is this right? */
+    return (struct xmalloc_hdr *)page_to_virt(pg);
+}
+
+#define free_adheap_page(pg) free_adheap_pages(pg,0)
+#define alloc_adheap_page() alloc_adheap_pages(0)
+
+#endif /* __ADMALLOC_H__ */

[-- 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:[~2008-08-29 17:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-29 17:12 Daniel Magenheimer [this message]
2008-08-29 18:18 ` [PATCH][RFC] sub-page anonymous domain memory allocator Keir Fraser
2008-08-29 19:46   ` Daniel Magenheimer

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=2dac25a9-af17-445b-8a45-e055d8ebf71c@default \
    --to=dan.magenheimer@oracle.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.