Received: from eggs.gnu.org ([208.118.235.92]:54421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4tkV-0002VX-A5 for qemu-devel@nongnu.org; Tue, 06 Mar 2012 07:44:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4tk4-0000Rp-Rx for qemu-devel@nongnu.org; Tue, 06 Mar 2012 07:44:14 -0500 Received: from smtp.ispras.ru ([83.149.198.202]:33312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4tk4-0000Le-KJ for qemu-devel@nongnu.org; Tue, 06 Mar 2012 07:43:48 -0500 Date: Tue, 6 Mar 2012 16:43:35 +0400 (MSK) From: Kirill Batuzov In-Reply-To: <4F546B05.9050200@samsung.com> Message-ID: References: <1330680137-6601-1-git-send-email-batuzovk@ispras.ru> <4F546B05.9050200@samsung.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [Qemu-devel] [PATCH 0/1] Fix large memory chunks allocation with tcg_malloc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Evgeny Voevodin Cc: qemu-devel@nongnu.org, zhur@ispras.ru, Dmitry Solodkiy On Mon, 5 Mar 2012, Evgeny Voevodin wrote: > > As I understand, your approach removes linking back to the previous allocated > chunk to avoid usage of already allocated and used memory again. Also you > added g_free() to tcg_pool_reset(). Wouldn't it slow down emulation? No, it would not. I added g_free() for large memory chunks only. Emulation runs which use only small allocations are unaffected. If an emulation run uses a large memory allocation - well, it was broken before. So there is nothing to compare speed to in this case. > Maybe such linkage to previous chunk was made with assumption that big > allocations will not happen twice one after another? For example, while > loading kernel on realview and exynos, the code never reaches this string in > tcg_malloc_internal(): > > p->next = s->pool_current; > The corresponding code had not changed since 2008. And, probably, never worked. It would be hard to know now what the author wanted from this code back then. > If this assumption is correct, maybe it's better to just insert a verification > that allocated chunk has enough space to hold requested block? > > + if (s->pool_cur - p->data + size > p->size) { > + goto new_pool; > + } > > s->pool_current = p; > s->pool_cur = p->data + size; > s->pool_end = p->data + p->size; > return p->data; > First, this verification does not solve problem of circular links in the list. Second, it does not solve problem of unbound increase of memory consumption. I probably should clarify that I found this issue when I was writing an unrelated modification to the register allocator which required large memory allocations. Current code in TCG probably never does such allocations and does not trigger memory corruption. -- Kirill Batuzov