debuggers.hg

changeset 22567:a2713356ad24

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>
author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
date Tue Dec 14 19:04:03 2010 +0000 (2010-12-14)
parents 6df91a11dcb0
children 197c0b40423a
files tools/libxl/libxl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Tue Dec 14 18:59:44 2010 +0000
     1.2 +++ b/tools/libxl/libxl.c	Tue Dec 14 19:04:03 2010 +0000
     1.3 @@ -2822,18 +2822,25 @@ static int libxl__fill_dom0_memory_info(
     1.4      int rc;
     1.5      libxl_dominfo info;
     1.6      libxl_physinfo physinfo;
     1.7 -    char *target = NULL, *endptr = NULL;
     1.8 +    char *target = NULL, *staticmax = NULL, *freememslack = NULL, *endptr = NULL;
     1.9      char *target_path = "/local/domain/0/memory/target";
    1.10      char *max_path = "/local/domain/0/memory/static-max";
    1.11      char *free_mem_slack_path = "/local/domain/0/memory/freemem-slack";
    1.12      xs_transaction_t t;
    1.13      libxl_ctx *ctx = libxl__gc_owner(gc);
    1.14 -    uint32_t free_mem_slack = 0;
    1.15 +    uint32_t free_mem_slack_kb = 0;
    1.16  
    1.17  retry_transaction:
    1.18      t = xs_transaction_start(ctx->xsh);
    1.19  
    1.20      target = libxl__xs_read(gc, t, target_path);
    1.21 +    staticmax = libxl__xs_read(gc, t, target_path);
    1.22 +    freememslack = libxl__xs_read(gc, t, target_path);
    1.23 +    if (target && staticmax && freememslack) {
    1.24 +        rc = 0;
    1.25 +        goto out;
    1.26 +    }
    1.27 +
    1.28      if (target) {
    1.29          *target_memkb = strtoul(target, &endptr, 10);
    1.30          if (*endptr != '\0') {
    1.31 @@ -2842,38 +2849,43 @@ retry_transaction:
    1.32              rc = ERROR_FAIL;
    1.33              goto out;
    1.34          }
    1.35 -        rc = 0;
    1.36 -        goto out;
    1.37      }
    1.38  
    1.39      rc = libxl_domain_info(ctx, &info, 0);
    1.40      if (rc < 0)
    1.41 -        return rc;
    1.42 +        goto out;
    1.43  
    1.44      rc = libxl_get_physinfo(ctx, &physinfo);
    1.45      if (rc < 0)
    1.46 -        return rc;
    1.47 -
    1.48 -    libxl__xs_write(gc, t, target_path, "%"PRIu32,
    1.49 -            (uint32_t) info.current_memkb);
    1.50 -    libxl__xs_write(gc, t, max_path, "%"PRIu32,
    1.51 -            (uint32_t) info.max_memkb);
    1.52 -
    1.53 -    free_mem_slack = (uint32_t) (PAGE_TO_MEMKB(physinfo.total_pages) -
    1.54 -            info.current_memkb);
    1.55 -    /* From empirical measurements the free_mem_slack shouldn't be more
    1.56 -     * than 15% of the total memory present on the system. */
    1.57 -    if (free_mem_slack > PAGE_TO_MEMKB(physinfo.total_pages) * 0.15)
    1.58 -        free_mem_slack = PAGE_TO_MEMKB(physinfo.total_pages) * 0.15;
    1.59 -    libxl__xs_write(gc, t, free_mem_slack_path, "%"PRIu32, free_mem_slack);
    1.60 -
    1.61 -    *target_memkb = (uint32_t) info.current_memkb;
    1.62 +        goto out;
    1.63 +
    1.64 +    if (target == NULL) {
    1.65 +        libxl__xs_write(gc, t, target_path, "%"PRIu32,
    1.66 +                (uint32_t) info.current_memkb);
    1.67 +        *target_memkb = (uint32_t) info.current_memkb;
    1.68 +    }
    1.69 +    if (staticmax == NULL)
    1.70 +        libxl__xs_write(gc, t, max_path, "%"PRIu32,
    1.71 +                (uint32_t) info.max_memkb);
    1.72 +
    1.73 +    if (freememslack == NULL) {
    1.74 +        free_mem_slack_kb = (uint32_t) (PAGE_TO_MEMKB(physinfo.total_pages) -
    1.75 +                info.current_memkb);
    1.76 +        /* From empirical measurements the free_mem_slack shouldn't be more
    1.77 +         * than 15% of the total memory present on the system. */
    1.78 +        if (free_mem_slack_kb > PAGE_TO_MEMKB(physinfo.total_pages) * 0.15)
    1.79 +            free_mem_slack_kb = PAGE_TO_MEMKB(physinfo.total_pages) * 0.15;
    1.80 +        libxl__xs_write(gc, t, free_mem_slack_path, "%"PRIu32, free_mem_slack_kb);
    1.81 +    }
    1.82      rc = 0;
    1.83  
    1.84  out:
    1.85 -    if (!xs_transaction_end(ctx->xsh, t, 0))
    1.86 +    if (!xs_transaction_end(ctx->xsh, t, 0)) {
    1.87          if (errno == EAGAIN)
    1.88              goto retry_transaction;
    1.89 +        else
    1.90 +            rc = ERROR_FAIL;
    1.91 +    }
    1.92  
    1.93  
    1.94      return rc;