xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xensource.com
Subject: [PATCH 4 of 9] xenpaging: move nominate+evict into single function
Date: Mon, 20 Feb 2012 21:48:06 +0100	[thread overview]
Message-ID: <1679965628f5fb2f4127.1329770886@probook.site> (raw)
In-Reply-To: <patchbomb.1329770882@probook.site>

# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1329769124 -3600
# Node ID 1679965628f5fb2f4127edcb0fc1d449f50f32d6
# Parent  41d398992bc05ec5c3d9c7e10f5d5156d8794725
xenpaging: move nominate+evict into single function

Move all code to evict a single gfn into one function. This simplifies
error handling in caller. The function returns -1 on fatal error, 0 on
success and 1 if the gfn cant be paged.

Signed-off-by: Olaf Hering <olaf@aepfle.de>

diff -r 41d398992bc0 -r 1679965628f5 tools/xenpaging/xenpaging.c
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -571,6 +571,11 @@ static void put_response(struct mem_even
     RING_PUSH_RESPONSES(back_ring);
 }
 
+/* Evict a given gfn
+ * Returns < 0 on fatal error
+ * Returns 0 on successful evict
+ * Returns > 0 if gfn can not be evicted
+ */
 static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int fd, int slot)
 {
     xc_interface *xch = paging->xc_handle;
@@ -580,31 +585,51 @@ static int xenpaging_evict_page(struct x
 
     DECLARE_DOMCTL;
 
+    /* Nominate page */
+    ret = xc_mem_paging_nominate(xch, paging->mem_event.domain_id, gfn);
+    if ( ret < 0 )
+    {
+        /* unpageable gfn is indicated by EBUSY */
+        if ( errno == EBUSY )
+            ret = 1;
+        else
+            PERROR("Error nominating page %lx", gfn);
+        goto out;
+    }
+
     /* Map page */
-    ret = -EFAULT;
     page = xc_map_foreign_pages(xch, paging->mem_event.domain_id, PROT_READ, &victim, 1);
     if ( page == NULL )
     {
         PERROR("Error mapping page %lx", gfn);
+        ret = -1;
         goto out;
     }
 
     /* Copy page */
     ret = write_page(fd, page, slot);
-    if ( ret != 0 )
+    if ( ret < 0 )
     {
         PERROR("Error copying page %lx", gfn);
         munmap(page, PAGE_SIZE);
+        ret = -1;
         goto out;
     }
 
+    /* Release page */
     munmap(page, PAGE_SIZE);
 
     /* Tell Xen to evict page */
     ret = xc_mem_paging_evict(xch, paging->mem_event.domain_id, gfn);
-    if ( ret != 0 )
+    if ( ret < 0 )
     {
-        PERROR("Error evicting page %lx", gfn);
+        /* A gfn in use is indicated by EBUSY */
+        if ( errno == EBUSY )
+        {
+                ret = 1;
+                DPRINTF("Nominated page %lx busy", gfn);
+        } else
+            PERROR("Error evicting page %lx", gfn);
         goto out;
     }
 
@@ -619,6 +644,8 @@ static int xenpaging_evict_page(struct x
     /* Record number of evicted pages */
     paging->num_paged_out++;
 
+    ret = 0;
+
  out:
     return ret;
 }
@@ -753,9 +780,10 @@ static int evict_victim(struct xenpaging
             ret = -EINTR;
             goto out;
         }
-        ret = xc_mem_paging_nominate(xch, paging->mem_event.domain_id, gfn);
-        if ( ret == 0 )
-            ret = xenpaging_evict_page(paging, gfn, fd, slot);
+
+        ret = xenpaging_evict_page(paging, gfn, fd, slot);
+        if ( ret < 0 )
+            goto out;
     }
     while ( ret );

  parent reply	other threads:[~2012-02-20 20:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-20 20:48 [PATCH 0 of 9] tools/xenpaging: cleanups and performance improvements Olaf Hering
2012-02-20 20:48 ` [PATCH 1 of 9] xenpaging: use flat index for pagefile and page-in requests Olaf Hering
2012-02-20 20:48 ` [PATCH 2 of 9] xenpaging: no poll timeout while page-out is in progress Olaf Hering
2012-02-20 20:48 ` [PATCH 3 of 9] xenpaging: reduce number of qemu cache flushes Olaf Hering
2012-02-20 20:48 ` Olaf Hering [this message]
2012-02-20 20:48 ` [PATCH 5 of 9] xenpaging: improve performance in policy_choose_victim Olaf Hering
2012-02-20 20:48 ` [PATCH 6 of 9] xenpaging: unify error handling Olaf Hering
2012-02-20 20:48 ` [PATCH 7 of 9] xenpaging: move pagefile filedescriptor into struct xenpaging Olaf Hering
2012-02-20 20:48 ` [PATCH 8 of 9] xenpaging: move page_buffer " Olaf Hering
2012-02-20 20:48 ` [PATCH 9 of 9] xenpaging: implement stack of free slots in pagefile Olaf Hering
2012-02-21 17:38 ` [PATCH 0 of 9] tools/xenpaging: cleanups and performance improvements Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1679965628f5fb2f4127.1329770886@probook.site \
    --to=olaf@aepfle.de \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).