From patchwork Thu May 28 15:13:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11576111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9551190 for ; Thu, 28 May 2020 15:15:25 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70D2120814 for ; Thu, 28 May 2020 15:15:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=xen.org header.i=@xen.org header.b="Kak50CIA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70D2120814 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: cc230362-a0f5-11ea-9947-bc764e2007e4 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) 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=; 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 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" 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 = 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++) {