From mboxrd@z Thu Jan 1 00:00:00 1970 From: Izik Eidus Subject: Re: kvm userspace: ksm support Date: Mon, 03 Aug 2009 22:04:15 +0300 Message-ID: <4A7734AF.3060505@redhat.com> References: <20090728193959.49cc28b6@woof.woof> <200908031308.24804.iggy@theiggy.com> <4A7727E2.4060906@redhat.com> <200908031337.55323.iggy@theiggy.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Brian Jackson Return-path: Received: from mx2.redhat.com ([66.187.237.31]:43617 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754004AbZHCTGE (ORCPT ); Mon, 3 Aug 2009 15:06:04 -0400 In-Reply-To: <200908031337.55323.iggy@theiggy.com> Sender: kvm-owner@vger.kernel.org List-ID: Brian Jackson wrote: > On Monday 03 August 2009 01:09:38 pm Izik Eidus wrote: > >> Brian Jackson wrote: >> >>> If someone wanted to play around with ksm in qemu-kvm-0.x.x would it be >>> as simple as adding the below additions to kvm_setup_guest_memory in >>> kvm-all.c >>> >> qemu-kvm-0.x.x doesnt tell me much, but if it is the function that >> register the memory than yes... >> >> (I just remember that qemu used to have something called phys_ram_base, >> in that case it would be just making madvise on phys_ram_base with the >> same of phys_ram_size....) >> > > Sorry, I'm using qemu-kvm-0.10.6 > > > This is what qemu_ram_alloc looks like: > > > > /* XXX: better than nothing */ > ram_addr_t qemu_ram_alloc(ram_addr_t size) > { > ram_addr_t addr; > if ((phys_ram_alloc_offset + size) > phys_ram_size) { > fprintf(stderr, "Not enough memory (requested_size = %" PRIu64 ", max memory = %" PRIu64 ")\n", > (uint64_t)size, (uint64_t)phys_ram_size); > abort(); > } > addr = phys_ram_alloc_offset; > phys_ram_alloc_offset = TARGET_PAGE_ALIGN(phys_ram_alloc_offset + size); > > if (kvm_enabled()) > kvm_setup_guest_memory(phys_ram_base + addr, size); > > return addr; > } > > > And this is what my new kvm_setup_guest_memory looks like: > > > void kvm_setup_guest_memory(void *start, size_t size) > { > if (!kvm_has_sync_mmu()) { > #ifdef MADV_DONTFORK > int ret = madvise(start, size, MADV_DONTFORK); > > if (ret) { > perror("madvice"); > exit(1); > } > #else > fprintf(stderr, > "Need MADV_DONTFORK in absence of synchronous KVM MMU\n"); > exit(1); > #endif > } > #ifdef MADV_MERGEABLE > madvise(start, size, MADV_MERGEABLE); > #endif > } > > > > Look okay? > > > Yes.