From patchwork Thu Feb 14 20:21:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satoru Moriya X-Patchwork-Id: 220496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8F4922C0087 for ; Fri, 15 Feb 2013 07:22:31 +1100 (EST) Received: from localhost ([::1]:47795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U65K8-0002k4-OF for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2013 15:22:28 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U65Jw-0002jy-7Y for qemu-devel@nongnu.org; Thu, 14 Feb 2013 15:22:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U65Jp-0008CT-W7 for qemu-devel@nongnu.org; Thu, 14 Feb 2013 15:22:16 -0500 Received: from usindpps06.hds.com ([207.126.252.19]:51285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U65Jp-0008Bs-Pr for qemu-devel@nongnu.org; Thu, 14 Feb 2013 15:22:09 -0500 Received: from usindmail01.hds.com (usindmail03 [207.126.252.22]) by usindpps06.hds.com (8.14.4/8.14.4) with ESMTP id r1EKLsAA022473; Thu, 14 Feb 2013 12:21:54 -0800 Received: from USINDEHT102.corp.hds.com (usindnetf5d-vlan47float.corp.hds.com [10.74.73.11]) by usindmail01.hds.com (8.14.1/8.14.1) with ESMTP id r1EKLrqm020784; Thu, 14 Feb 2013 15:21:54 -0500 (EST) Received: from USINDEM103.corp.hds.com ([fe80::3ccb:1c2:3efb:4f2c]) by USINDEHT102.corp.hds.com ([fe80::e15c:8ff4:b462:8142%12]) with mapi id 14.02.0328.009; Thu, 14 Feb 2013 15:21:52 -0500 From: Satoru Moriya To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2] Add option to mlock qemu and guest memory Thread-Index: Ac4K8OyrhqSUQkCDQ16ya6KDjpcU+Q== Date: Thu, 14 Feb 2013 20:21:51 +0000 Message-ID: <8631DC5930FA9E468F04F3FD3A5D007214B0C1F2@USINDEM103.corp.hds.com> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.74.73.11] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327, 1.0.431, 0.0.0000 definitions=2013-02-14_07:2013-02-14, 2013-02-14, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_policy_notspam policy=outbound_policy score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1211240000 definitions=main-1302140150 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 207.126.252.19 Cc: "jan.kiszka@siemens.com" , "dle-develop@lists.sourceforge.net" , Seiji Aguchi , "mtosatti@redhat.com" Subject: [Qemu-devel] [PATCH v2] Add option to mlock qemu and guest memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We have some plans to migrate legacy enterprise systems which require low latency (10 msec order) to kvm virtualized environment. In our usecase, the system runs with other untrusted guests and so locking memory which is used by the system is needed to avoid latency impacts from other guests' memory activity. ChangeLog: v2 - Change the option name from -mlock to -realtime mlock=on|off - Rebase qemu version 1.3.91 - Update patch description Reviewed-by: Paolo Bonzini Reviewed-by: Marcelo Tosatti --- In certain scenario, latency induced by paging is significant and memory locking is needed. Also, in the scenario with untrusted guests, latency improvement due to mlock is desired. This patch introduces a following new option to mlock guest and qemu memory: -realtime mlock=on|off Signed-off-by: Satoru Moriya --- include/sysemu/os-posix.h | 1 + include/sysemu/os-win32.h | 1 + os-posix.c | 8 ++++++++ qemu-options.hx | 13 +++++++++++++ vl.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index 7f198e4..2f2ead6 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -31,6 +31,7 @@ void os_set_proc_name(const char *s); void os_setup_signal_handling(void); void os_daemonize(void); void os_setup_post(void); +void os_mlock(void); typedef struct timeval qemu_timeval; #define qemu_gettimeofday(tp) gettimeofday(tp, NULL) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index bf9edeb..a74ca13 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -80,6 +80,7 @@ static inline void os_daemonize(void) {} static inline void os_setup_post(void) {} void os_set_line_buffering(void); static inline void os_set_proc_name(const char *dummy) {} +static inline void os_mlock(void) {} #if !defined(EPROTONOSUPPORT) # define EPROTONOSUPPORT EINVAL diff --git a/os-posix.c b/os-posix.c index 5c64518..1304b0e 100644 --- a/os-posix.c +++ b/os-posix.c @@ -363,3 +363,11 @@ bool is_daemonized(void) { return daemonize; } + +void os_mlock(void) +{ + if (mlockall(MCL_CURRENT | MCL_FUTURE)) { + perror("mlockall"); + exit(1); + } +} diff --git a/qemu-options.hx b/qemu-options.hx index 9d7131a..843fcb4 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2464,6 +2464,19 @@ STEXI Do not start CPU at startup (you must type 'c' in the monitor). ETEXI +DEF("realtime", HAS_ARG, QEMU_OPTION_realtime, + "-realtime [mlock=on|off]\n" + " run qemu with realtime features\n" + " mlock=on|off controls mlock support (default: on)\n", + QEMU_ARCH_ALL) +STEXI +@item -realtime mlock=on|off +@findex -realtime +Run qemu with realtime features. +mlocking qemu and guest memory can be enabled via @option{mlock=on} +(enabled by default). +ETEXI + DEF("gdb", HAS_ARG, QEMU_OPTION_gdb, \ "-gdb dev wait for gdb connection on 'dev'\n", QEMU_ARCH_ALL) STEXI diff --git a/vl.c b/vl.c index 1355f69..c16c8ad 100644 --- a/vl.c +++ b/vl.c @@ -491,6 +491,18 @@ static QemuOptsList qemu_object_opts = { }, }; +static QemuOptsList qemu_realtime_opts = { + .name = "realtime", + .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head), + .desc = { + { + .name = "mlock", + .type = QEMU_OPT_BOOL, + }, + { /* end of list */ } + }, +}; + const char *qemu_get_vm_name(void) { return qemu_name; @@ -1384,6 +1396,17 @@ static void smp_parse(const char *optarg) max_cpus = smp_cpus; } +static void configure_realtime(QemuOpts *opts) +{ + bool is_mlock; + + is_mlock = qemu_opt_get_bool(opts, "mlock", true); + + if (is_mlock) { + os_mlock(); + } +} + /***********************************************************/ /* USB devices */ @@ -2860,6 +2883,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_sandbox_opts); qemu_add_opts(&qemu_add_fd_opts); qemu_add_opts(&qemu_object_opts); + qemu_add_opts(&qemu_realtime_opts); runstate_init(); @@ -3806,6 +3830,13 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_realtime: + opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0); + if (!opts) { + exit(1); + } + configure_realtime(opts); + break; default: os_parse_cmd_args(popt->index, optarg); }