diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-12-17 06:27:55 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-12-17 06:27:55 +0000 |
commit | 287d07f6a7b84d9caf6e734f987a02ef5de7561c (patch) | |
tree | 9621123f10a616f72073e5706d1e4fffa17d1889 /tools/xenpaging/file_ops.c | |
parent | c0c8c01d6776b3cb2c42a6a3c82e484992dc9265 (diff) | |
download | xen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.tar.gz xen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.tar.bz2 xen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.zip |
User-land tool for memory paging.
This tool will page out the specified number of pages from the specified
domain. When a paged out page is accessed, Xen will issue a request and
notify the tool over an event channel. The tool will process ther request,
page the page in, and notify Xen.
The current (default) policy tracks the 1024 most recently paged in pages
and will not choose to evict any of those. This is done with the assumption
that if a page is accessed, it is likely to be accessed again soon.
Signed-off-by: Patrick Colp <Patrick.Colp@citrix.com>
Diffstat (limited to 'tools/xenpaging/file_ops.c')
-rw-r--r-- | tools/xenpaging/file_ops.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/xenpaging/file_ops.c b/tools/xenpaging/file_ops.c new file mode 100644 index 0000000000..30c9385b23 --- /dev/null +++ b/tools/xenpaging/file_ops.c @@ -0,0 +1,83 @@ +/****************************************************************************** + * tools/xenpaging/file_ops.c + * + * Common file operations. + * + * Copyright (c) 2009 by Citrix (R&D) Ltd. (Patrick Colp) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include <unistd.h> +#include <xc_private.h> + + +#define page_offset(_pfn) (((off_t)(_pfn)) << PAGE_SHIFT) + + +static int file_op(int fd, void *page, int i, + ssize_t (*fn)(int, const void *, size_t)) +{ + off_t seek_ret; + int total; + int bytes; + int ret; + + seek_ret = lseek64(fd, i << PAGE_SHIFT, SEEK_SET); + + total = 0; + while ( total < PAGE_SIZE ) + { + bytes = fn(fd, page + total, PAGE_SIZE - total); + if ( bytes <= 0 ) + { + ret = -errno; + goto err; + } + + total += bytes; + } + + return 0; + + err: + return ret; +} + +static ssize_t my_read(int fd, const void *buf, size_t count) +{ + return read(fd, (void *)buf, count); +} + +int read_page(int fd, void *page, int i) +{ + return file_op(fd, page, i, &my_read); +} + +int write_page(int fd, void *page, int i) +{ + return file_op(fd, page, i, &write); +} + + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ |