diff mbox series

[v2] libxl: stop libxl_domain_info() consuming massive amounts of stack

Message ID 20200528151330.20964-1-paul@xen.org (mailing list archive)
State New, archived
Headers show
Series [v2] libxl: stop libxl_domain_info() consuming massive amounts of stack | expand

Commit Message

Paul Durrant May 28, 2020, 3:13 p.m. UTC
From: Paul Durrant <pdurrant@amazon.com>

Currently an array of 1024 xc_domaininfo_t is declared on stack. That alone
consumes ~112k. Since libxl_domain_info() creates a new gc this patch simply
uses it to allocate the array instead.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wl@xen.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>

This is small and IMO it would be nice to have this in 4.14 but I'd like an
opinion from a maintainer too.

v2:
 - Use GCNEW_ARRAY
---
 tools/libxl/libxl_domain.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ian Jackson May 28, 2020, 3:44 p.m. UTC | #1
Paul Durrant writes ("[PATCH v2] libxl: stop libxl_domain_info() consuming massive amounts of stack"):
> From: Paul Durrant <pdurrant@amazon.com>
> 
> Currently an array of 1024 xc_domaininfo_t is declared on stack. That alone
> consumes ~112k. Since libxl_domain_info() creates a new gc this patch simply
> uses it to allocate the array instead.
> 
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>
> ---
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Wei Liu <wl@xen.org>
> Cc: Anthony PERARD <anthony.perard@citrix.com>
> 
> This is small and IMO it would be nice to have this in 4.14 but I'd like an
> opinion from a maintainer too.

Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>

I agree that this is 4.14 material.

Ian.
diff mbox series

Patch

diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
index fef2cd4e13..bb21087eb8 100644
--- a/tools/libxl/libxl_domain.c
+++ b/tools/libxl/libxl_domain.c
@@ -314,11 +314,13 @@  libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out)
 {
     libxl_dominfo *ptr = NULL;
     int i, ret;
-    xc_domaininfo_t info[1024];
+    xc_domaininfo_t *info;
     int size = 0;
     uint32_t domid = 0;
     GC_INIT(ctx);
 
+    GCNEW_ARRAY(info, 1024);
+
     while ((ret = xc_domain_getinfolist(ctx->xch, domid, 1024, info)) > 0) {
         ptr = libxl__realloc(NOGC, ptr, (size + ret) * sizeof(libxl_dominfo));
         for (i = 0; i < ret; i++) {