Skip to contentSkip to conversation

balloon.py unaware of pages on page_scrub_list

DISCUSSION Charles Coffing 2 participants 3 messages Jun 19, 2006 – Jun 23, 2006 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

Suppose I create a domain with a "large" amount of memory (for some value of "large") and I set "on_crash" to be "reboot". Then I crash the domain. All the domain's memory gets put on the page_scrub_list. Then xend attempts to restart the domain. The balloon code in xend sees that very little memory is free, so it attempts to balloon dom0 down even more. At this point, the balloon code and the page scrubber are racing. The domain may fail to restart, or domain 0 may be squeezed down farther than necessary. If dom0-min-mem is not tuned for the machine, this can get ugly.

I think this applies to rebooting too, not just crashing.

Would it make sense to give this information to balloon.py, and apply some heuristics? Perhaps xend should wait for the scrub list to go to zero before trying to balloon. Or maybe it should consider that memory as free, and only try to balloon (needed - to_scrub).

The most obvious way (to me) to get that information to xend is via DOM0_PHYSINFO. That way, the number of free pages and the number of pages to scrub can be gotten atomically.

Thoughts?

I volunteer to code and test this if there's some agreement on how it should be done.

Thanks,
Chuck

#1 lore raw
Quoted 7 lines · Charles Coffing

Would it make sense to give this information to balloon.py, and apply some heuristics? Perhaps xend should wait for the scrub list to go to zero before trying to balloon. Or maybe it should consider that memory as free, and only try to balloon (needed - to_scrub).

The most obvious way (to me) to get that information to xend is via DOM0_PHYSINFO. That way, the number of free pages and the number of pages to scrub can be gotten atomically.

Thoughts?

I volunteer to code and test this if there's some agreement on how it should be done.

Your approach sounds fine to me.

-- Keir

#2 lore raw

Keir,

Attached is a patch that makes the ballooning logic in xend aware of pages that are on the page scrub list. This fixes the case where crashing/restarting a domain can cause dom0 to balloon more than necessary.

I changed the physinfo dictionary in Python to be in KiB, rather than MiB, to avoid accumulating ugly rounding errors. I tried to avoid changing units anywhere else.

The patch is against xen-unstable. It applies and works against xen-3.0-testing also (in fact that's where I did most of my testing) but I don't know if you want to apply it there. I changed the dom0_physinfo in a non-backwards-compatible way. Looked nicer to me to group the *_pages fields together, but that's probably not something you'd want to do in 3.0.2... your call.

Thanks,
Charles

Quoted 3 lines · Keir Fraser
Quoted 1 line · Charles Coffing

Would it make sense to give this information to balloon.py, and

apply

Quoted 1 line
Quoted 1 line

some heuristics? Perhaps xend should wait for the scrub list to go

to

Quoted 5 lines
Quoted 4 lines

zero before trying to balloon. Or maybe it should consider that memory as free, and only try to balloon (needed - to_scrub).

The most obvious way (to me) to get that information to xend is via

Quoted 7 lines
Quoted 7 lines

DOM0_PHYSINFO. That way, the number of free pages and the number of

pages to scrub can be gotten atomically.

Thoughts?

I volunteer to code and test this if there's some agreement on how

it

Quoted 11 lines
Quoted 1 line

should be done.

Your approach sounds fine to me.

-- Keir

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

tools/python/xen/lowlevel/xc/xc.c +11 -10
diff -ru xen-unstable.hg~/tools/python/xen/lowlevel/xc/xc.c xen-unstable.hg/tools/python/xen/lowlevel/xc/xc.c
@@ -582,6 +582,12 @@
 }
 
 
+static unsigned long pages_to_kib(unsigned long pages)
+{
+    return pages * (XC_PAGE_SIZE / 1024);
+}
+
+
 static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args)
 {
     unsigned long pages;
@@ -589,13 +595,7 @@
     if (!PyArg_ParseTuple(args, "l", &pages))
         return NULL;
 
-    return PyLong_FromUnsignedLong(pages * (XC_PAGE_SIZE / 1024));
-}
-
-
-static unsigned long pages_to_mb(unsigned long pages)
-{
-    return (pages * (XC_PAGE_SIZE / 1024) + 1023) / 1024;
+    return PyLong_FromUnsignedLong(pages_to_kib(pages));
 }
 
 
@@ -618,13 +618,14 @@
     if(q>cpu_cap)
         *(q-1)=0;
 
-    return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:i,s:s}",
+    return Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
                          "threads_per_core", info.threads_per_core,
                          "cores_per_socket", info.cores_per_socket,
                          "sockets_per_node", info.sockets_per_node,
                          "nr_nodes",         info.nr_nodes,
-                         "total_memory",     pages_to_mb(info.total_pages),
-                         "free_memory",      pages_to_mb(info.free_pages),
+                         "total_memory",     pages_to_kib(info.total_pages),
+                         "free_memory",      pages_to_kib(info.free_pages),
+                         "scrub_memory",     pages_to_kib(info.scrub_pages),
                          "cpu_khz",          info.cpu_khz,
                          "hw_caps",          cpu_cap);
 }
tools/python/xen/xend/balloon.py +37 -32

134 lines not on this page · raw message

tools/python/xen/xend/XendNode.py +3 -0
diff -ru xen-unstable.hg~/tools/python/xen/xend/XendNode.py xen-unstable.hg/tools/python/xen/xend/XendNode.py
@@ -64,6 +64,9 @@
                            info['cores_per_socket'] *
                            info['threads_per_core'])
         info['cpu_mhz'] = info['cpu_khz'] / 1000
+        # physinfo is in KiB
+        info['total_memory'] = info['total_memory'] / 1024
+        info['free_memory']  = info['free_memory'] / 1024
 
         ITEM_ORDER = ['nr_cpus',
                       'nr_nodes',
xen/arch/x86/dom0_ops.c +1 -0
diff -ru xen-unstable.hg~/xen/arch/x86/dom0_ops.c xen-unstable.hg/xen/arch/x86/dom0_ops.c
@@ -194,6 +194,7 @@
         pi->nr_nodes         = 1;
         pi->total_pages      = total_pages;
         pi->free_pages       = avail_domheap_pages();
+        pi->scrub_pages      = avail_scrub_pages();
         pi->cpu_khz          = cpu_khz;
         memset(pi->hw_cap, 0, sizeof(pi->hw_cap));
         memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
xen/common/page_alloc.c +8 -0
diff -ru xen-unstable.hg~/xen/common/page_alloc.c xen-unstable.hg/xen/common/page_alloc.c
@@ -61,6 +61,7 @@
 
 static DEFINE_SPINLOCK(page_scrub_lock);
 LIST_HEAD(page_scrub_list);
+static unsigned long scrub_pages;
 
 /*********************
  * ALLOCATION BITMAP
@@ -696,6 +697,7 @@
             {
                 spin_lock(&page_scrub_lock);
                 list_add(&pg[i].list, &page_scrub_list);
+                scrub_pages ++;
                 spin_unlock(&page_scrub_lock);
             }
         }
@@ -784,6 +786,7 @@
         /* Remove peeled pages from the list. */
         ent->next->prev = &page_scrub_list;
         page_scrub_list.next = ent->next;
+        scrub_pages -= (i+1);
         
         spin_unlock(&page_scrub_lock);
         
@@ -800,6 +803,11 @@
     } while ( (NOW() - start) < MILLISECS(1) );
 }
 
+unsigned long avail_scrub_pages(void)
+{
+    return scrub_pages;
+}
+
 static __init int page_scrub_init(void)
 {
     open_softirq(PAGE_SCRUB_SOFTIRQ, page_scrub_softirq);

Only in xen-unstable.hg/xen/common: page_alloc.c.orig

xen/include/public/dom0_ops.h +1 -0
diff -ru xen-unstable.hg~/xen/include/public/dom0_ops.h xen-unstable.hg/xen/include/public/dom0_ops.h
@@ -231,6 +231,7 @@
     uint32_t cpu_khz;
     uint64_t total_pages;
     uint64_t free_pages;
+    uint64_t scrub_pages;
     uint32_t hw_cap[8];
 };
 typedef struct dom0_physinfo dom0_physinfo_t;
xen/include/xen/mm.h +1 -0
diff -ru xen-unstable.hg~/xen/include/xen/mm.h xen-unstable.hg/xen/include/xen/mm.h
@@ -91,6 +91,7 @@
         if ( !list_empty(&page_scrub_list) )    \
             raise_softirq(PAGE_SCRUB_SOFTIRQ);  \
     } while ( 0 )
+unsigned long avail_scrub_pages(void);
 
 #include <asm/mm.h>
 

Only in xen-unstable.hg/xen/include/xen: mm.h.orig

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