changeset:   23874:651aed73b39c
user:        Olaf Hering <olafiaepfle.de>
date:        Mon Sep 26 22:19:42 2011 +0100
files:       tools/libxc/xc_domain.c tools/libxc/xenctrl.h xen/arch/x86/mm/p2m.c xen/common/domctl.c xen/include/public/domctl.h xen/include/xen/sched.h
description:
xenpaging: track number of paged pages in struct domain

The toolstack should know how many pages are paged-out at a given point
in time so it could make smarter decisions about how many pages should
be paged or ballooned.

Add a new member to xen_domctl_getdomaininfo and bump interface version.
Use the new member in xc_dominfo_t.
The SONAME of libxc should be changed if this patch gets applied.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Tim Deegan <tim@xen.org>


---
 tools/libxc/xc_domain.c     |    1 +
 tools/libxc/xenctrl.h       |    1 +
 xen/arch/x86/mm/p2m.c       |    5 +++++
 xen/common/domctl.c         |    1 +
 xen/include/public/domctl.h |    3 ++-
 xen/include/xen/sched.h     |    1 +
 6 files changed, 11 insertions(+), 1 deletion(-)

Index: xen-4.1.4-testing/tools/libxc/xc_domain.c
===================================================================
--- xen-4.1.4-testing.orig/tools/libxc/xc_domain.c
+++ xen-4.1.4-testing/tools/libxc/xc_domain.c
@@ -235,6 +235,7 @@ int xc_domain_getinfo(xc_interface *xch,
         info->ssidref  = domctl.u.getdomaininfo.ssidref;
         info->nr_pages = domctl.u.getdomaininfo.tot_pages;
         info->nr_shared_pages = domctl.u.getdomaininfo.shr_pages;
+        info->nr_paged_pages = domctl.u.getdomaininfo.paged_pages;
         info->max_memkb = domctl.u.getdomaininfo.max_pages << (PAGE_SHIFT-10);
         info->shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
         info->cpu_time = domctl.u.getdomaininfo.cpu_time;
Index: xen-4.1.4-testing/tools/libxc/xenctrl.h
===================================================================
--- xen-4.1.4-testing.orig/tools/libxc/xenctrl.h
+++ xen-4.1.4-testing/tools/libxc/xenctrl.h
@@ -353,6 +353,7 @@ typedef struct xc_dominfo {
     unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
     unsigned long nr_pages; /* current number, not maximum */
     unsigned long nr_shared_pages;
+    unsigned long nr_paged_pages;
     unsigned long shared_info_frame;
     uint64_t      cpu_time;
     unsigned long max_memkb;
Index: xen-4.1.4-testing/xen/arch/x86/mm/p2m.c
===================================================================
--- xen-4.1.4-testing.orig/xen/arch/x86/mm/p2m.c
+++ xen-4.1.4-testing/xen/arch/x86/mm/p2m.c
@@ -2924,6 +2924,9 @@ int p2m_mem_paging_evict(struct p2m_doma
     /* Put the page back so it gets freed */
     put_page(page);
 
+    /* Track number of paged gfns */
+    atomic_inc(&p2m->domain->paged_pages);
+
     return 0;
 }
 
@@ -3008,6 +3011,8 @@ int p2m_mem_paging_prep(struct p2m_domai
     audit_p2m(p2m, 1);
     p2m_unlock(p2m);
 
+    atomic_dec(&p2m->domain->paged_pages);
+
     return 0;
 }
 
Index: xen-4.1.4-testing/xen/common/domctl.c
===================================================================
--- xen-4.1.4-testing.orig/xen/common/domctl.c
+++ xen-4.1.4-testing/xen/common/domctl.c
@@ -140,6 +140,7 @@ void getdomaininfo(struct domain *d, str
     info->tot_pages         = d->tot_pages;
     info->max_pages         = d->max_pages;
     info->shr_pages         = atomic_read(&d->shr_pages);
+    info->paged_pages       = atomic_read(&d->paged_pages);
     info->shared_info_frame = mfn_to_gmfn(d, __pa(d->shared_info)>>PAGE_SHIFT);
     BUG_ON(SHARED_M2P(info->shared_info_frame));
 
Index: xen-4.1.4-testing/xen/include/public/domctl.h
===================================================================
--- xen-4.1.4-testing.orig/xen/include/public/domctl.h
+++ xen-4.1.4-testing/xen/include/public/domctl.h
@@ -35,7 +35,7 @@
 #include "xen.h"
 #include "grant_table.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000007
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000008
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
@@ -95,6 +95,7 @@ struct xen_domctl_getdomaininfo {
     uint64_aligned_t tot_pages;
     uint64_aligned_t max_pages;
     uint64_aligned_t shr_pages;
+    uint64_aligned_t paged_pages;
     uint64_aligned_t shared_info_frame; /* GMFN of shared_info struct */
     uint64_aligned_t cpu_time;
     uint32_t nr_online_vcpus;    /* Number of VCPUs currently online. */
Index: xen-4.1.4-testing/xen/include/xen/sched.h
===================================================================
--- xen-4.1.4-testing.orig/xen/include/xen/sched.h
+++ xen-4.1.4-testing/xen/include/xen/sched.h
@@ -215,6 +215,7 @@ struct domain
     unsigned int     tot_pages;       /* number of pages currently possesed */
     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          */
     unsigned int     xenheap_pages;   /* # pages allocated from Xen heap    */
 
     unsigned int     max_vcpus;
