From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHruT-0000CK-1a for qemu-devel@nongnu.org; Tue, 28 Jun 2016 08:14:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHruP-0007CG-MZ for qemu-devel@nongnu.org; Tue, 28 Jun 2016 08:14:32 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:44998 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHruP-0007Aw-D1 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 08:14:29 -0400 References: <1467104499-27517-1-git-send-email-pl@kamp.de> From: Peter Lieven Message-ID: <57726A20.4000808@kamp.de> Date: Tue, 28 Jun 2016 14:14:24 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 00/15] optimize Qemu RSS usage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, mst@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, kraxel@redhat.com Am 28.06.2016 um 13:37 schrieb Paolo Bonzini: > > On 28/06/2016 11:01, Peter Lieven wrote: >> I recently found that Qemu is using several hundred megabytes of RSS memory >> more than older versions such as Qemu 2.2.0. So I started tracing >> memory allocation and found 2 major reasons for this. >> >> 1) We changed the qemu coroutine pool to have a per thread and a global release >> pool. The choosen poolsize and the changed algorithm could lead to up to >> 192 free coroutines with just a single iothread. Each of the coroutines >> in the pool each having 1MB of stack memory. > But the fix, as you correctly note, is to reduce the stack size. It > would be nice to compile block-obj-y with -Wstack-usage=2048 too. To reveal if there are any big stack allocations in the block layer? As it seems reducing to 64kB breaks live migration in some (non reproducible) cases. The question is which way to go? Reduce the stack size and fix the big stack allocations or keep the stack size at 1MB? > >> 2) Between Qemu 2.2.0 and 2.3.0 RCU was introduced which lead to delayed freeing >> of memory. This lead to higher heap allocations which could not effectively >> be returned to kernel (most likely due to fragmentation). > I agree that some of the exec.c allocations need some care, but I would > prefer to use a custom free list or lazy allocation instead of mmap. This would only help if the elements from the free list would be allocated using mmap? The issue is that RCU delays the freeing so that the number of concurrent allocations is high and then a bunch is freed at once. If the memory was malloced it would still have caused trouble. > > Changing allocations to use mmap also is not really useful if you do it > for objects that are never freed (as in patches 8-9-10-15 at least, and > probably 11 too which is one of the most contentious). 9 actually frees the memory ;-) 15 frees the memory as soon as the vnc client disconnects. The others I agree. If the objects in Patch 11 are freed needs to be checked. > > In other words, the effort tracking down the allocation is really, > really appreciated. But the patches look like you only had a hammer at > hand, and everything looked like a nail. :) I just have observed that forcing ptmalloc to use mmap for everything above 4kB significantly reduced the RSS usage. Peter