From patchwork Wed Apr 6 02:37:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 8757781 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 54D8BC0553 for ; Wed, 6 Apr 2016 02:39:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE4EE2034E for ; Wed, 6 Apr 2016 02:39:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B9BA202F2 for ; Wed, 6 Apr 2016 02:39:46 +0000 (UTC) Received: from localhost ([::1]:40317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andNh-0003iL-IL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 22:39:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andM9-0000rm-B8 for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1andM8-0002fW-F2 for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49224) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andM8-0002fA-9n for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:08 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDAE38D3B5; Wed, 6 Apr 2016 02:38:07 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-7-238.pek2.redhat.com [10.72.7.238]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u362c1Ac016115; Tue, 5 Apr 2016 22:38:06 -0400 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Wed, 6 Apr 2016 10:37:57 +0800 Message-Id: <1459910280-5101-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1459910280-5101-1-git-send-email-jasowang@redhat.com> References: <1459910280-5101-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , Pooja Dhannawat Subject: [Qemu-devel] [PULL 2/5] net: Allocating Large sized arrays to heap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pooja Dhannawat nc_sendv_compat has a huge stack usage of 69680 bytes approx. Moving large arrays to heap to reduce stack usage. Reviewed-by: Stefan Hajnoczi Signed-off-by: Pooja Dhannawat Signed-off-by: Jason Wang --- net/net.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/net.c b/net/net.c index 0bc42a1..f8b1e00 100644 --- a/net/net.c +++ b/net/net.c @@ -683,23 +683,28 @@ ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, int iovcnt, unsigned flags) { - uint8_t buf[NET_BUFSIZE]; + uint8_t *buf = NULL; uint8_t *buffer; size_t offset; + ssize_t ret; if (iovcnt == 1) { buffer = iov[0].iov_base; offset = iov[0].iov_len; } else { + buf = g_new(uint8_t, NET_BUFSIZE); buffer = buf; - offset = iov_to_buf(iov, iovcnt, 0, buf, sizeof(buf)); + offset = iov_to_buf(iov, iovcnt, 0, buf, NET_BUFSIZE); } if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) { - return nc->info->receive_raw(nc, buffer, offset); + ret = nc->info->receive_raw(nc, buffer, offset); } else { - return nc->info->receive(nc, buffer, offset); + ret = nc->info->receive(nc, buffer, offset); } + + g_free(buf); + return ret; } ssize_t qemu_deliver_packet_iov(NetClientState *sender,