From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afVhX-00035l-IM for qemu-devel@nongnu.org; Mon, 14 Mar 2016 12:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afVhT-0003kI-W6 for qemu-devel@nongnu.org; Mon, 14 Mar 2016 12:50:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afVhT-0003kE-QM for qemu-devel@nongnu.org; Mon, 14 Mar 2016 12:50:35 -0400 Date: Mon, 14 Mar 2016 16:50:32 +0000 From: "Daniel P. Berrange" Message-ID: <20160314165032.GJ21198@redhat.com> References: <1457753338-22089-1-git-send-email-dhannawatpooja1@gmail.com> <1457973473-21791-1-git-send-email-dhannawatpooja1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1457973473-21791-1-git-send-email-dhannawatpooja1@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 1/1] socket: Allocating Large sized arrays to heap Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pooja Dhannawat Cc: qemu-devel@nongnu.org On Mon, Mar 14, 2016 at 10:07:53PM +0530, Pooja Dhannawat wrote: > net_socket_send has a huge stack usage of 69712 bytes approx. > Moving large arrays to heap to reduce stack usage. > > Signed-off-by: Pooja Dhannawat > --- > net/socket.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/net/socket.c b/net/socket.c > index e32e3cb..3fcd7a6 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -147,10 +147,10 @@ static void net_socket_send(void *opaque) > NetSocketState *s = opaque; > int size, err; > unsigned l; > - uint8_t buf1[NET_BUFSIZE]; > + uint8_t *buf1 = g_new(uint8_t, NET_BUFSIZE); You're allocating NET_BUFSIZE worth of uint8_t's > const uint8_t *buf; > > - size = qemu_recv(s->fd, buf1, sizeof(buf1), 0); > + size = qemu_recv(s->fd, (uint8_t *)buf1, sizeof(uint8_t), 0); But only reading 1 byte which is clearly wrong. You likely wanted NET_BUFSIZE here, not sizeof(uint8_t) Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|