Skip to contentSkip to conversation

XENMEM_claim_pages (subop of existing) hypercall

PATCH Superseded Dan Magenheimer 4 participants 20 messages Nov 14, 2012 – Nov 21, 2012

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 XENMEM_claim_pages (subop of existing) hypercall

This is a second cut of the hypervisor patch of the proposed XENMEM_claim_pages hypercall/subop, taking into account feedback from Jan and Keir, plus some fixes found via runtime debugging (using privcmd only) and some comments/cleanup.

v1->v2:
- Add reset-to-zero page claim in domain_kill [JBeulich]
- Proper handling of struct passed to hypercall [JBeulich]
- Fix alloc_heap_pages when a domain has a claim [JBeulich]
- Need not hold heap_lock if !d->unclaimed_pages [keir]
- Fix missed tot_pages call in donate_page [djm]
- Remove domain_reset_unclaimed_pages; use set with zero [djm]
- Bugfixes found through testing in set_unclaimed [djm]
- More comments in code [djm]
- Code formatting fixes [djm]

===

Motivation:

The goal of this hypercall
is to attempt to atomically and very quickly determine if there are sufficient pages available in the system and, if so, "set aside" that quantity of pages for future allocations by that domain. Unlike an existing hypercall such as increase_reservation or populate_physmap, specific physical pageframes are not assigned to the domain because this cannot be done sufficiently quickly (especially for very large allocations in an arbitrarily fragmented system) and so the existing mechanisms result in classic time-of-check-time-of-use (TOCTOU) races. One can think of claiming as similar to a "lazy" allocation, but subsequent hypercalls are required to do the actual physical pageframe allocation.

I don't have a patch for the toolstack side, but I envision a "xl create --claim" option to maximize backwards compatibility while minimizing impact on existing toolstacks. As a result, testing has (so far) only been done via privcmd.

Code overview:

Though the hypercall simply does arithmetic within locks, some of the semantics in the code may be a bit subtle so let me explain a bit.

The key variables (d->unclaimed_pages and total_unclaimed_pages) start at zero if no claim has yet been staked for any domain. (Perhaps a better name is "claimed_but_not_yet_possessed" but that's a bit unwieldy.) If no claim hypercalls are executed, there should be no impact on existing usage.

When a claim is successfully staked by a domain, it is like a watermark but there is no record kept of the size of the claim. Instead, d->unclaimed_pages is set to the difference between d->tot_pages and the claim (d->tot_pages may normally be zero but see Note 1). When d->tot_pages increases or decreases, d->unclaimed_pages atomically decreases or increases. Once d->unclaimed_pages reaches zero, the claim is satisfied and d->unclaimed pages stays at zero -- unless a new claim is subsequently staked. See Note 2.

The systemwide variable total_unclaimed_pages is always the sum of d->unclaimed_pages, across all domains. A non-domain- specific heap allocation will fail if total_unclaimed_pages exceeds free (plus, on tmem enabled systems, freeable) pages.

Claim semantics may be modified by flags. The initial implementation has one flag, which discerns whether the caller would like tmem freeable pages to be considered in determining whether or not the claim can be successfully staked. Future flags may, for example, specify that the caller would like the claim to be successful only if there are sufficient pages available on a single node (per Dario's suggestion).

Note 1: Tim: I'm thinking this may resolve your concern that the claim mechanism must be more complicated to handle restricted memory allocations and order>0 allocations. The proposed claim mechanism only guarantees a quantity of order==0 pages; if restricted allocations are required, these are done first by the toolstack, and followed by the claim. Order>0 allocations still work if memory is not fragmented, but the claim mechanism doesn't guarantee anything but a quantity of order==0 pages.

Note 2: Tim: This arithmetic also indirectly implements the "claim auto-expire" discussed earlier. We certainly don't want a negative claim. It's possible that the toolstack need never call "unclaim" (and so such a hypercall/subop need not even exist) as long as domain_reset_unclaimed_pages() is called when a domain dies. This draft doesn't even provide unclaim... though if a reason for its existence is determined, it should be easy to add.

Note 3: There is currently no way to observe a staked claim, so a staked claim will not survive a save/restore/migrate. Not clear yet if this is needed but could be added.

Thanks for any feedback!

 arch/x86/mm.c             |    2 
 arch/x86/mm/mem_sharing.c |    4 -
 common/domain.c           |    1 
 common/grant_table.c      |    2 
 common/memory.c           |   31 ++++++++++++-
 common/page_alloc.c       |  107 +++++++++++++++++++++++++++++++++++++++++++++-
 include/public/memory.h   |   31 +++++++++++++
 include/xen/mm.h          |    6 ++
 include/xen/sched.h       |    1 
 9 files changed, 178 insertions(+), 7 deletions(-)
xen/arch/x86/mm.c +1 -1
index fad3d33..7e55908 100644
@@ -3841,7 +3841,7 @@ int donate_page(
     {
         if ( d->tot_pages >= d->max_pages )
             goto fail;
-        d->tot_pages++;
+        domain_increase_tot_pages(d, 1);
     }
 
     page->count_info = PGC_allocated | 1;
xen/arch/x86/mm/mem_sharing.c +2 -2
index 5103285..943a3b5 100644
@@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
     }
 
     page_set_owner(page, dom_cow);
-    d->tot_pages--;
+    domain_decrease_tot_pages(d, 1);
     drop_dom_ref = (d->tot_pages == 0);
     page_list_del(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
@@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
     ASSERT(page_get_owner(page) == dom_cow);
     page_set_owner(page, d);
 
-    if ( d->tot_pages++ == 0 )
+    if ( domain_increase_tot_pages(d, 1) == 0 )
         get_domain(d);
     page_list_add_tail(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
xen/common/domain.c +1 -0
index 0e3e36a..95509e2 100644
@@ -492,6 +492,7 @@ int domain_kill(struct domain *d)
         evtchn_destroy(d);
         gnttab_release_mappings(d);
         tmem_destroy(d->tmem);
+        domain_set_unclaimed_pages(d, 0, 0);
         d->tmem = NULL;
         /* fallthrough */
     case DOMDYING_dying:
xen/common/grant_table.c +1 -1
index 7912769..10ce78f 100644
@@ -1656,7 +1656,7 @@ gnttab_transfer(
         }
 
         /* Okay, add the page to 'e'. */
-        if ( unlikely(e->tot_pages++ == 0) )
+        if ( unlikely(domain_increase_tot_pages(e, 1) == 0) )
             get_knownalive_domain(e);
         page_list_add_tail(page, &e->page_list);
         page_set_owner(page, e);
xen/common/memory.c +30 -1
index 83e2666..38f2cb9 100644
@@ -454,7 +454,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
                              (j * (1UL << exch.out.extent_order)));
 
                 spin_lock(&d->page_alloc_lock);
-                d->tot_pages -= dec_count;
+                domain_decrease_tot_pages(d, dec_count);
                 drop_dom_ref = (dec_count && !d->tot_pages);
                 spin_unlock(&d->page_alloc_lock);
 
@@ -685,6 +685,35 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case XENMEM_claim_pages:
+    {
+        unsigned long request;
+
+        start_extent = cmd >> MEMOP_EXTENT_SHIFT;
+
+        if ( copy_from_guest(&reservation, arg, 1) )
+            return start_extent;
+
+        if ( !(guest_handle_is_null(reservation.extent_start)) )
+            return start_extent;
+
+        rc = rcu_lock_target_domain_by_id(reservation.domid, &d);
+        if ( rc )
+            return rc;
+
+        /*
+         * extent_order may be non-zero, but is only a multiplier and
+         * does not currently claim any order>0 slabs, though this is
+         * a possible future feature
+         */
+        request = reservation.nr_extents << reservation.extent_order;
+        rc = domain_set_unclaimed_pages(d, request, reservation.mem_flags);
+
+        rcu_unlock_domain(d);
+
+        break;
+    }
+
     default:
         rc = arch_memory_op(op, arg);
         break;
xen/common/page_alloc.c +105 -2

131 lines not on this page · raw message

xen/include/public/memory.h +31 -0
index f1ddbc0..c4de5c1 100644
@@ -68,6 +68,8 @@ struct xen_memory_reservation {
      *   IN:  GPFN bases of extents to populate with memory
      *   OUT: GMFN bases of extents that were allocated
      *   (NB. This command also updates the mach_to_phys translation table)
+     * XENMEM_claim_pages:
+     *   IN: must be zero
      */
     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
 
@@ -421,6 +423,35 @@ struct xen_mem_sharing_op {
 typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
 DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
 
+/*
+ * Attempt to stake a claim for a domain on a quantity of pages
+ * of system RAM, but _not_ assign specific pageframes.  Only
+ * arithmetic is performed so the hypercall is very fast and need
+ * not be preemptible, thus sidestepping time-of-check-time-of-use
+ * races for memory allocation.  Returns 0 if the hypervisor page
+ * allocator has atomically and successfully claimed the requested
+ * number of pages, else non-zero.
+ *
+ * Any domain may have only one active claim.  When sufficient memory
+ * has been allocated to resolve the claim, the claim silently expires.
+ * Claiming zero pages effectively resets any outstanding claim and
+ * is always successful.
+ *
+ * Note that a valid claim may be staked even after memory has been
+ * allocated for a domain.  In this case, the claim is not incremental,
+ * i.e. if the domain's tot_pages is 3, and a claim is staked for 10,
+ * only 7 additional pages are claimed.
+ */
+#define XENMEM_claim_pages                  24
+/*
+ * XENMEM_claim_pages flags:
+ *  free_only: claim is successful only if sufficient free pages
+ *    are available.  If not set and tmem is enabled, hypervisor
+ *    may also consider tmem "freeable" pages to satisfy the claim.
+ */
+#define _XENMEM_CLAIMF_free_only            0
+#define XENMEM_CLAIMF_free_only             (1U<<_XENMEM_CLAIMF_free_only)
+
 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
 
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
xen/include/xen/mm.h +6 -0
index 64a0cc1..5c63581 100644
@@ -48,6 +48,12 @@ void free_xenheap_pages(void *v, unsigned int order);
 #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
 #define free_xenheap_page(v) (free_xenheap_pages(v,0))
 
+/* Claim handling */
+unsigned long domain_increase_tot_pages(struct domain *d, unsigned long pages);
+unsigned long domain_decrease_tot_pages(struct domain *d, unsigned long pages);
+int domain_set_unclaimed_pages(
+    struct domain *d, unsigned long pages, unsigned long flags);
+
 /* Domain suballocator. These functions are *not* interrupt-safe.*/
 void init_domheap_pages(paddr_t ps, paddr_t pe);
 struct page_info *alloc_domheap_pages(
xen/include/xen/sched.h +1 -0
index 6c55039..480ef39 100644
@@ -242,6 +242,7 @@ struct domain
     struct page_list_head page_list;  /* linked list */
     struct page_list_head xenpage_list; /* linked list (size xenheap_pages) */
     unsigned int     tot_pages;       /* number of pages currently possesed */
+    unsigned int     unclaimed_pages; /* pages claimed but not possessed    */
     unsigned int     max_pages;       /* maximum value for tot_pages        */
     atomic_t         shr_pages;       /* number of shared pages             */
     atomic_t         paged_pages;     /* number of paged-out pages          */
xen/arch/x86/mm.c +1 -1
index fad3d33..7e55908 100644
@@ -3841,7 +3841,7 @@ int donate_page(
     {
         if ( d->tot_pages >= d->max_pages )
             goto fail;
-        d->tot_pages++;
+        domain_increase_tot_pages(d, 1);
     }
 
     page->count_info = PGC_allocated | 1;
xen/arch/x86/mm/mem_sharing.c +2 -2
index 5103285..943a3b5 100644
@@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
     }
 
     page_set_owner(page, dom_cow);
-    d->tot_pages--;
+    domain_decrease_tot_pages(d, 1);
     drop_dom_ref = (d->tot_pages == 0);
     page_list_del(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
@@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
     ASSERT(page_get_owner(page) == dom_cow);
     page_set_owner(page, d);
 
-    if ( d->tot_pages++ == 0 )
+    if ( domain_increase_tot_pages(d, 1) == 0 )
         get_domain(d);
     page_list_add_tail(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
xen/common/domain.c +1 -0
index 0e3e36a..95509e2 100644
@@ -492,6 +492,7 @@ int domain_kill(struct domain *d)
         evtchn_destroy(d);
         gnttab_release_mappings(d);
         tmem_destroy(d->tmem);
+        domain_set_unclaimed_pages(d, 0, 0);
         d->tmem = NULL;
         /* fallthrough */
     case DOMDYING_dying:
xen/common/grant_table.c +1 -1
index 7912769..10ce78f 100644
@@ -1656,7 +1656,7 @@ gnttab_transfer(
         }
 
         /* Okay, add the page to 'e'. */
-        if ( unlikely(e->tot_pages++ == 0) )
+        if ( unlikely(domain_increase_tot_pages(e, 1) == 0) )
             get_knownalive_domain(e);
         page_list_add_tail(page, &e->page_list);
         page_set_owner(page, e);
xen/common/memory.c +30 -1
index 83e2666..38f2cb9 100644
@@ -454,7 +454,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
                              (j * (1UL << exch.out.extent_order)));
 
                 spin_lock(&d->page_alloc_lock);
-                d->tot_pages -= dec_count;
+                domain_decrease_tot_pages(d, dec_count);
                 drop_dom_ref = (dec_count && !d->tot_pages);
                 spin_unlock(&d->page_alloc_lock);
 
@@ -685,6 +685,35 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case XENMEM_claim_pages:
+    {
+        unsigned long request;
+
+        start_extent = cmd >> MEMOP_EXTENT_SHIFT;
+
+        if ( copy_from_guest(&reservation, arg, 1) )
+            return start_extent;
+
+        if ( !(guest_handle_is_null(reservation.extent_start)) )
+            return start_extent;
+
+        rc = rcu_lock_target_domain_by_id(reservation.domid, &d);
+        if ( rc )
+            return rc;
+
+        /*
+         * extent_order may be non-zero, but is only a multiplier and
+         * does not currently claim any order>0 slabs, though this is
+         * a possible future feature
+         */
+        request = reservation.nr_extents << reservation.extent_order;
+        rc = domain_set_unclaimed_pages(d, request, reservation.mem_flags);
+
+        rcu_unlock_domain(d);
+
+        break;
+    }
+
     default:
         rc = arch_memory_op(op, arg);
         break;
xen/common/page_alloc.c +105 -2

131 lines not on this page · raw message

xen/include/public/memory.h +31 -0
index f1ddbc0..c4de5c1 100644
@@ -68,6 +68,8 @@ struct xen_memory_reservation {
      *   IN:  GPFN bases of extents to populate with memory
      *   OUT: GMFN bases of extents that were allocated
      *   (NB. This command also updates the mach_to_phys translation table)
+     * XENMEM_claim_pages:
+     *   IN: must be zero
      */
     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
 
@@ -421,6 +423,35 @@ struct xen_mem_sharing_op {
 typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
 DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
 
+/*
+ * Attempt to stake a claim for a domain on a quantity of pages
+ * of system RAM, but _not_ assign specific pageframes.  Only
+ * arithmetic is performed so the hypercall is very fast and need
+ * not be preemptible, thus sidestepping time-of-check-time-of-use
+ * races for memory allocation.  Returns 0 if the hypervisor page
+ * allocator has atomically and successfully claimed the requested
+ * number of pages, else non-zero.
+ *
+ * Any domain may have only one active claim.  When sufficient memory
+ * has been allocated to resolve the claim, the claim silently expires.
+ * Claiming zero pages effectively resets any outstanding claim and
+ * is always successful.
+ *
+ * Note that a valid claim may be staked even after memory has been
+ * allocated for a domain.  In this case, the claim is not incremental,
+ * i.e. if the domain's tot_pages is 3, and a claim is staked for 10,
+ * only 7 additional pages are claimed.
+ */
+#define XENMEM_claim_pages                  24
+/*
+ * XENMEM_claim_pages flags:
+ *  free_only: claim is successful only if sufficient free pages
+ *    are available.  If not set and tmem is enabled, hypervisor
+ *    may also consider tmem "freeable" pages to satisfy the claim.
+ */
+#define _XENMEM_CLAIMF_free_only            0
+#define XENMEM_CLAIMF_free_only             (1U<<_XENMEM_CLAIMF_free_only)
+
 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
 
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
xen/include/xen/mm.h +6 -0
index 64a0cc1..5c63581 100644
@@ -48,6 +48,12 @@ void free_xenheap_pages(void *v, unsigned int order);
 #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
 #define free_xenheap_page(v) (free_xenheap_pages(v,0))
 
+/* Claim handling */
+unsigned long domain_increase_tot_pages(struct domain *d, unsigned long pages);
+unsigned long domain_decrease_tot_pages(struct domain *d, unsigned long pages);
+int domain_set_unclaimed_pages(
+    struct domain *d, unsigned long pages, unsigned long flags);
+
 /* Domain suballocator. These functions are *not* interrupt-safe.*/
 void init_domheap_pages(paddr_t ps, paddr_t pe);
 struct page_info *alloc_domheap_pages(
xen/include/xen/sched.h +1 -0
index 6c55039..480ef39 100644
@@ -242,6 +242,7 @@ struct domain
     struct page_list_head page_list;  /* linked list */
     struct page_list_head xenpage_list; /* linked list (size xenheap_pages) */
     unsigned int     tot_pages;       /* number of pages currently possesed */
+    unsigned int     unclaimed_pages; /* pages claimed but not possessed    */
     unsigned int     max_pages;       /* maximum value for tot_pages        */
     atomic_t         shr_pages;       /* number of shared pages             */
     atomic_t         paged_pages;     /* number of paged-out pages          */

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

#1 lore raw

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 692

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Dan Magenheimer
xen/common/memory.c +5 -0
@@ -685,6 +685,35 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case XENMEM_claim_pages:
+    {
+        unsigned long request;
+
+        start_extent = cmd >> MEMOP_EXTENT_SHIFT;

What's this? You don't do continuations (you explicitly do that change in order to be fast), and hence this ought to be ignored just like e.g. XENMEM_remove_from_physmap ignores it.

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 695

Quoted 3 lines
xen/common/memory.c +3 -0
+
+        if ( copy_from_guest(&reservation, arg, 1) )
+            return start_extent;

-EFAULT

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 698

Quoted 3 lines
xen/common/memory.c +3 -0
+
+        if ( !(guest_handle_is_null(reservation.extent_start)) )
+            return start_extent;

-EINVAL

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 708

Quoted 10 lines
xen/common/memory.c +10 -0
+
+        rc = rcu_lock_target_domain_by_id(reservation.domid, &d);
+        if ( rc )
+            return rc;
+
+        /*
+         * extent_order may be non-zero, but is only a multiplier and
+         * does not currently claim any order>0 slabs, though this is
+         * a possible future feature
+         */

If extent_order doesn't do what it promises to do, just don't allow non-zero values.

xen/common/memory.c long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)

Quoted 13 lines
xen/common/memory.c +12 -0
+        request = reservation.nr_extents << reservation.extent_order;
+        rc = domain_set_unclaimed_pages(d, request, reservation.mem_flags);
+
+        rcu_unlock_domain(d);
+
+        break;
+    }
+
...
+unsigned long domain_decrease_tot_pages(struct domain *d, unsigned long pages)
+{
+    ASSERT(spin_is_locked(&d->page_alloc_lock));
+    ASSERT(!spin_is_locked(&heap_lock));

There are numerous of these throughout the code, but while asserting a certain lock to be held is valid, asserting that one isn't being held (by _anyone_) clearly isn't. You're presumably mixing this up with something like spin_is_owned()...

Review

Quoted 2 lines
(quoted diff) +2 -0
+    spin_lock(&heap_lock);
+    d->tot_pages -= pages;

Shouldn't you do the same lockless approach for the common case here as you did on Keir's advice in domain_increase_tot_pages()?

Quoted 4 lines
xen/common/page_alloc.c +4 -0
+    if ( d->unclaimed_pages )
+    {
+        d->unclaimed_pages += pages;
+        total_unclaimed_pages += pages;

xen/common/page_alloc.c static long midsize_alloc_zone_pages; · line 286

Quoted 10 lines
xen/common/page_alloc.c +10 -0
+    }
+    spin_unlock(&heap_lock);
+    return d->tot_pages;
+}
+
+int domain_set_unclaimed_pages(struct domain *d, unsigned long pages,
+                                unsigned long flags)
+{
+    int ret = -ENOMEM;
+    unsigned long claim = 0, avail_pages = 0;

Pointless initializers.

Quoted 13 lines
xen/common/page_alloc.c +13 -0
+
+    /*
+     * take the domain's page_alloc_lock, else all increases/decreases
+     * must always take the global heap_lock rather than only in the much
+     * rarer case that d->unclaimed_pages is non-zero
+     */
+    ASSERT(!spin_is_locked(&d->page_alloc_lock));
+    spin_lock(&d->page_alloc_lock);
+    ASSERT(!spin_is_locked(&heap_lock));
+    spin_lock(&heap_lock);
+
+    /* pages==0 means "unset" the claim (and flags is ignored) */
+    if (pages == 0)

xen/common/page_alloc.c static long midsize_alloc_zone_pages; · line 309

Quoted 10 lines
xen/common/page_alloc.c +10 -0
+    {
+        total_unclaimed_pages -= d->unclaimed_pages;
+        d->unclaimed_pages = 0;
+        ret = 0;
+        goto out;
+    }
+
+    /* only one active claim per domain please */
+    if ( d->unclaimed_pages)
+        goto out;

-ENOMEM for this case seems wrong.

Quoted 4 lines
xen/common/page_alloc.c +4 -0
+
+    /* how much memory is available? */
+    avail_pages = total_avail_pages;
+    if ( !(flags & XENMEM_CLAIMF_free_only) )

xen/common/page_alloc.c static long midsize_alloc_zone_pages; · line 323

Quoted 10 lines
xen/common/page_alloc.c +10 -0
+        avail_pages += tmem_freeable_pages();
+    avail_pages -= total_unclaimed_pages;
+
+    /*
+     * note, if domain has already allocated memory before making a claim 
+     * then the claim must take tot_pages into account
+     */
+    claim = pages - d->tot_pages;
+    if ( claim > avail_pages )
+        goto out;

What if pages < d->tot_pages?

Quoted 15 lines
xen/common/page_alloc.c +11 -0
+
+    /* yay, claim fits in available memory, stake the claim, success! */
+    d->unclaimed_pages = claim;
+    total_unclaimed_pages += d->unclaimed_pages;
+    ret = 0;
+
+out:
+    spin_unlock(&heap_lock);
+    spin_unlock(&d->page_alloc_lock);
+    return ret;
+}
 
 static unsigned long init_node_heap(int node, unsigned long mfn,
                                     unsigned long nr, bool_t *use_tail)

xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 546

Quoted 10 lines
xen/common/page_alloc.c +7 -0
@@ -443,6 +537,15 @@ static struct page_info *alloc_heap_pages(
     spin_lock(&heap_lock);
 
     /*
+     * Claimed memory is considered unavailable unless the request
+     * is made by a domain with sufficient unclaimed pages.
+     */
+    if ( (total_unclaimed_pages + request >
+           total_avail_pages + tmem_freeable_pages()) &&
+          (d == NULL || d->unclaimed_pages < request) )
+        goto not_found;

The treatment of d being NULL certainly needs further thought:
Is it really better to fulfill the claim and fail some (perhaps important) _xmalloc()?

Also, I'm missing a mechanism by which the tools could find out how much unclaimed memory is available, in order to determine (if in use) how much memory needs to be ballooned out of Dom0.

Similarly, but perhaps of lower priority, there is no integration with the low-mem handling.

Finally, there still are a number of formatting issues.

Jan

#2 lore raw
Quoted 5 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, November 15, 2012 3:25 AM
To: Dan Magenheimer
Cc: [email protected]; KonradWilk; Zhigang Wang; Keir Fraser; TimDeegan
Subject: Re: [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Hi Jan --

Thanks for the quick review!

Mostly fixed for v3 but a couple things:

Quoted 11 lines

xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 546

Quoted 7 lines
xen/common/page_alloc.c +7 -0
+     * Claimed memory is considered unavailable unless the request
+     * is made by a domain with sufficient unclaimed pages.
+     */
+    if ( (total_unclaimed_pages + request >
+           total_avail_pages + tmem_freeable_pages()) &&
+          (d == NULL || d->unclaimed_pages < request) )
+        goto not_found;

The treatment of d being NULL certainly needs further thought:
Is it really better to fulfill the claim and fail some (perhaps important) _xmalloc()?

Ideally, allocation in the presence of existing claims should behave as if the claiming domains had actually already allocated the unclaimed-amount-of-memory. So I'd argue that enforcing the claim should be sacrosanct here.

Quoted 3 lines

Also, I'm missing a mechanism by which the tools could find out how much unclaimed memory is available, in order to determine (if in use) how much memory needs to be ballooned out of Dom0.

OK. I'm not certain if this will be useful on a per-domain basis as well but, for completeness, I will also add unclaimed_pages into xc_dominfo etc (which causes a bump in XEN_DOMCTL_INTERFACE_VERSION).

Quoted 2 lines

Similarly, but perhaps of lower priority, there is no integration with the low-mem handling.

I'd also consider this lower priority as Olaf and Andre have argued that the claim mechanism is not needed for sharing/paging so the two mechanisms may not be used together, at least for the foreseeable future. So I plan to skip this, unless you change your mind and consider it a showstopper for acceptance.

Quoted 1 line

Finally, there still are a number of formatting issues.

Hmmm... I found one I think. Is there an equivalent to checkpatch for hypervisor code? If you see any formatting issues in v3, please call them out explicitly as I am sincerely trying to avoid them.

Thanks,
Dan

#3 lore raw
Quoted 11 lines
Quoted 4 lines
Quoted 1 line · Dan Magenheimer

From: Jan Beulich [mailto:[email protected]]
Similarly, but perhaps of lower priority, there is no integration with the low-mem handling.

I'd also consider this lower priority as Olaf and Andre have argued that the claim mechanism is not needed for sharing/paging so the two mechanisms may not be used together, at least for the foreseeable future. So I plan to skip this, unless you change your mind and consider it a showstopper for acceptance.

Skipping for the initial implementation is likely fine, but that shouldn't mean deferring the integration indefinitely. Also, I see no close connection between the low-mem feature and sharing/paging (apart from Andres working on both).

Jan

#4 lore raw
Quoted 18 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Friday, November 16, 2012 3:36 AM
To: Dan Magenheimer
Cc: [email protected]; Konrad Wilk; ZhigangWang; Keir Fraser; TimDeegan
Subject: RE: [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 11 lines
Quoted 4 lines
Quoted 1 line · Dan Magenheimer

From: Jan Beulich [mailto:[email protected]]
Similarly, but perhaps of lower priority, there is no integration with the low-mem handling.

I'd also consider this lower priority as Olaf and Andre have argued that the claim mechanism is not needed for sharing/paging so the two mechanisms may not be used together, at least for the foreseeable future. So I plan to skip this, unless you change your mind and consider it a showstopper for acceptance.

Quoted 4 lines

Skipping for the initial implementation is likely fine, but that shouldn't mean deferring the integration indefinitely. Also, I see no close connection between the low-mem feature and sharing/paging (apart from Andres working on both).

Fair enough.

After reviewing the thread where low_mem was submitted, I have to admit that I am a bit baffled as to when the low_mem handling would ever be
necessary. I suspect it is because the author and I are approaching
memory management from a completely different paradigm (per discussion in an earlier thread where "claim" was first proposed), so that is probably better left for the deferred discussion of the integration.

So since you (Jan) do not consider this (lack of integration with low_mem) a showstopper for claim, I will set myself a reminder to initiate a new thread about this later.

Thanks,
Dan

#5 lore raw
In reply to Dan Magenheimer
Quoted 10 lines · Dan Magenheimer

Note 1: Tim: I'm thinking this may resolve your concern that the claim mechanism must be more complicated to handle restricted memory allocations and order>0 allocations. The proposed claim mechanism only guarantees a quantity of order==0 pages; if restricted allocations are required, these are done first by the toolstack, and followed by the claim. Order>0 allocations still work if memory is not fragmented, but the claim mechanism doesn't guarantee anything but a quantity of order==0 pages.

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

Ian.

#6 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

This case is unreliable already, and has always been (I think we have a tools side hack in some of our trees in an attempt to deal with that), when ballooning is used to get at the memory, or when trying to start a 32-bit guest after having run 64-bit ones exhausting most of memory, and having terminated an early created one (as allocation is top down, ones created close to exhaustion, i.e. later, would eat up that "special" memory at lower addresses).

So this new functionality "only" makes a bad situation worse (which isn't meant to say I wouldn't prefer to see it get fixed).

Jan

#7 lore raw
Quoted 21 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, November 15, 2012 5:39 AM
To: Ian Campbell; Dan Magenheimer
Cc: [email protected]; Dave McCracken; KonradWilk; Zhigang Wang; Keir (Xen.org); Tim(Xen.org)
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 4 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

This case is unreliable already, and has always been (I think we have a tools side hack in some of our trees in an attempt to deal with that), when ballooning is used to get at the memory, or when trying to start a 32-bit guest after having run 64-bit ones exhausting most of memory, and having terminated an early created one (as allocation is top down, ones created close to exhaustion, i.e. later, would eat up that "special" memory at lower addresses).

Quoted 2 lines

So this new functionality "only" makes a bad situation worse (which isn't meant to say I wouldn't prefer to see it get fixed).

Hmmm... I guess I don't see how claim makes the situation worse. Well maybe a few microseconds worse.

Old model:
(1) Allocate a huge number of pages

New model:
(1) Claim a huge number of pages. If successful...
(2) Allocate that huge number of pages

In either case, the failure conditions are the same except that the claim mechanism checks one of the failure conditions sooner.

Or am I misunderstanding?

#8 lore raw
Quoted 37 lines
Quoted 6 lines
Quoted 1 line · Dan Magenheimer

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, November 15, 2012 5:39 AM
To: Ian Campbell; Dan Magenheimer
Cc: [email protected]; Dave McCracken; KonradWilk; Zhigang Wang; Keir

(Xen.org); Tim(Xen.org)

Quoted 1 line

Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 15 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines · Ian Campbell

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

This case is unreliable already, and has always been (I think we have a tools side hack in some of our trees in an attempt to deal with that), when ballooning is used to get at the memory, or when trying to start a 32-bit guest after having run 64-bit ones exhausting most of memory, and having terminated an early created one (as allocation is top down, ones created close to exhaustion, i.e. later, would eat up that "special" memory at lower addresses).

Quoted 2 lines

So this new functionality "only" makes a bad situation worse (which isn't meant to say I wouldn't prefer to see it get fixed).

Hmmm... I guess I don't see how claim makes the situation worse. Well maybe a few microseconds worse.

Old model:
(1) Allocate a huge number of pages

New model:
(1) Claim a huge number of pages. If successful...
(2) Allocate that huge number of pages

Quoted 5 lines

In either case, the failure conditions are the same except that the claim mechanism checks one of the failure conditions sooner.

Or am I misunderstanding?

I think you are: Your new code adds one more thing that isn't properly integrated with the creation of such guests. I.e. it's not the user experience getting worse, but the state of the code.

Jan

#9 lore raw
In reply to Ian Campbell
Quoted 23 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 10 lines · Dan Magenheimer

Note 1: Tim: I'm thinking this may resolve your concern that the claim mechanism must be more complicated to handle restricted memory allocations and order>0 allocations. The proposed claim mechanism only guarantees a quantity of order==0 pages; if restricted allocations are required, these are done first by the toolstack, and followed by the claim. Order>0 allocations still work if memory is not fragmented, but the claim mechanism doesn't guarantee anything but a quantity of order==0 pages.

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Quoted 6 lines

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

For 32 bit PV guests, note that a claim does NOT have to be staked prior to any allocation. So if a toolstack needs to enforce that some portion of allocated memory is under a host address limit, it can (attempt to) allocate those pages, then stake a claim for the rest. Or just not use the claim mechanism at all.

Dan

#10 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Dan Magenheimer

For 32 bit PV guests, note that a claim does NOT have to be staked prior to any allocation. So if a toolstack needs to enforce that some portion of allocated memory is under a host address limit, it can (attempt to) allocate those pages, then stake a claim for the rest. Or just not use the claim mechanism at all.

I don't get what you're trying to tell us here.

Jan

#11 lore raw
In reply to Dan Magenheimer
Quoted 30 lines · Dan Magenheimer
Quoted 23 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 10 lines · Dan Magenheimer

Note 1: Tim: I'm thinking this may resolve your concern that the claim mechanism must be more complicated to handle restricted memory allocations and order>0 allocations. The proposed claim mechanism only guarantees a quantity of order==0 pages; if restricted allocations are required, these are done first by the toolstack, and followed by the claim. Order>0 allocations still work if memory is not fragmented, but the claim mechanism doesn't guarantee anything but a quantity of order==0 pages.

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Quoted 6 lines

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

Quoted 6 lines

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

Well, you could always account the number of free superpages in the system, which would allow you to cover this case too.

Quoted 5 lines

For 32 bit PV guests, note that a claim does NOT have to be staked prior to any allocation. So if a toolstack needs to enforce that some portion of allocated memory is under a host address limit, it can (attempt to) allocate those pages, then stake a claim for the rest.

For 32 bit PV guests this is *all* of the pages needed to build any 32 bit PV guest.

Quoted 1 line

Or just not use the claim mechanism at all.

So your use case has no requirement to be able to start 32 bit domains? Or whatever requirement you have the leads to the claim mechanism somehow doesn't apply to those sorts of guests? If not then why not?

As it stands it seems that any toolstack which wants to use claim would still have to cope with the fact that a potentially significant proportion of guests may still fail to build even after a claim has been successfully staked.

Even if these shortcomings are acceptable in your specific scenario I don't see why we should be satisfied with a solution which is not more generally applicable.

Ian.

#12 lore raw
Quoted 2 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Hi Ian --

Quoted 28 lines · Dan Magenheimer
Quoted 20 lines
Quoted 13 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

On Wed, 2012-11-14 at 23:55 +0000, Dan Magenheimer wrote:

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Quoted 6 lines

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

Quoted 6 lines

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

Quoted 2 lines

Well, you could always account the number of free superpages in the system, which would allow you to cover this case too.

Because of the nature of the buddy allocator (i.e. 4MB chunks are kept separately from 2MB chunks even though a 4MB page contains two 2MB pages), I don't think this is trivial. Also, once memory is fragmented, creation of a PV-superpages domain will fail (relatively quickly) whether claiming first or not. The situation could be improved by adding defrag code to Xen (or "compaction" as Linux calls it), which I'd be interested in pursuing, but that is also non-trivial. Last, once PVH is an available option, community (and Oracle's) interest in PV+superpages may fade away quickly.

So I agree that this is worth adding superpages to a to-do list for future claim work, but I see it as a "would be nice to add later" feature, not a showstopper.

Quoted 8 lines
Quoted 5 lines

For 32 bit PV guests, note that a claim does NOT have to be staked prior to any allocation. So if a toolstack needs to enforce that some portion of allocated memory is under a host address limit, it can (attempt to) allocate those pages, then stake a claim for the rest.

For 32 bit PV guests this is *all* of the pages needed to build any 32 bit PV guest.

I am ignorant of the details here, but this is _all_ of the pages only on machines with >160GiB of physical memory, correct? (If incorrect, just ignore the 160GB parts below :-)

Quoted 5 lines
Quoted 1 line

Or just not use the claim mechanism at all.

So your use case has no requirement to be able to start 32 bit domains? Or whatever requirement you have the leads to the claim mechanism somehow doesn't apply to those sorts of guests? If not then why not?

Claim doesn't fail to start 32-bit PV domains, it just doesn't help them avoid "failing slowly" [on machines with >160GiB of RAM].

32-bit PV domains are highly likely to be legacy domains with much smaller RAM requirements [always <= 64GiB?] so "failing slowly" is much less of a concern.

32-bit PV domains are on their way to obsolescence so I am (and I believe Oracle would be) quite happy documenting that launching them might result in conditions not seen when creating other domain types... especially when other failure conditions already exist for 32-bit PV domains.

Quoted 4 lines

As it stands it seems that any toolstack which wants to use claim would still have to cope with the fact that a potentially significant proportion of guests may still fail to build even after a claim has been successfully staked.

The problem being addressed here is "slow failure" when creating a domain and this can currently occur with 100% of domain creations. The proposed claim hypercall solves this problem for:

- All HVM domains and all future PVH domains
- All 64-bit PV domains [when system RAM < 5TiB]
- [All 32-bit PV domains when system RAM < 160GiB]

and, as you've observed, currently doesn't solve the problem for

- All 32-bit PV domains [except when system RAM > 160 GiB]
- PV domains with superpages=1 that "almost succeed" but fail

I see that as a pretty good start and, with the flags argument, the proposal even has room for future extensions should they be needed.

Quoted 3 lines

Even if these shortcomings are acceptable in your specific scenario I don't see why we should be satisfied with a solution which is not more generally applicable.

I would welcome a solution which is more generally applicable if you've got one. Otherwise, I am very satisfied with this one. If you'd like confirmation from Oracle management that they are satisfied as well, I can encourage them to reply.

Dan

#13 lore raw
Quoted 36 lines
Quoted 3 lines
Quoted 1 line · Dan Magenheimer

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Hi Ian --

Quoted 3 lines · Dan Magenheimer
Quoted 2 lines
Quoted 2 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 25 lines
Quoted 24 lines
Quoted 11 lines · Dan Magenheimer

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Quoted 6 lines

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

Quoted 6 lines
Quoted 2 lines

Well, you could always account the number of free superpages in the system, which would allow you to cover this case too.

Because of the nature of the buddy allocator (i.e. 4MB chunks are kept separately from 2MB chunks even though a 4MB page contains two 2MB pages), I don't think this is trivial.

This ought to be as simple as adding respective accounting when
- splitting a chunk in alloc_heap_pages(), crossing the super page size boundary, and
- merging chunks in free_heap_pages(), crossing the super page size boundary.

Jan

#14 lore raw
Quoted 43 lines · Jan Beulich
Quoted 36 lines
Quoted 3 lines
Quoted 1 line · Dan Magenheimer

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Hi Ian --

Quoted 3 lines · Dan Magenheimer
Quoted 2 lines
Quoted 2 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 25 lines
Quoted 24 lines
Quoted 11 lines · Dan Magenheimer

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Also doesn't this fail to make any sort of guarantee if you are building a 32 bit PV guest, since they require memory under a certain host address limit (160GB IIRC)?

Quoted 6 lines

Basically neither of those cases benefit from this hypercall at all? I don't know what the usecase for the superpage PV guests is (but I suppose it is important to Oracle, at least). The 32 bit PV guest use case is still a pretty significant one which I think ought to be handled, otherwise any system built on top of this functionality will only work reliably in a subset of cases.

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

Quoted 6 lines
Quoted 2 lines

Well, you could always account the number of free superpages in the system, which would allow you to cover this case too.

Because of the nature of the buddy allocator (i.e. 4MB chunks are kept separately from 2MB chunks even though a 4MB page contains two 2MB pages), I don't think this is trivial.

Quoted 6 lines

This ought to be as simple as adding respective accounting when
- splitting a chunk in alloc_heap_pages(), crossing the super page size boundary, and
- merging chunks in free_heap_pages(), crossing the super page size boundary.

That was my first thought too.

Ian.

#15 lore raw
Quoted 36 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 32 lines · Jan Beulich
Quoted 31 lines
Quoted 3 lines
Quoted 1 line · Dan Magenheimer

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Hi Ian --

Quoted 3 lines · Dan Magenheimer
Quoted 2 lines
Quoted 2 lines

From: Ian Campbell [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 14 lines
Quoted 7 lines
Quoted 6 lines · Dan Magenheimer

How does this interact with the feature which lets you create PV guests using only superpages? I believe is something Oracle added and still maintains (Dave added to the CC).

Quoted 6 lines

The claim mechanism will not benefit PV superpages. IIUC, the design of the PV superpages will cause a domain launch to fail if it requests 10000 superpages but Xen can only successfully allocate 9999. That's already very fragile. Since the only way currently to find out if there are 10000 superpages available is to start allocating them, claim can't really help.

Quoted 2 lines

Well, you could always account the number of free superpages in the system, which would allow you to cover this case too.

Because of the nature of the buddy allocator (i.e. 4MB chunks are kept separately from 2MB chunks even though a 4MB page contains two 2MB pages), I don't think this is trivial.

Quoted 8 lines
Quoted 6 lines

This ought to be as simple as adding respective accounting when
- splitting a chunk in alloc_heap_pages(), crossing the super page size boundary, and
- merging chunks in free_heap_pages(), crossing the super page size boundary.

That was my first thought too.

Hi Ian and Jan --

I agree it's possible, just saying it's not trivial... one has to account not only for superpages system-wide (which isn't currently done) but a mix of unclaimed superpages and unclaimed order==0 pages per-domain. Especially since that would improve launch of only a small and shrinking class of domains (PV && superpages=1 && mem="huge"), can we please consider it a possible future enhancement, not a showstopper? The proposed claim hypercall doesn't _break_ PV-superpage domains, it just doesn't pre-fail domain launch when there is sufficient physical RAM but insufficient quantity of superpages. And the toolstack doesn't need to special-case... always doing a claim first is worthwhile because it still pre-fails the case where there is insufficient physical RAM.

(I'd ask Konrad or Kurt to chime in here, but I know both are away from the office due to the holidays... and I should be too.)

Thanks,
Dan

#16 lore raw
Quoted 6 lines · Dan Magenheimer

I agree it's possible, just saying it's not trivial... one has to account not only for superpages system-wide (which isn't currently done) but a mix of unclaimed superpages and unclaimed order==0 pages per-domain. Especially since that would improve launch of only a small and shrinking class of domains (PV && superpages=1 && mem="huge"), can we please consider it a possible future enhancement, not a showstopper?

Please, no. Either you need this benighted hypercall, or you don't. If you really need it, do it properly.

Tim.

#17 lore raw
Quoted 11 lines

From: Tim Deegan [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 6 lines · Dan Magenheimer

I agree it's possible, just saying it's not trivial... one has to account not only for superpages system-wide (which isn't currently done) but a mix of unclaimed superpages and unclaimed order==0 pages per-domain. Especially since that would improve launch of only a small and shrinking class of domains (PV && superpages=1 && mem="huge"), can we please consider it a possible future enhancement, not a showstopper?

Quoted 2 lines

Please, no. Either you need this benighted hypercall, or you don't. If you really need it, do it properly.

Hi Tim --

I must respectfully disagree.

For years, Xen has been accepting features that work on a 64-bit hypervisor but not on a 32-bit hypervisor. And new features such as memory-sharing/paging _could_ be designed to help PV domains and have completely ignored PV but have still been accepted. There is clearly precedent for new features that don't enhance every possible case.

The claim feature dramatically decreases a real customer problem in the vast majority of our customer environments with no loss of functionality in the small remaining percentage. This real problem is getting continually worse as system physical RAM and domain memory requirements increase. So, yes, _we_ do need it.

Considering maintenance, adding 100% claim support for remaining near-obsolescent domains will (IMHO) unnecessarily clutter both the hypervisor and the toolstack, with very little net value to real customers.

So, in my opinion, it _is_ done properly already, just not obsessively.

Dan

P.S. Did you mean "beknighted"? Or are you referring to your omniscient toolstack as enlightened and Oracle's toolstack as ignorant? As a fan of etymology and wordplay, I'm curious...

#18 lore raw
Quoted 27 lines
Quoted 3 lines
Quoted 1 line · Dan Magenheimer

From: Tim Deegan [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 11 lines
Quoted 6 lines · Dan Magenheimer

I agree it's possible, just saying it's not trivial... one has to account not only for superpages system-wide (which isn't currently done) but a mix of unclaimed superpages and unclaimed order==0 pages per-domain. Especially since that would improve launch of only a small and shrinking class of domains (PV && superpages=1 && mem="huge"), can we please consider it a possible future enhancement, not a showstopper?

Please, no. Either you need this benighted hypercall, or you don't. If you really need it, do it properly.

Hi Tim --

I must respectfully disagree.

For years, Xen has been accepting features that work on a 64-bit hypervisor but not on a 32-bit hypervisor. And new features such as memory-sharing/paging _could_ be designed to help PV domains and have completely ignored PV but have still been accepted. There is clearly precedent for new features that don't enhance every possible case.

Quoted 5 lines

The claim feature dramatically decreases a real customer problem in the vast majority of our customer environments with no loss of functionality in the small remaining percentage. This real problem is getting continually worse as system physical RAM and domain memory requirements increase. So, yes, _we_ do need it.

A meaningful difference is that those other features have tools side users, while you add (from the perspective of the Xen tree) dead code. That is, it wouldn't have any chance of getting checked for correctness when committed (other than for not breaking existing code), and it will bit rot pretty quickly. Or did you mean to supply tools side integration before expecting this to be considered for applying?

In any case, while the hypervisor side changes look acceptable, I'm afraid that without (mostly) convincing (almost) all of the maintainers, there's no perspective of this getting committed.

Jan

#19 lore raw
Quoted 37 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, November 21, 2012 1:32 AM
To: Dan Magenheimer
Cc: Ian Campbell; [email protected]; Dave Mccracken; Konrad Wilk; ZhigangWang; Keir (Xen.org); Tim Deegan
Subject: RE: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of existing) hypercall

Quoted 24 lines
Quoted 3 lines
Quoted 1 line · Dan Magenheimer

From: Tim Deegan [mailto:[email protected]]
Subject: Re: [Xen-devel] [RFC/PATCH v2] XENMEM_claim_pages (subop of

existing) hypercall

Quoted 8 lines
Quoted 3 lines · Dan Magenheimer

per-domain. Especially since that would improve launch of only a small and shrinking class of domains (PV && superpages=1 && mem="huge"), can we please consider it a possible future enhancement, not a showstopper?

Please, no. Either you need this benighted hypercall, or you don't. If you really need it, do it properly.

Hi Tim --

I must respectfully disagree.

For years, Xen has been accepting features that work on a 64-bit hypervisor but not on a 32-bit hypervisor. And new features such as memory-sharing/paging _could_ be designed to help PV domains and have completely ignored PV but have still been accepted. There is clearly precedent for new features that don't enhance every possible case.

Quoted 5 lines

The claim feature dramatically decreases a real customer problem in the vast majority of our customer environments with no loss of functionality in the small remaining percentage. This real problem is getting continually worse as system physical RAM and domain memory requirements increase. So, yes, _we_ do need it.

Quoted 7 lines

A meaningful difference is that those other features have tools side users, while you add (from the perspective of the Xen tree) dead code. That is, it wouldn't have any chance of getting checked for correctness when committed (other than for not breaking existing code), and it will bit rot pretty quickly. Or did you mean to supply tools side integration before expecting this to be considered for applying?

Oracle uses xm and a proprietary toolstack. I don't normally work on the toolstack (and other Oracle folk that do are tied up with a release right now)... I can probably come up with an xm/xend patch but I expect an xm/xend patch won't be well-received.

Quoted 3 lines

In any case, while the hypervisor side changes look acceptable, I'm afraid that without (mostly) convincing (almost) all of the maintainers, there's no perspective of this getting committed.

Thanks very much, Jan, for your repeated reviews and I'm very pleased that you think the hypervisor patch is acceptable.

I was under the impression that the hypervisor was supposed to be toolstack-independent. I think I've thoroughly explained Oracle's real customer need here... if advocates of other toolstacks don't understand it, it's not from lack of my trying. (More words have been spilled on this topic now than possibly any other 200 lines in Xen!)

If other maintainers wish to impose their toolstack requirements on other vendors' toolstacks and/or block hypervisor enhancements that don't fit with their idea of a toolstack's needs, I suppose that is a question that will need to be raised to the Xen Advisory Board, and that is above my pay grade.

Happy (U.S.) Thanksgiving!
Dan