xenpaging: libxl support
PATCH 1/1 xenpaging: libxl support
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1316099907 -7200
# Node ID c9a9779fd9581666c3276f95020ad12e8ceff930 # Parent 7fb21fac6d7d0a20a7af9aa2caa6fb4145ee3e23
xenpaging: libxl support
Add support to libxl for starting xenpaging, I send it out for review. It mimics what the code to start qemu-dm does.
The patch adds four new config options:
xenpaging=<int> , the number of pages to page-out xenpaging_dir=<string>, the working directory where the pagefile is stored xenpaging_debug=<int>, enable or disable debug output xenpaging_policy_mru_size=<int>, tweak the number of most-recently-used pages
There are still a few pieces missing like 'xl list -l'.
tools/libxl/libxl.h +1 -0
@@ -229,6 +229,7 @@ typedef struct {libxl_domain_create_info c_info;libxl_domain_build_info b_info;libxl_device_model_info dm_info; +libxl_xenpaging_info xp_info;int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs;
tools/libxl/libxl.idl +11 -0
@@ -190,6 +190,17 @@ by libxl_domain_build/restore. If either then the user is responsible for calling libxl_file_reference_unmap.""") +libxl_xenpaging_info = Struct("xenpaging_info",[ + ("xenpaging", integer, False, "number of pages"), + ("xenpaging_workdir", string, False, "directory to store guest page file"), + ("xenpaging_debug", bool, False, "enable debug output in pager"), + ("xenpaging_policy_mru_size", integer, False, "number of paged-in pages to keep in memory"), + ], + comment= +"""xenpaging information. + +Something review is missing""") + libxl_device_model_info = Struct("device_model_info",[ ("domid", libxl_domid), ("uuid", libxl_uuid, False, "this is use only with stubdom, and must be different from the domain uuid"),
tools/libxl/libxl_create.c +110 -0
128 lines not on this page · raw message
tools/libxl/libxl_internal.h +5 -0
@@ -251,6 +251,11 @@ typedef struct {libxl__spawn_starting *for_spawn; } libxl__device_model_starting; +typedef struct { +char *dom_path;/* from libxl_malloc, only for xp_xenstore_record_pid */ +int domid; +}libxl__xenpaging_starting ; +/* from xl_create */ _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid); _hidden int libxl__domain_build(libxl__gc *gc,
tools/libxl/xl_cmdimpl.c +16 -4
@@ -290,6 +290,7 @@ static void dolog(const char *file, intstatic void printf_info (int domid,libxl_domain_config *d_config, +libxl_xenpaging_info *xp_info,libxl_device_model_info *dm_info) {int i;
@@ -519,6 +520,7 @@ static void parse_config_data(const charconst char *configfile_data, int configfile_len, libxl_domain_config *d_config, + libxl_xenpaging_info *xp_info, libxl_device_model_info *dm_info) { const char *buf;
@@ -695,6 +697,15 @@ static void parse_config_data(const char b_info->u.hvm.timer_mode = l;if (!xlu_cfg_get_long (config,"nestedhvm" , &l)) b_info->u.hvm.nested_hvm = l; + +if (!xlu_cfg_get_long (config,"xenpaging" , &l)) + xp_info->xenpaging = l; +if (!xlu_cfg_get_long (config,"xenpaging_debug" , &l)) + xp_info->xenpaging_debug = l; +if (!xlu_cfg_get_long (config,"xenpaging_policy_mru_size" , &l)) + xp_info->xenpaging_policy_mru_size = l; +xlu_cfg_replace_string (config,"xenpaging_workdir" , &xp_info->xenpaging_workdir); +break ;case LIBXL_DOMAIN_TYPE_PV : {
@@ -1465,7 +1476,7 @@ static int create_domain(struct domain_cif (!dom_info->quiet)printf ("Parsing config file %s\n" , config_file); -parse_config_data (config_file, config_data, config_len, &d_config, &d_config.dm_info); +parse_config_data (config_file, config_data, config_len, &d_config, &d_config.xp_info, &d_config.dm_info);if (migrate_fd >=0 ) {if (d_config.c_info.name) {
@@ -1486,7 +1497,7 @@ static int create_domain(struct domain_c }if (debug || dom_info->dryrun) -printf_info (-1 , &d_config, &d_config.dm_info); +printf_info (-1 , &d_config, &d_config.xp_info, &d_config.dm_info); ret =0 ;if (dom_info->dryrun)
@@ -2211,6 +2222,7 @@ static void list_domains_details(const luint8_t *data;int i, len, rc;libxl_device_model_info dm_info; +libxl_xenpaging_info xp_info;for (i =0 ; i < nb_domain; i++) {/* no detailed info available on dom0 */
@@ -2221,8 +2233,8 @@ static void list_domains_details(const lcontinue ;CHK_ERRNO (asprintf (&config_file,"<domid %d data>" , info[i].domid));memset (&d_config,0x00 ,sizeof (d_config)); -parse_config_data (config_file, (char *)data, len, &d_config, &dm_info); -printf_info (info[i].domid, &d_config, &dm_info); +parse_config_data (config_file, (char *)data, len, &d_config, &xp_info, &dm_info); +printf_info (info[i].domid, &d_config, &xp_info, &dm_info);libxl_domain_config_destroy (&d_config);free (data);free (config_file);
Quoted 35 lines · Olaf Hering
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1316099907 -7200
# Node IDc9a9779fd9581666c3276f95020ad12e8ceff930# Parent7fb21fac6d7d0a20a7af9aa2caa6fb4145ee3e23
xenpaging: libxl supportAdd support to libxl for starting xenpaging, I send it out for review. It mimics what the code to start qemu-dm does.
The patch adds four new config options:
xenpaging=<int> , the number of pages to page-out xenpaging_dir=<string>, the working directory where the pagefile is stored xenpaging_debug=<int>, enable or disable debug output xenpaging_policy_mru_size=<int>, tweak the number of most-recently-used pagesThere are still a few pieces missing like 'xl list -l'.
Signed-off-by Olaf Hering <[email protected]>diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/libxl.htools/libxl/libxl.h +1
-0@@ -229,6 +229,7 @@ typedef struct {libxl_domain_create_info c_info;libxl_domain_build_info b_info;libxl_device_model_info dm_info; +libxl_xenpaging_info xp_info;int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs;diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/libxl.idl
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 193
Quoted 4 lines
tools/libxl/libxl.idl +1
-0@@ -190,6 +190,17 @@ by libxl_domain_build/restore. If either then the user is responsible for calling libxl_file_reference_unmap.""") +libxl_xenpaging_info = Struct("xenpaging_info",[
I'm not convinced this needs to be it's own struct (rather than being part of e.g. build_info or create_info) but I don't feel particularly strongly one way or the other.
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 195
Quoted 2 lines
tools/libxl/libxl.idl +2
-0+ ("xenpaging", integer, False, "number of pages"), + ("xenpaging_workdir", string, False, "directory to store guest page file"),
Really a directory or actually a file? xenpaging_path would probably be a nicer name.
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 196
Quoted 1 line
tools/libxl/libxl.idl +1
-0+ ("xenpaging_debug", bool, False, "enable debug output in pager"),
Perhaps a generic "extra_arguments" type field (string) would be more useful?
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 197
Quoted 1 line
tools/libxl/libxl.idl +1
-0+ ("xenpaging_policy_mru_size", integer, False, "number of paged-in pages to keep in memory"),
How is the distinct from / related to the xenpaging integer?
Quoted 13 lines
tools/libxl/libxl.idl +6
-0+ ], + comment= +"""xenpaging information. + +Something review is missing""") + libxl_device_model_info = Struct("device_model_info",[ ("domid", libxl_domid), ("uuid", libxl_uuid, False, "this is use only with stubdom, and must be different from the domain uuid"),diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/libxl_create.c
tools/libxl/libxl_create.c retry_transaction: · line 434
Quoted 6 lines
tools/libxl/libxl_create.c +3
-0@@ -429,6 +429,109 @@ retry_transaction:return rc; } +static void xp_xenstore_record_pid (void *for_spawn,pid_t innerchild) +{ +libxl__device_model_starting *starting = for_spawn;
Do you mean libxl__xenpaging_starting here?
It looks like xp_xenstore_record_pid could be shared with the dm one with only a little refactoring/abstraction.
tools/libxl/libxl_create.c retry_transaction: · line 490
Quoted 7 lines
tools/libxl/libxl_create.c +5
-0+static int libxl__create_xenpaging (libxl__gc *gc,char *dom_name,uint32_t domid,libxl_xenpaging_info *xp_info) +{ +/* Set working directory if not specified in config file */ +if (!xp_info->xenpaging_workdir) + xp_info->xenpaging_workdir ="/var/lib/xen/xenpaging" ;
Should come from libxl_paths, see e.g. libxl_sbindir_path().
tools/libxl/libxl_create.c retry_transaction: · line 510
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+/* Spawn the child */ + rc =libxl__spawn_spawn (gc,NULL ,"xenpaging" , xp_xenstore_record_pid, &buf_starting);
No libxl__spawn_starting argument. Do you handle failure to exec etc?
I wonder if we should make that argument to spawn_spawn mandatory?
tools/libxl/libxl_create.c retry_transaction: · line 520
Quoted 10 lines
tools/libxl/libxl_create.c +10
-0+if (rc <0 ) + goto out_close; +if (!rc) {/* inner child */ +setsid (); +/* Enable debug output in the child */ +if (xp_info->xenpaging_debug) +setenv ("XENPAGING_DEBUG" ,"1" ,1 ); +/* Adjust most-recently-used value in the child */ +if (xp_info->xenpaging_policy_mru_size) +setenv ("XENPAGING_POLICY_MRU_SIZE" ,libxl__sprintf (gc,"%d" , xp_info->xenpaging_policy_mru_size),1 );
I think the xenpaging binary should have a proper command line interface rather than passing them via the environment.
In the case of the policy mru size perhaps that should be in xenstore such that it can be changed on the fly?
Quoted 19 lines
diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/libxl_internal.htools/libxl/libxl_internal.h +5
-0@@ -251,6 +251,11 @@ typedef struct {libxl__spawn_starting *for_spawn; } libxl__device_model_starting; +typedef struct { +char *dom_path;/* from libxl_malloc, only for xp_xenstore_record_pid */ +int domid; +}libxl__xenpaging_starting ; +/* from xl_create */ _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid); _hidden int libxl__domain_build(libxl__gc *gc,diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.c static void dolog(const char *file, int · line 293
Quoted 4 lines
tools/libxl/xl_cmdimpl.c +1
-0@@ -290,6 +290,7 @@ static void dolog(const char *file, int static void printf_info(int domid, libxl_domain_config *d_config, + libxl_xenpaging_info *xp_info,
xp_info is d_config->xpo_info or something isn't it?
I'm not sure why dm_info is called out specially though. I think perhaps because of stubdomains there can be more than one so we need to pass round the relevant one for the context. Or maybe it's just a historical wart. In either case it doesn't really apply to the xp_info.
tools/libxl/xl_cmdimpl.c static void parse_config_data(const char · line 523
Quoted 8 lines
tools/libxl/xl_cmdimpl.c +1
-0libxl_device_model_info *dm_info) {int i;@@ -519,6 +520,7 @@ static void parse_config_data(const charconst char *configfile_data, int configfile_len, libxl_domain_config *d_config, + libxl_xenpaging_info *xp_info,
Same comment as above.
Did I miss a call to libxl_xenpaging_info_destroy() somewhere or does this leak?
Ian.
Quoted 5 lines · Ian Campbell
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 195
Quoted 2 lines
tools/libxl/libxl.idl +2
-0+ ("xenpaging", integer, False, "number of pages"), + ("xenpaging_workdir", string, False, "directory to store guest page file"),Really a directory or actually a file?
xenpaging_pathwould probably be a nicer name.
Yes, that could be changed. Right now xenpaging opens the file in the current directory. But since all config values could be passed via xenstore, it may contain the full path to the paging file as well.
Quoted 4 lines
Quoted 1 line
+ ("
xenpaging_debug", bool, False, "enable debug output in pager"),Perhaps a generic "
extra_arguments" type field (string) would be more useful?
Yes, that would work too.
Quoted 3 lines
Quoted 1 line
+ ("
xenpaging_policy_mru_size", integer, False, "number of paged-in pages to keep in memory"),How is the distinct from / related to the xenpaging integer?
It defines how many pages are seen as "hot" by xenpaging, they wont be paged-out again until that many other pages were paged-in. See tools/xenpaging/policy_default.c:policy_notify_paged_in(). For example, a value of less than 1024 for a fully paged-out guest will make it nearly unusuable. But a guest with a smaller xenpaging value can also have a smaller mru size.
Quoted 5 lines
tools/libxl/libxl_create.c retry_transaction: · line 434
Quoted 3 lines
tools/libxl/libxl_create.c +3
-0+static void xp_xenstore_record_pid (void *for_spawn,pid_t innerchild) +{ +libxl__device_model_starting *starting = for_spawn;Do you mean
libxl__xenpaging_startinghere?
Yes, thats a typo. I did just copy&paste.
Quoted 2 lines
It looks like
xp_xenstore_record_pidcould be shared with the dm one with only a little refactoring/abstraction.
Yes, but could share the same struct libxl__*_starting.
Quoted 9 lines
tools/libxl/libxl_create.c retry_transaction: · line 490
Quoted 7 lines
tools/libxl/libxl_create.c +5
-0+static int libxl__create_xenpaging (libxl__gc *gc,char *dom_name,uint32_t domid,libxl_xenpaging_info *xp_info) +{ +/* Set working directory if not specified in config file */ +if (!xp_info->xenpaging_workdir) + xp_info->xenpaging_workdir ="/var/lib/xen/xenpaging" ;Should come from
libxl_paths, see e.g.libxl_sbindir_path().
I will update that part.
Quoted 4 lines
tools/libxl/libxl_create.c retry_transaction: · line 510
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+/* Spawn the child */ + rc =libxl__spawn_spawn (gc,NULL ,"xenpaging" , xp_xenstore_record_pid, &buf_starting);No
libxl__spawn_startingargument. Do you handle failure to exec etc?
I will update that part.
Quoted 11 lines
tools/libxl/libxl_create.c retry_transaction: · line 520
Quoted 10 lines
tools/libxl/libxl_create.c +10
-0+if (rc <0 ) + goto out_close; +if (!rc) {/* inner child */ +setsid (); +/* Enable debug output in the child */ +if (xp_info->xenpaging_debug) +setenv ("XENPAGING_DEBUG" ,"1" ,1 ); +/* Adjust most-recently-used value in the child */ +if (xp_info->xenpaging_policy_mru_size) +setenv ("XENPAGING_POLICY_MRU_SIZE" ,libxl__sprintf (gc,"%d" , xp_info->xenpaging_policy_mru_size),1 );
Quoted 2 lines
I think the xenpaging binary should have a proper command line interface rather than passing them via the environment.
I will add a --debug option.
Quoted 2 lines
In the case of the policy mru size perhaps that should be in xenstore such that it can be changed on the fly?
Changing it on the fly needs some refactoring of the code, but it should be doable.
Quoted 20 lines
Quoted 20 lines
diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/libxl_internal.htools/libxl/libxl_internal.h +5
-0@@ -251,6 +251,11 @@ typedef struct {libxl__spawn_starting *for_spawn; } libxl__device_model_starting; +typedef struct { +char *dom_path;/* from libxl_malloc, only for xp_xenstore_record_pid */ +int domid; +}libxl__xenpaging_starting ; +/* from xl_create */ _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid); _hidden int libxl__domain_build(libxl__gc *gc,diff -r
7fb21fac6d7d-rc9a9779fd958tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +0
-0@@ -290,6 +290,7 @@ static void dolog(const char *file, int
Quoted 5 lines
tools/libxl/xl_cmdimpl.c static void dolog(const char *file, int · line 293
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +1
-0static void printf_info(int domid, libxl_domain_config *d_config, + libxl_xenpaging_info *xp_info,
xp_infoisd_config->xpo_infoor something isn't it?
Yes, depends were it ends up. I will move it elsewhere.
Quoted 2 lines
Did I miss a call to
libxl_xenpaging_info_destroy()somewhere or does this leak?
I will check.
Thanks for the comments.
Olaf
Olaf Hering writes ("[Xen-devel] [PATCH] xenpaging: libxl support"):
Quoted 2 lines
The patch adds four new config options:
xenpaging=<int> , the number of pages to page-out
...
Quoted 2 lines
tools/libxl/libxl.idl +2
-0+libxl_xenpaging_info = Struct("xenpaging_info",[ + ("xenpaging", integer, False, "number of pages"),
...
tools/libxl/xl_cmdimpl.c static void parse_config_data(const char · line 702
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2
-0+if (!xlu_cfg_get_long (config,"xenpaging" , &l)) + xp_info->xenpaging = l;
The config file setting should be a number of megabytes, just like "memory", "maxmem", etc., not a number of pages. And at the libxl interface it should be a number of kilobytes like max_memkb et al.
Also as I said at the hackathon, I think that we need a more sophisticated approach to the interaction with ballooning. I would like to see the argument to the xenpaging daemon not be a target number of pages to page out, but rather for it to be a total memory usage target.
The effect of this would be that you could tell a guest to balloon down, but also tell xenpaging to page it out, and balance between ballooning and paging is then up to the guest.
tools/libxl/libxl_create.c retry_transaction:
Quoted 3 lines
tools/libxl/libxl_create.c +3
-0+static int libxl__create_xenpaging (libxl__gc *gc,char *dom_name,uint32_t domid,libxl_xenpaging_info *xp_info) +{ + [a lot of stuff]
Can any of this be factored out and made common with the device model creation ?
Also:
- what deletes the logfile, if anything ?
- will the xenpaging daemon automatically exit if the domain dies ?
Ian.
Quoted 6 lines · Ian Jackson
Olaf Hering writes ("[Xen-devel] [PATCH] xenpaging: libxl support"):
Quoted 2 lines
The patch adds four new config options:
xenpaging=<int> , the number of pages to page-out...
tools/libxl/libxl.idl by libxl_domain_build/restore. If either · line 194
Quoted 2 lines
tools/libxl/libxl.idl +2
-0+libxl_xenpaging_info = Struct("xenpaging_info",[ + ("xenpaging", integer, False, "number of pages"),
Quoted 7 lines
...
tools/libxl/xl_cmdimpl.c static void parse_config_data(const char · line 702
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2
-0+if (!xlu_cfg_get_long (config,"xenpaging" , &l)) + xp_info->xenpaging = l;The config file setting should be a number of megabytes, just like "memory", "maxmem", etc., not a number of pages. And at the libxl interface it should be a number of kilobytes like
max_memkbet al.
I will change that part.
Quoted 5 lines
Also as I said at the hackathon, I think that we need a more sophisticated approach to the interaction with ballooning. I would like to see the argument to the xenpaging daemon not be a target number of pages to page out, but rather for it to be a total memory usage target.
That would mean xenpaging has to monitor tot_pages and try to reach the configured number?
Quoted 3 lines
The effect of this would be that you could tell a guest to balloon down, but also tell xenpaging to page it out, and balance between ballooning and paging is then up to the guest.
Does a guest even know its paged? If I understand it correctly, mem-set will ask the guests balloon driver to work toward that number, but if xenpaging is instructed to page-out the entire guest, the guest wont notice it.
A new mem-tot_pages command (with a better name) would limit the amount of consumed mfns, while mem-set would limit the amount of mfns the guest balloon driver thinks it has.
Is it that what you have in mind?
Quoted 6 lines
tools/libxl/libxl_create.c retry_transaction:
Quoted 3 lines
tools/libxl/libxl_create.c +3
-0+static int libxl__create_xenpaging (libxl__gc *gc,char *dom_name,uint32_t domid,libxl_xenpaging_info *xp_info) +{ + [a lot of stuff]Can any of this be factored out and made common with the device model creation ?
Yes. The current device model startup uses the spawn functions, and things like *_record_pid and libxl__wait_for_* should be part of the spawn interface itself because the way libxl__spawn_spawn works a read from the pipe has to happen in some way. I will prepare patches for review.
Quoted 2 lines
Also:
- what deletes the logfile, if anything ?
The pagefile is unlinked by xenpaging on exit.
Quoted 1 line
- will the xenpaging daemon automatically exit if the domain dies ?
xenpaging has a watch on @releaseDomain.
Olaf