Skip to contentSkip to conversation

design/API for plugging tmem into existing xen physical memory management code

RFC Dan Magenheimer 2 participants 7 messages Feb 13, 2009 – Feb 20, 2009

lore
Share & tools
lore
#0 lore raw

Keir (and xen physical memory management experts) --

Alright, I think I am ready for the final step of plugging in tmem into the existing xen physical memory management code. **

This is a bit long, but I'd appreciate some design feedback before I proceed with this. And that requires a bit of background explanation... if this isn't enough background, I'll be happy to answer any questions.

(Note that tmem is not intended to be deployed on a 32-bit hypervisor -- due to xenheap constraints -- and should port easily (though hasn't been ported yet) to ia64. It is currently controlled by a xen command-line option, default off; and it requires tmem-modified guests.)

Tmem absorbs essentially all free memory on the machine for its use, but the vast majority of that memory can be easily freed, synchronously and on demand, for other uses. Tmem now maintains its own page list, tmem_page_list, which holds tmem pages when they (temporarily) don't contain data. (There's no sense scrubbing and freeing these to xenheap or domheap, when tmem is just going to grab them again and overwrite them anyway.) So tmem holds three types of memory:

(1) Machine-pages (4K) on the tmem_page_list
(2) Pages containing "ephemeral" data managed by tmem
(3) Ppages containing "persistent" data managed by tmem

Pages regularly move back and forth between ((2)or(3)) and (1) as part of tmem's normal operations. When a page is moved "involuntarily" from (2) to (1), we call this an "eviction". Note that, due to compression, evicting a tmem ephemeral data page does not necessarily free up a raw machine page (4K) of memory... partial pages are kept in a tmem-specific tlsf pool, and tlsf frees up the machine page when all allocations on it are freed. (tlsf is the mechanism underlying the new highly-efficient xmalloc added to xen-unstable late last year.)

Now let's assume that Xen has need of memory but tmem has absorbed it all. Xen's demand is always one of the following: (here, a page is a raw machine page (4K))

A) a page
B) a large number of individual non-consecutive pages
C) a block of 2**N consecutive pages (order N > 0)

Of these:
(A) eventually finds its way to alloc_heap_pages()
(B) happens in (at least) two circumstances:
(i) when a new domain is created, and
(ii) when a domain makes a balloon request.
(C) happens mostly at system startup and then rarely after that (when? why? see below)

Tmem will export this API:

a) struct page_info *tmem_relinquish_page(void)
b) struct page_info *tmem_relinquish_pageblock(int order)
c) uint32_t tmem_evict_npages(uint32_t npages)
d) uint32_t tmem_relinquish_pages(uint32_t npages)

(a) and (b) are internal to the hypervisor. (c) and
(d) are internal and accessible via privileged hypercall.

(a) is fairly straightforward and synchronous, though it may be a bit slow since it has to scrub the page before returning. If there is a page in tmem_page_list, it will (scrub and) return it. If not, it will evict tmem ephemeral data until there is a page freed to tmem_page_list and then it will (scrub and) return it. If tmem has no more ephemeral pages to evict and there's nothing in tmem_page_list, it will return NULL. (a) can be used in, for example, alloc_heap_pages when "No suitable memory blocks" can be found so as to avoid failing the request.

(b) is similar but is used if order > 0 (ie. a bigger chunk of pages is needed). It works the same way except that, due to fragmentation, it may have to evict MANY pages, in fact possibly ALL ephemeral data. Even then it still may not find enough consecutive pages to satisfy the request. Further, tmem doesn't use a buddy allocator... because it uses nothing larger than a machine page, it never needs one internally. So all of those
pages need to be scrubbed and freed to the xen heap before it can be determined if the request can be satisfied. As a result, this is potentially VERY slow and still has a high probability of failure. Fortunately, requests for order>0 are, I think, rare.

(c) and (d) are intentionally not combined. (c) evicts tmem ephemeral pages until it has added at least npages (machine pages) into the tmem_page_list. This may be slow. For (d), I'm thinking it will transfer npages from tmem_page_list to the scrub_list, where the existing page_scrub_timer will eventually scrub them and free them to xen's heap. (c) will return the number of pages it successfuly added to tmem_page_list. And (d) will return the number of pages it successfully moved from tmem_page_list to scrub_list.

So this leaves some design questions:

1) Does this design make sense?
2) Are there places other than in alloc_heap_pages in Xen where I need to add "hooks" for tmem to relinquish a page or a block of pages?
3) Are there are any other circumstances I've forgotten where large npages are requested?
4) Does anybody have a list of alloc requests of order > 0
that occur after xen startup (e.g. when launching a new domain) and the consequences of failing the request? I'd consider not providing interface (b) at all if it never happens or if multi-page requests always fail gracefully (e.g. get broken into smaller order requests). I'm thinking for now that I may not implement this, just fail it and printk and see if any bad things happen.

Thanks for taking the time to read through this... any feedback is appreciated.

Dan

** tmem has been working for months but the code has until now allocated (and freed) to (and from) xenheap and domheap. This has been a security hole as the pages were released unscrubbed and so data could easily leak between domains. Obviously this needed to be fixed :-) And scrubbing data at every transfer from tmem to domheap/xenheap would be a huge waste of CPU cycles, especially since the most likely next consumer of that same page is tmem again.

#1 lore raw
Quoted 2 lines · Dan Magenheimer

4) Does anybody have a list of alloc requests of order > 0

Domain and vcpu structs are order 1. Shadow pages are allocated in order-2 blocks.

Quoted 9 lines

** tmem has been working for months but the code has until now allocated (and freed) to (and from) xenheap and domheap. This has been a security hole as the pages were released unscrubbed and so data could easily leak between domains. Obviously this needed to be fixed :-) And scrubbing data at every transfer from tmem to domheap/xenheap would be a huge waste of CPU cycles, especially since the most likely next consumer of that same page is tmem again.

Then why not mark pages as coming from tmem when you free them, and scrub them on next use if it isn't going back to tmem?

I wasn't clear on who would call your C and D functions, and why they can't be merged. I might veto those depending on how ugly and exposed the changes are outside tmem.

-- Keir

#2 lore raw

Thanks much for the reply!

Quoted 5 lines
Quoted 2 lines

4) Does anybody have a list of alloc requests of order > 0

Domain and vcpu structs are order 1. Shadow pages are allocated in order-2 blocks.

Are all of these allocated at domain startup only? Or are any (shadow pages perhaps?) allocated at relatively random times? If random, what are the consequences
if the allocation fails? Isn't it quite possible
for a random order>0 allocation to fail today due to "natural causes"? E.g. because the currently running domains by coincidence (or by ballooning) have used up all available memory? Have we just been "lucky" to date, because fragmentation is so bad and ballooning is so rarely used, that we haven't seen failures of order>0 allocations? (Or maybe have seen them but didn't know it because the observable symptoms are a failed domain creation or a failed migration?)

In other words, I'm wondering if tmem doesn't create this problem, just increases the probability that it will happen?

Perhaps Jan's idea of using xenheap as an "emergency fund" for free pages is really a good idea?

Quoted 10 lines
Quoted 9 lines

** tmem has been working for months but the code has until now allocated (and freed) to (and from) xenheap and domheap. This has been a security hole as the pages were released unscrubbed and so data could easily leak between domains. Obviously this needed to be fixed :-) And scrubbing data at every transfer from tmem to domheap/xenheap would be a huge waste of CPU cycles, especially since the most likely next consumer of that same page is tmem again.

Quoted 3 lines

Then why not mark pages as coming from tmem when you free them, and scrub
them on next use if it isn't going back to tmem?

That's a reasonable idea... maybe with a "scrub_me" flag set in the struct page_info by tmem and checked by the existing alloc_heap_pages (and ignored if a memflags flag is passed to alloc_xxxheap_pages() set to "ignore_scrub_me")? There'd also need to be a free_and_scrub_domheap_pages().

If you prefer that approach, I'll give it a go. But still some (most?) of the time, there will be no free pages so alloc_heap_pages will still need to have a hook to tmem for that case.

Quoted 5 lines

I wasn't clear on who would call your C and D functions, and why they can't
be merged. I might veto those depending on how ugly and exposed the changes
are outside tmem.

I *think* these calls are just in python code (domain creation and ballooning) and, if so, will just go through the existing tmem hypercall.

Thanks,
Dan

#3 lore raw
Quoted 5 lines · Dan Magenheimer

Are all of these allocated at domain startup only? Or are any (shadow pages perhaps?) allocated at relatively random times? If random, what are the consequences
if the allocation fails? Isn't it quite possible
for a random order>0 allocation to fail today due

Quoted 8 lines

to "natural causes"? E.g. because the currently running domains by coincidence (or by ballooning) have used up all available memory? Have we just been "lucky" to date, because fragmentation is so bad and ballooning is so rarely used, that we haven't seen failures of order>0 allocations? (Or maybe have seen them but didn't know it because the observable symptoms are a failed domain creation or a failed migration?)

I think the per-domain shadow pool is pre-reserved, so it should be okay. Lack of memory simply causes domain creation failure. Any extra memory that shadow code would try to allocate would just be gravy I'm pretty sure.

Quoted 2 lines

Perhaps Jan's idea of using xenheap as an "emergency fund" for free pages is really a good idea?

It's a can of worms. How big to make the pool? Who should be allowed to allocate from it and when? What if the emergency pool becomes exhausted?

Quoted 10 lines

That's a reasonable idea... maybe with a "scrub_me" flag set in the struct page_info by tmem and checked by the existing alloc_heap_pages (and ignored if a memflags flag is passed to alloc_xxxheap_pages() set to "ignore_scrub_me")? There'd also need to be a free_and_scrub_domheap_pages().

If you prefer that approach, I'll give it a go. But still some (most?) of the time, there will be no free pages so alloc_heap_pages will still need to have a hook to tmem for that case.

I'm not super fussed, it's just an idea to consider. Could doing it this new way make it less possible to scrub pages asynchronously before they're needed?

Quoted 3 lines

I *think* these calls are just in python code (domain creation and ballooning) and, if so, will just go through the existing tmem hypercall.

Well, probably okay.

-- Keir

#4 lore raw

OK, here's the changes I've implemented to plug tmem into the existing xen physical memory management code. Hopefully it looks OK.

For easier review, this patch and the diffstat below includes only files changed in the hypervisor for tmem.

I had some difficulty understanding the page_list macros so left page_list_splice unimplemented for now. The working code removes pages from the tmem list one at a time and adds them to the scrub list, but since the pages could number in the millions for a large-memory machine, this could be very slow.

Also, I'm uncertain about the change in alloc_heap_page... is any tlb flushing required given that tmem pages are never visible outside of the hypervisor?

Thanks,
Dan

 arch/x86/mm.c                  |   36 +++++++++++++++++++++++++++++++++++
 arch/x86/setup.c               |    3 ++
 arch/x86/x86_32/entry.S        |    2 +
 arch/x86/x86_64/compat/entry.S |    2 +
 arch/x86/x86_64/entry.S        |    2 +
 common/Makefile                |    4 +++
 common/compat/Makefile         |    1 
 common/domain.c                |    4 +++
 common/page_alloc.c            |   42 +++++++++++++++++++++++++++++++++++------
 common/xmalloc_tlsf.c          |   33 ++++++++++++++++++++++----------
 include/Makefile               |    1 
 include/asm-x86/mm.h           |    2 +
 include/public/xen.h           |    1 
 include/xen/hypercall.h        |    5 ++++
 include/xen/mm.h               |   13 ++++++++++++
 include/xen/sched.h            |    3 ++
 include/xen/xmalloc.h          |    8 ++++++-
 include/xlat.lst               |    3 ++
 18 files changed, 148 insertions(+), 17 deletions(-)
xen/arch/x86/mm.c +36 -0
diff -r 4ac8bc60c000 xen/arch/x86/mm.c
@@ -3469,6 +3469,42 @@ int replace_grant_host_mapping(
     return rc;
 }
 
+int donate_page(
+    struct domain *d, struct page_info *page, unsigned int memflags)
+{
+    spin_lock(&d->page_alloc_lock);
+
+    if ( is_xen_heap_page(page) || (page_get_owner(page) != NULL) )
+        goto fail;
+
+    if ( d->is_dying )
+        goto fail;
+
+    if ( page->count_info & ~(PGC_allocated | 1) )
+        goto fail;
+
+    if ( !(memflags & MEMF_no_refcount) )
+    {
+        if ( d->tot_pages >= d->max_pages )
+            goto fail;
+        d->tot_pages++;
+    }
+
+    page->count_info = PGC_allocated | 1;
+    page_set_owner(page, d);
+    page_list_add_tail(page,&d->page_list);
+
+    spin_unlock(&d->page_alloc_lock);
+    return 0;
+
+ fail:
+    spin_unlock(&d->page_alloc_lock);
+    MEM_LOG("Bad page %p: ed=%p(%u), sd=%p, caf=%08lx, taf=%" PRtype_info,
+            (void *)page_to_mfn(page), d, d->domain_id,
+            page_get_owner(page), page->count_info, page->u.inuse.type_info);
+    return -1;
+}
+
 int steal_page(
     struct domain *d, struct page_info *page, unsigned int memflags)
 {
xen/arch/x86/setup.c +3 -0
diff -r 4ac8bc60c000 xen/arch/x86/setup.c
@@ -109,6 +109,7 @@ extern void early_cpu_init(void);
 extern void early_cpu_init(void);
 extern void vesa_init(void);
 extern void vesa_mtrr_init(void);
+extern void init_tmem(void);
 
 DEFINE_PER_CPU(struct desc_struct *, gdt_table) = boot_cpu_gdt_table;
 #ifdef CONFIG_COMPAT
@@ -1057,6 +1058,8 @@ void __init __start_xen(unsigned long mb
 
     init_trace_bufs();
 
+    init_tmem();
+
     console_endboot();
 
     /* Hide UART from DOM0 if we're using it */
xen/arch/x86/x86_32/entry.S +2 -0
diff -r 4ac8bc60c000 xen/arch/x86/x86_32/entry.S
@@ -703,6 +703,7 @@ ENTRY(hypercall_table)
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+        .long do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -750,6 +751,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+        .byte 1 /* do_tmem_op           */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/compat/entry.S +2 -0
diff -r 4ac8bc60c000 xen/arch/x86/x86_64/compat/entry.S
@@ -408,6 +408,7 @@ ENTRY(compat_hypercall_table)
         .quad do_sysctl                 /* 35 */
         .quad do_domctl
         .quad compat_kexec_op
+        .quad do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8)
         .quad compat_ni_hypercall
         .endr
@@ -455,6 +456,7 @@ ENTRY(compat_hypercall_args_table)
         .byte 1 /* do_sysctl                */  /* 35 */
         .byte 1 /* do_domctl                */
         .byte 2 /* compat_kexec_op          */
+        .byte 1 /* do_tmem_op               */
         .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table)
         .byte 0 /* compat_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +2 -0
diff -r 4ac8bc60c000 xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,7 @@ ENTRY(hypercall_table)
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+        .quad do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,6 +740,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
+        .byte 1 /* do_tmem_op           */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/Makefile +4 -0
diff -r 4ac8bc60c000 xen/common/Makefile
@@ -28,6 +28,10 @@ obj-y += vsprintf.o
 obj-y += vsprintf.o
 obj-y += xmalloc_tlsf.o
 obj-y += rcupdate.o
+obj-y += tmem.o
+obj-y += tmem_xen.o
+obj-y += radix-tree.o
+obj-y += lzo.o
 
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
xen/common/compat/Makefile +1 -0
diff -r 4ac8bc60c000 xen/common/compat/Makefile
@@ -3,3 +3,4 @@ obj-y += memory.o
 obj-y += memory.o
 obj-y += multicall.o
 obj-y += xlat.o
+obj-y += tmem_xen.o
xen/common/domain.c +4 -0
diff -r 4ac8bc60c000 xen/common/domain.c
@@ -30,6 +30,7 @@
 #include <public/sched.h>
 #include <public/vcpu.h>
 #include <xsm/xsm.h>
+#include <xen/tmem.h>
 
 /* Linux config option: propageted to domain0 */
 /* xen_processor_pmbits: xen control Cx, Px, ... */
@@ -555,6 +556,9 @@ static void complete_domain_destroy(stru
 
     grant_table_destroy(d);
 
+    if ( d->tmem != NULL )
+        tmem_destroy(d->tmem);
+
     arch_domain_destroy(d);
 
     rangeset_domain_destroy(d);
xen/common/page_alloc.c +36 -6

90 lines not on this page · raw message

xen/common/xmalloc_tlsf.c +23 -10
diff -r 4ac8bc60c000 xen/common/xmalloc_tlsf.c
@@ -320,10 +320,11 @@ struct xmem_pool *xmem_pool_create(
     pool->put_mem = put_mem;
     strlcpy(pool->name, name, sizeof(pool->name));
     region = get_mem(init_size);
-    if ( region == NULL )
-        goto out_region;
-    ADD_REGION(region, init_size, pool);
-    pool->init_region = region;
+    if ( region != NULL )
+    {
+        ADD_REGION(region, init_size, pool);
+        pool->init_region = region;
+    }
 
     spin_lock_init(&pool->lock);
 
@@ -332,10 +333,6 @@ struct xmem_pool *xmem_pool_create(
     spin_unlock(&pool_list_lock);
 
     return pool;
-
- out_region:
-    free_xenheap_pages(pool, pool_order);
-    return NULL;
 }
 
 unsigned long xmem_pool_get_used_size(struct xmem_pool *pool)
@@ -360,8 +357,11 @@ void xmem_pool_destroy(struct xmem_pool 
     /* User is destroying without ever allocating from this pool */
     if ( xmem_pool_get_used_size(pool) == BHDR_OVERHEAD )
     {
-        pool->put_mem(pool->init_region);
-        pool->used_size -= BHDR_OVERHEAD;
+        if ( pool->init_region )
+        {
+            pool->put_mem(pool->init_region);
+            pool->used_size -= BHDR_OVERHEAD;
+        }
     }
 
     /* Check for memory leaks in this pool */
@@ -381,6 +381,14 @@ void *xmem_pool_alloc(unsigned long size
     struct bhdr *b, *b2, *next_b, *region;
     int fl, sl;
     unsigned long tmp_size;
+
+    if ( pool->init_region == NULL )
+    {
+        if ( (region = pool->get_mem(pool->init_size)) == NULL )
+            goto out;
+        ADD_REGION(region, pool->init_size, pool);
+        pool->init_region = region;
+    }
 
     size = (size < MIN_BLOCK_SIZE) ? MIN_BLOCK_SIZE : ROUNDUP_SIZE(size);
     /* Rounding up the requested size and calculating fl and sl */
@@ -496,6 +504,11 @@ void xmem_pool_free(void *ptr, struct xm
     spin_unlock(&pool->lock);
 }
 
+int xmem_pool_maxalloc(struct xmem_pool *pool)
+{
+    return pool->grow_size - (2 * BHDR_OVERHEAD);
+}
+
 /*
  * Glue for xmalloc().
  */
xen/include/Makefile +1 -0
diff -r 4ac8bc60c000 xen/include/Makefile
@@ -14,6 +14,7 @@ headers-y := \
     compat/physdev.h \
     compat/platform.h \
     compat/sched.h \
+    compat/tmem.h \
     compat/trace.h \
     compat/vcpu.h \
     compat/version.h \
xen/include/asm-x86/mm.h +2 -0
diff -r 4ac8bc60c000 xen/include/asm-x86/mm.h
@@ -466,6 +466,8 @@ int compat_subarch_memory_op(int op, XEN
 
 int steal_page(
     struct domain *d, struct page_info *page, unsigned int memflags);
+int donate_page(
+    struct domain *d, struct page_info *page, unsigned int memflags);
 
 int map_ldt_shadow_page(unsigned int);
 
xen/include/public/xen.h +1 -0
diff -r 4ac8bc60c000 xen/include/public/xen.h
@@ -91,6 +91,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
 #define __HYPERVISOR_sysctl               35
 #define __HYPERVISOR_domctl               36
 #define __HYPERVISOR_kexec_op             37
+#define __HYPERVISOR_tmem_op              38
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/xen/hypercall.h +5 -0
diff -r 4ac8bc60c000 xen/include/xen/hypercall.h
@@ -13,6 +13,7 @@
 #include <public/sysctl.h>
 #include <public/platform.h>
 #include <public/event_channel.h>
+#include <public/tmem.h>
 #include <asm/hypercall.h>
 #include <xsm/xsm.h>
 
@@ -117,6 +118,10 @@ do_xsm_op(
 do_xsm_op(
     XEN_GUEST_HANDLE(xsm_op_t) u_xsm_op);
 
+extern long
+do_tmem_op(
+    XEN_GUEST_HANDLE(tmem_op_t) uops);
+
 #ifdef CONFIG_COMPAT
 
 extern int
xen/include/xen/mm.h +13 -0
diff -r 4ac8bc60c000 xen/include/xen/mm.h
@@ -74,6 +74,8 @@ int assign_pages(
 #define  MEMF_no_refcount (1U<<_MEMF_no_refcount)
 #define _MEMF_populate_on_demand 1
 #define  MEMF_populate_on_demand (1U<<_MEMF_populate_on_demand)
+#define _MEMF_no_scrub    2
+#define  MEMF_no_scrub    (1U<<_MEMF_no_scrub)
 #define _MEMF_node        8
 #define  MEMF_node(n)     ((((n)+1)&0xff)<<_MEMF_node)
 #define _MEMF_bits        24
@@ -219,6 +221,12 @@ page_list_remove_head(struct page_list_h
     return page;
 }
 
+static inline void
+page_list_splice(struct page_info *page, struct page_list_head *head)
+{
+    BUG_ON(1);  //FIXME
+}
+
 #define page_list_for_each(pos, head) \
     for ( pos = (head)->next; pos; pos = page_list_next(pos, head) )
 #define page_list_for_each_safe(pos, tmp, head) \
@@ -255,6 +263,7 @@ page_list_remove_head(struct page_list_h
     list_for_each_entry_safe(pos, tmp, head, list)
 # define page_list_for_each_safe_reverse(pos, tmp, head) \
     list_for_each_entry_safe_reverse(pos, tmp, head, list)
+# define page_list_splice(pg, hd)        list_splice(&(pg)->list, hd)
 #endif
 
 /* Automatic page scrubbing for dead domains. */
@@ -269,9 +278,13 @@ extern struct page_list_head page_scrub_
         if ( !page_list_empty(&page_scrub_list) )                       \
             cpumask_raise_softirq(cpu_online_map, PAGE_SCRUB_SOFTIRQ);  \
     } while ( 0 )
+void scrub_list_splice(struct page_info *);
+void scrub_list_add(struct page_info *);
+void scrub_one_page(struct page_info *);
 unsigned long avail_scrub_pages(void);
 
 int guest_remove_page(struct domain *d, unsigned long gmfn);
+
 
 /* Returns TRUE if the whole page at @mfn is ordinary RAM. */
 int page_is_conventional_ram(unsigned long mfn);
xen/include/xen/sched.h +3 -0
diff -r 4ac8bc60c000 xen/include/xen/sched.h
@@ -267,6 +267,9 @@ struct domain
 
     /* VRAM dirty support. */
     struct sh_dirty_vram *dirty_vram;
+
+    /* transcendent memory, auto-allocated on first tmem op by each domain */
+    void *tmem;
 };
 
 struct domain_setup_info
xen/include/xen/xmalloc.h +7 -1
diff -r 4ac8bc60c000 xen/include/xen/xmalloc.h
@@ -76,7 +76,13 @@ void *xmem_pool_alloc(unsigned long size
 void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool);
 
 /**
- * xmem_pool_free - free memory from given pool
+ * xmem_pool_maxalloc - xmem_pool_alloc's greater than this size will fail
+ * @mem_pool: pool
+ */
+int xmem_pool_maxalloc(struct xmem_pool *pool);
+
+/**
+ * xmem_pool_maxsize - 
  * @ptr: address of memory to be freed
  * @mem_pool: pool to free from
  */
xen/include/xlat.lst +3 -0
diff -r 4ac8bc60c000 xen/include/xlat.lst
@@ -58,3 +58,6 @@
 ?	processor_px			platform.h
 !	psd_package			platform.h
 !	processor_performance		platform.h
+# ?	tmem_op_t			tmem.h
+# ?	tmem_cli_mfn_t			tmem.h
+# ?	tmem_cli_va_t			tmem.h

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

Oops, always after the email is sent! :-)

I neglected the page_scrub_lock around scrub_list_add and scrub_list_splice. Consider those already added.

Dan

Quoted 50 lines

-----Original Message-----
From: Dan Magenheimer
Sent: Thursday, February 19, 2009 3:21 PM
To: Keir Fraser; Xen-Devel (E-mail)
Subject: RE: [Xen-devel] [RFC] design/API for plugging tmem into existing xen physical memory management code

OK, here's the changes I've implemented to plug tmem into the existing xen physical memory management code. Hopefully it looks OK.

For easier review, this patch and the diffstat below includes only files changed in the hypervisor for tmem.

I had some difficulty understanding the page_list macros so left page_list_splice unimplemented for now. The working code removes pages
from the tmem list one at a time and adds them to the scrub list, but since the pages could number in the millions for a large-memory machine, this could be very slow.

Also, I'm uncertain about the change in alloc_heap_page... is any tlb flushing required given that tmem pages are never visible outside of the hypervisor?

Thanks,
Dan

 arch/x86/mm.c                  |   36 
+++++++++++++++++++++++++++++++++++
 arch/x86/setup.c               |    3 ++
 arch/x86/x86_32/entry.S        |    2 +
 arch/x86/x86_64/compat/entry.S |    2 +
 arch/x86/x86_64/entry.S        |    2 +
 common/Makefile                |    4 +++
 common/compat/Makefile         |    1 
 common/domain.c                |    4 +++
 common/page_alloc.c            |   42 
+++++++++++++++++++++++++++++++++++------
 common/xmalloc_tlsf.c          |   33 
++++++++++++++++++++++----------
 include/Makefile               |    1 
 include/asm-x86/mm.h           |    2 +
 include/public/xen.h           |    1 
 include/xen/hypercall.h        |    5 ++++
 include/xen/mm.h               |   13 ++++++++++++
 include/xen/sched.h            |    3 ++
 include/xen/xmalloc.h          |    8 ++++++-
 include/xlat.lst               |    3 ++
 18 files changed, 148 insertions(+), 17 deletions(-)
#6 lore raw
In reply to Dan Magenheimer
Quoted 3 lines · Dan Magenheimer

Also, I'm uncertain about the change in alloc_heap_page... is any tlb flushing required given that tmem pages are never visible outside of the hypervisor?

No, the TLB flushes are always to flush guest mappings.

-- Keir