From mboxrd@z Thu Jan 1 00:00:00 1970 From: Izik Eidus Subject: [RFC][PATCH 5/5] example of userspace application register it memory in ksm Date: Mon, 21 Jan 2008 18:16:31 +0200 Message-ID: <4794C55F.102@qumranet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030401030002000808000909" To: kvm-devel , andrea-atKUWr5tajBWk0Htik3J/w@public.gmane.org, avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org, dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org, yaniv-atKUWr5tajBWk0Htik3J/w@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is a multi-part message in MIME format. --------------030401030002000808000909 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit (this is the modification for qemu to make it work with ksm) -- woof. --------------030401030002000808000909 Content-Type: text/x-patch; name="0005-qemu-register-the-memory-of-qemu-with-ksm.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0005-qemu-register-the-memory-of-qemu-with-ksm.patch" >>From 813266c7d59acb64c104448c255cc2c9d4f0187e Mon Sep 17 00:00:00 2001 From: Izik Eidus Date: Mon, 21 Jan 2008 17:41:09 +0200 Subject: [PATCH] qemu: register the memory of qemu with ksm, so it can be shared Signed-off-by: Izik Eidus --- qemu/vl.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/qemu/vl.c b/qemu/vl.c index 756e13d..691db36 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -21,6 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "ksm.h" #include "hw/hw.h" #include "hw/boards.h" #include "hw/usb.h" @@ -8501,6 +8503,37 @@ void qemu_get_launch_info(int *argc, char ***argv, int *opt_daemonize, const cha *opt_incoming = incoming; } +int ksm_register_memory(void) +{ + int fd; + int ksm_fd; + int r = 1; + struct ksm_memory_region ksm_region; + + fd = open("/dev/ksm", O_RDWR | O_TRUNC, (mode_t)0600); + if (fd == -1) + goto out; + + ksm_fd = ioctl(fd, KSM_CREATE_SHARED_MEMORY_AREA); + if (ksm_fd == -1) + goto out_free; + + ksm_region.npages = phys_ram_size / TARGET_PAGE_SIZE; + ksm_region.addr = phys_ram_base; + r = ioctl(ksm_fd, KSM_REGISTER_MEMORY_REGION, &ksm_region); + if (r) + goto out_free1; + + return r; + +out_free1: + close(ksm_fd); +out_free: + close(fd); +out: + return r; +} + int main(int argc, char **argv) { #ifdef CONFIG_GDBSTUB @@ -9353,6 +9386,8 @@ int main(int argc, char **argv) } #endif + ksm_register_memory(); + bdrv_init(); /* we always create the cdrom drive, even if no disk is there */ -- 1.5.3.6 --------------030401030002000808000909 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --------------030401030002000808000909 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------030401030002000808000909--