From nobody Thu May 2 10:08:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1590678842; cv=none; d=zohomail.com; s=zohoarc; b=MQxXccmoMJY/0gr+4y1jhsjH1VhgIoPaiO2IW1uuhDu3Xn5O7lHblHGyX+pMrtpOCPjk4sF1wt69OK22aR3BSx95tLbs638eOLqTGzDrS3gAXnH9hFqLNfPZ3aeHBr9vKaAayJooCr4zUr09JE4dhokkj2WZ6YN7VeRM0mP2NEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590678842; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=RWE7FsZRvo9h78tHiAsaTBasLYIAlxCJdGiu/keK7GI=; b=k4W2P6+D0f2bdU6Mqf+VPpWQbeKE+KpJejTz7P3icc6UyVtTXxUOzOTs1/HiDQHWoBBE/C75Z1sGvidFNcU2kJzeyNTAUG4983gbv/8d1joznVKMEg/RxbCQdunNPxPXFoBwRX8nmhGPlkFMv4SGm8l1lZzlUqguqahhHjE2fF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1590678842757268.2755634432839; Thu, 28 May 2020 08:14:02 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeKDv-0001Yi-K9; Thu, 28 May 2020 15:13:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeKDu-0001Yb-G8 for xen-devel@lists.xenproject.org; Thu, 28 May 2020 15:13:34 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cc230362-a0f5-11ea-9947-bc764e2007e4; Thu, 28 May 2020 15:13:34 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeKDt-0006VB-I4; Thu, 28 May 2020 15:13:33 +0000 Received: from [54.239.6.187] (helo=CBG-R90WXYV0.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeKDt-0004v3-8D; Thu, 28 May 2020 15:13:33 +0000 X-Inumbo-ID: cc230362-a0f5-11ea-9947-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RWE7FsZRvo9h78tHiAsaTBasLYIAlxCJdGiu/keK7GI=; b=Kak50CIAlbQvjWF1B+0ze6GAkv ZK3o02xEA9tAEpBbeXcOstLtKvHpgGHSIBmPxh3/5GG9Cuaaexr3nGjlWO+tlTMas1C0uqwajDg4J dFEBHGecWwxoHf8qiFfRNm+NZS2Aci/80dDCDmGadvzg2KeaY2BwJmKxFW1P171yfwEg=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v2] libxl: stop libxl_domain_info() consuming massive amounts of stack Date: Thu, 28 May 2020 16:13:30 +0100 Message-Id: <20200528151330.20964-1-paul@xen.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant 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 Reviewed-by: Ian Jackson --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD 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(-) 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 =3D NULL; int i, ret; - xc_domaininfo_t info[1024]; + xc_domaininfo_t *info; int size =3D 0; uint32_t domid =3D 0; GC_INIT(ctx); =20 + GCNEW_ARRAY(info, 1024); + while ((ret =3D xc_domain_getinfolist(ctx->xch, domid, 1024, info)) > = 0) { ptr =3D libxl__realloc(NOGC, ptr, (size + ret) * sizeof(libxl_domi= nfo)); for (i =3D 0; i < ret; i++) { --=20 2.17.1