Skip to contentSkip to conversation

libxl: stop libxl_domain_info() consuming massive amounts of stack

PATCH Superseded Paul Durrant 3 participants 3 messages May 28, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: stop libxl_domain_info() consuming massive amounts of stack

From: Paul Durrant <[email protected]>

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.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>

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.

---
 tools/libxl/libxl_domain.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/libxl/libxl_domain.c +3 -1
index fef2cd4e13..c07ec8fd3a 100644
@@ -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);
 
+    info = libxl__calloc(gc, 1024, sizeof(*info));
+
     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++) {
Signature · 1 line
2.17.1
#1 lore raw

Paul Durrant writes ("[PATCH] libxl: stop libxl_domain_info() consuming massive amounts of stack"):

Quoted 4 lines

From: Paul Durrant <[email protected]>

Currently an array of 1024 xc_domaininfo_t is declared on stack. That alone consumes ~112k.

Wow.

Quoted 2 lines

Since libxl_domain_info() creates a new gc this patch simply uses it to allocate the array instead.

Thanks.

Quoted 1 line

+ info = libxl__calloc(gc, 1024, sizeof(*info));

Wy not GCNEW_ARRAY ?

That avoids a possible bug with wrong number of * to sizeof (although in this case you seem to have it right...)

Thanks,
Ian.

#2 lore raw
Quoted 16 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Sent: 28 May 2020 15:57
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; Anthony Perard <[email protected]>
Subject: Re: [PATCH] libxl: stop libxl_domain_info() consuming massive amounts of stack

Paul Durrant writes ("[PATCH] libxl: stop libxl_domain_info() consuming massive amounts of stack"):

Quoted 4 lines

From: Paul Durrant <[email protected]>

Currently an array of 1024 xc_domaininfo_t is declared on stack. That alone consumes ~112k.

Wow.

Quoted 8 lines
Quoted 2 lines

Since libxl_domain_info() creates a new gc this patch simply uses it to allocate the array instead.

Thanks.

Quoted 1 line

+ info = libxl__calloc(gc, 1024, sizeof(*info));

Wy not GCNEW_ARRAY ?

'Cos I didn't know about that one :-)

Quoted 4 lines

That avoids a possible bug with wrong number of * to sizeof (although in this case you seem to have it right...)

Cool. I'll send a v2 in mo'.

Paul

Quoted 2 lines

Thanks,
Ian.