diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2010-12-14 19:04:03 +0000 |
---|---|---|
committer | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2010-12-14 19:04:03 +0000 |
commit | cd55de70cac1981633f5109edebca989330067b4 (patch) | |
tree | ec60f1da0b5fed1d01f89f1bd37ed9e3a742b397 /tools | |
parent | 78bae44397633621fcf32d191f9e83692c216115 (diff) | |
download | xen-cd55de70cac1981633f5109edebca989330067b4.tar.gz xen-cd55de70cac1981633f5109edebca989330067b4.tar.bz2 xen-cd55de70cac1981633f5109edebca989330067b4.zip |
libxl: do not assume target and freemem-slack are written at the same time
This improves robustness in some pathological configurations.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Tested-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libxl/libxl.c | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 516589c35e..051a462f5e 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2822,18 +2822,25 @@ static int libxl__fill_dom0_memory_info(libxl__gc *gc, uint32_t *target_memkb) int rc; libxl_dominfo info; libxl_physinfo physinfo; - char *target = NULL, *endptr = NULL; + char *target = NULL, *staticmax = NULL, *freememslack = NULL, *endptr = NULL; char *target_path = "/local/domain/0/memory/target"; char *max_path = "/local/domain/0/memory/static-max"; char *free_mem_slack_path = "/local/domain/0/memory/freemem-slack"; xs_transaction_t t; libxl_ctx *ctx = libxl__gc_owner(gc); - uint32_t free_mem_slack = 0; + uint32_t free_mem_slack_kb = 0; retry_transaction: t = xs_transaction_start(ctx->xsh); target = libxl__xs_read(gc, t, target_path); + staticmax = libxl__xs_read(gc, t, target_path); + freememslack = libxl__xs_read(gc, t, target_path); + if (target && staticmax && freememslack) { + rc = 0; + goto out; + } + if (target) { *target_memkb = strtoul(target, &endptr, 10); if (*endptr != '\0') { @@ -2842,38 +2849,43 @@ retry_transaction: rc = ERROR_FAIL; goto out; } - rc = 0; - goto out; } rc = libxl_domain_info(ctx, &info, 0); if (rc < 0) - return rc; + goto out; rc = libxl_get_physinfo(ctx, &physinfo); if (rc < 0) - return rc; - - libxl__xs_write(gc, t, target_path, "%"PRIu32, - (uint32_t) info.current_memkb); - libxl__xs_write(gc, t, max_path, "%"PRIu32, - (uint32_t) info.max_memkb); + goto out; - free_mem_slack = (uint32_t) (PAGE_TO_MEMKB(physinfo.total_pages) - - info.current_memkb); - /* From empirical measurements the free_mem_slack shouldn't be more - * than 15% of the total memory present on the system. */ - if (free_mem_slack > PAGE_TO_MEMKB(physinfo.total_pages) * 0.15) - free_mem_slack = PAGE_TO_MEMKB(physinfo.total_pages) * 0.15; - libxl__xs_write(gc, t, free_mem_slack_path, "%"PRIu32, free_mem_slack); + if (target == NULL) { + libxl__xs_write(gc, t, target_path, "%"PRIu32, + (uint32_t) info.current_memkb); + *target_memkb = (uint32_t) info.current_memkb; + } + if (staticmax == NULL) + libxl__xs_write(gc, t, max_path, "%"PRIu32, + (uint32_t) info.max_memkb); - *target_memkb = (uint32_t) info.current_memkb; + if (freememslack == NULL) { + free_mem_slack_kb = (uint32_t) (PAGE_TO_MEMKB(physinfo.total_pages) - + info.current_memkb); + /* From empirical measurements the free_mem_slack shouldn't be more + * than 15% of the total memory present on the system. */ + if (free_mem_slack_kb > PAGE_TO_MEMKB(physinfo.total_pages) * 0.15) + free_mem_slack_kb = PAGE_TO_MEMKB(physinfo.total_pages) * 0.15; + libxl__xs_write(gc, t, free_mem_slack_path, "%"PRIu32, free_mem_slack_kb); + } rc = 0; out: - if (!xs_transaction_end(ctx->xsh, t, 0)) + if (!xs_transaction_end(ctx->xsh, t, 0)) { if (errno == EAGAIN) goto retry_transaction; + else + rc = ERROR_FAIL; + } return rc; |