From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKk97-0003zT-Hl for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKk95-0002cj-8r for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:41 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:46663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKk94-0002c0-Nm for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:39 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Mar 2013 16:42:13 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 090CD2CE804D for ; Wed, 27 Mar 2013 17:47:28 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2R6YQcM4587794 for ; Wed, 27 Mar 2013 17:34:26 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2R6lR7n028821 for ; Wed, 27 Mar 2013 17:47:27 +1100 Message-ID: <515295A1.8030705@linux.vnet.ibm.com> Date: Wed, 27 Mar 2013 14:45:53 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1364240439-23450-1-git-send-email-lcapitulino@redhat.com> <1364240439-23450-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1364240439-23450-3-git-send-email-lcapitulino@redhat.com> Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] Monitor: Make output buffer dynamic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: fred.konrad@greensocs.com, qemu-devel@nongnu.org, kraxel@redhat.com Hi, Luiz Personally I hope reduce the dynamic allocated buffer which brings fragments and unexpected memory grow. Instead, how about sacrifice some time to wait output complete, since monitor is not time critical? in this case static buffer's size can decide how many work can be postponded. Following is my suggestion: --- a/monitor.c +++ b/monitor.c @@ -293,17 +293,28 @@ static void monitor_puts(Monitor *mon, const char *str) { char c; + /* if mux do not put in any thing to buffer */ + if (mon->mux_out) { + return; + } + for(;;) { - assert(mon->outbuf_index < sizeof(mon->outbuf) - 1); + if (mon->outbuf_index >= sizeof(mon->outbuf) - 1) { + /* when buffer is full, flush it and retry. If buffer is bigger, more + work can be postponed. */ + monitor_flush(mon); + usleep(1); + continue; + } c = *str++; if (c == '\0') break; if (c == '\n') mon->outbuf[mon->outbuf_index++] = '\r'; mon->outbuf[mon->outbuf_index++] = c; - if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) - || c == '\n') + if (c == '\n') { monitor_flush(mon); + } } } > Commit f628926bb423fa8a7e0b114511400ea9df38b76a changed monitor_flush() > to retry on qemu_chr_fe_write() errors. However, the Monitor's output > buffer can keep growing while the retry is not issued and this can > cause the buffer to overflow. > > To reproduce this issue, just start qemu and type on the Monitor: > > (qemu) ? > > This will cause the assertion to trig. > > To fix this problem this commit makes the Monitor buffer dynamic, > which means that it can grow as much as needed. > > Signed-off-by: Luiz Capitulino > --- > monitor.c | 42 +++++++++++++++++++++++++----------------- > 1 file changed, 25 insertions(+), 17 deletions(-) >