libxl: stop libxl_domain_info() consuming massive amounts of stack
authorPaul Durrant <pdurrant@amazon.com>
Thu, 28 May 2020 15:13:30 +0000 (16:13 +0100)
committerWei Liu <wl@xen.org>
Tue, 2 Jun 2020 11:57:01 +0000 (11:57 +0000)
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>
Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_domain.c

index c08af308faca671fecc70be8b6b1407c67a81583..39f08a651927f2337673d1ee3c1a3424caa84d23 100644 (file)
@@ -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++) {