From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xensource.com
Subject: [PATCH 7 of 9] xenpaging: move pagefile filedescriptor into struct xenpaging
Date: Mon, 20 Feb 2012 21:48:09 +0100 [thread overview]
Message-ID: <c137d7bd207b7b21d69b.1329770889@probook.site> (raw)
In-Reply-To: <patchbomb.1329770882@probook.site>
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1329769124 -3600
# Node ID c137d7bd207b7b21d69bd6470be285023a4c2baf
# Parent e4b7da7e355998a404252777c274e8e149ce7a63
xenpaging: move pagefile filedescriptor into struct xenpaging
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r e4b7da7e3559 -r c137d7bd207b tools/xenpaging/xenpaging.c
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -448,6 +448,14 @@ static struct xenpaging *xenpaging_init(
goto err;
}
+ /* Open file */
+ paging->fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
+ if ( paging->fd < 0 )
+ {
+ PERROR("failed to open file");
+ goto err;
+ }
+
return paging;
err:
@@ -562,7 +570,7 @@ static void put_response(struct mem_even
* 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)
+static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int slot)
{
xc_interface *xch = paging->xc_handle;
void *page;
@@ -593,7 +601,7 @@ static int xenpaging_evict_page(struct x
}
/* Copy page */
- ret = write_page(fd, page, slot);
+ ret = write_page(paging->fd, page, slot);
if ( ret < 0 )
{
PERROR("Error copying page %lx", gfn);
@@ -670,7 +678,7 @@ static int xenpaging_resume_page(struct
return ret;
}
-static int xenpaging_populate_page(struct xenpaging *paging, unsigned long gfn, int fd, int i)
+static int xenpaging_populate_page(struct xenpaging *paging, unsigned long gfn, int i)
{
xc_interface *xch = paging->xc_handle;
int ret;
@@ -679,7 +687,7 @@ static int xenpaging_populate_page(struc
DPRINTF("populate_page < gfn %lx pageslot %d\n", gfn, i);
/* Read page */
- ret = read_page(fd, paging_buffer, i);
+ ret = read_page(paging->fd, paging_buffer, i);
if ( ret != 0 )
{
PERROR("Error reading page");
@@ -738,7 +746,7 @@ static void resume_pages(struct xenpagin
* Returns 0 on successful evict
* Returns > 0 if no gfn can be evicted
*/
-static int evict_victim(struct xenpaging *paging, int fd, int slot)
+static int evict_victim(struct xenpaging *paging, int slot)
{
xc_interface *xch = paging->xc_handle;
unsigned long gfn;
@@ -771,7 +779,7 @@ static int evict_victim(struct xenpaging
goto out;
}
- ret = xenpaging_evict_page(paging, gfn, fd, slot);
+ ret = xenpaging_evict_page(paging, gfn, slot);
if ( ret < 0 )
goto out;
}
@@ -791,7 +799,7 @@ static int evict_victim(struct xenpaging
* Returns 0 if no gfn can be evicted
* Returns > 0 on successful evict
*/
-static int evict_pages(struct xenpaging *paging, int fd, int num_pages)
+static int evict_pages(struct xenpaging *paging, int num_pages)
{
xc_interface *xch = paging->xc_handle;
int rc, slot, num = 0;
@@ -802,7 +810,7 @@ static int evict_pages(struct xenpaging
if ( paging->slot_to_gfn[slot] )
continue;
- rc = evict_victim(paging, fd, slot);
+ rc = evict_victim(paging, slot);
if ( rc )
{
num = rc < 0 ? -1 : num;
@@ -826,10 +834,6 @@ int main(int argc, char *argv[])
int rc;
xc_interface *xch;
- int open_flags = O_CREAT | O_TRUNC | O_RDWR;
- mode_t open_mode = S_IRUSR | S_IWUSR;
- int fd;
-
/* Initialise domain paging */
paging = xenpaging_init(argc, argv);
if ( paging == NULL )
@@ -841,14 +845,6 @@ int main(int argc, char *argv[])
DPRINTF("starting %s for domain_id %u with pagefile %s\n", argv[0], paging->mem_event.domain_id, filename);
- /* Open file */
- fd = open(filename, open_flags, open_mode);
- if ( fd < 0 )
- {
- perror("failed to open file");
- return 2;
- }
-
/* ensure that if we get a signal, we'll do cleanup, then exit */
act.sa_handler = close_handler;
act.sa_flags = 0;
@@ -911,7 +907,7 @@ int main(int argc, char *argv[])
else
{
/* Populate the page */
- if ( xenpaging_populate_page(paging, req.gfn, fd, slot) < 0 )
+ if ( xenpaging_populate_page(paging, req.gfn, slot) < 0 )
{
ERROR("Error populating page %"PRIx64"", req.gfn);
goto out;
@@ -1005,7 +1001,7 @@ int main(int argc, char *argv[])
paging->use_poll_timeout = 0;
num = 42;
}
- if ( evict_pages(paging, fd, num) < 0 )
+ if ( evict_pages(paging, num) < 0 )
goto out;
}
/* Resume some pages if target not reached */
@@ -1033,7 +1029,7 @@ int main(int argc, char *argv[])
DPRINTF("xenpaging got signal %d\n", interrupted);
out:
- close(fd);
+ close(paging->fd);
unlink_pagefile();
/* Tear down domain paging */
diff -r e4b7da7e3559 -r c137d7bd207b tools/xenpaging/xenpaging.h
--- a/tools/xenpaging/xenpaging.h
+++ b/tools/xenpaging/xenpaging.h
@@ -50,6 +50,7 @@ struct xenpaging {
int *gfn_to_slot;
struct mem_event mem_event;
+ int fd;
/* number of pages for which data structures were allocated */
int max_pages;
int num_paged_out;
next prev 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 ` [PATCH 4 of 9] xenpaging: move nominate+evict into single function Olaf Hering
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 ` Olaf Hering [this message]
2012-02-20 20:48 ` [PATCH 8 of 9] xenpaging: move page_buffer into struct xenpaging 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=c137d7bd207b7b21d69b.1329770889@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).