From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gordan Bobic Subject: Re: KSM For All Via LD_PRELOAD? Date: Thu, 10 Jun 2010 10:09:15 +0100 Message-ID: <4C10ABBB.8070009@bobich.net> References: <4C0E8F3B.5060501@bobich.net> <4C1097F2.8070802@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit To: kvm@vger.kernel.org Return-path: Received: from 78-86-195-86.zone2.bethere.co.uk ([78.86.195.86]:47709 "EHLO sentinel1.shatteredsilicon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758617Ab0FJJJS (ORCPT ); Thu, 10 Jun 2010 05:09:18 -0400 Received: from thinkpad.shatteredsilicon.net (unknown [10.255.20.6]) by sentinel1.shatteredsilicon.net (Postfix) with ESMTP id D58FE1D8F01 for ; Thu, 10 Jun 2010 10:09:16 +0100 (BST) In-Reply-To: <4C1097F2.8070802@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/10/2010 08:44 AM, Jes Sorensen wrote: > On 06/08/10 20:43, Gordan Bobic wrote: >> Is this plausible? >> >> I'm trying to work out if it's even worth considering this approach to >> enable all memory used by in a system to be open to KSM page merging, >> rather than only memory used by specific programs aware of it (e.g. >> kvm/qemu). >> >> Something like this would address the fact that container based >> virtualization (OpenVZ, VServer, LXC) cannot benefit from KSM. >> >> What I'm thinking about is somehow intercepting malloc() and wrapping it >> so that all malloc()-ed memory gets madvise()-d as well. > > Not sure if it is worth it, but you might want to look at ElectricFence > which does malloc wrapping in a somewhat similar way. It might save you > some code :) I'll look into it, but I don't see this requiring more than maybe 50 lines of code, including comments, headers and Makefile. I was planning to literally just intercept mmap()/brk()/malloc() and mark them with madvise() when the underlying call returns. Which brings me to another question: Would intercepting malloc() be completely redundant if mmap() is intercepted? Would I also need to do something with intercepting free()? Is three anything else I would need to intercept? > Whether or not you will run into problems if you run it system wise is > really hard to predict. Any other application that might be linked in a > special way or use preload itself might bark, but you can try it out and > see what explodes. Thanks for the heads up. Can you think of any such applications off the top of your head? Gordan