...
...
33
but the memory overhead it introduces is an undesirable side effect,
33
but the memory overhead it introduces is an undesirable side effect,
34
which we can completely avoid by passing MCL_ONFAULT to mlockall, which
34
which we can completely avoid by passing MCL_ONFAULT to mlockall, which
35
is what this series allows to do with a new option for mem-lock called
35
is what this series allows to do with a new option for mem-lock called
36
on-fault.
36
on-fault.
37
37
38
memlock=on-fault:
38
memlock-onfault:
39
$ ./qemu-system-x86_64 -overcommit mem-lock=on-fault
39
$ ./qemu-system-x86_64 -overcommit mem-lock=on-fault
40
$ ps -p $(pidof ./qemu-system-x86_64) -o rss=
40
$ ps -p $(pidof ./qemu-system-x86_64) -o rss=
41
54004
41
54004
42
42
43
$ ./qemu-system-x86_64 -overcommit mem-lock=on-fault -enable-kvm
43
$ ./qemu-system-x86_64 -overcommit mem-lock=on-fault -enable-kvm
...
...
51
this case, but it's still way less than it was with just the mem-lock=on.
51
this case, but it's still way less than it was with just the mem-lock=on.
52
52
53
Changes since v1:
53
Changes since v1:
54
- Don't make a separate mem-lock-onfault, add an on-fault option to mem-lock instead
54
- Don't make a separate mem-lock-onfault, add an on-fault option to mem-lock instead
55
55
56
Daniil Tatianin (2):
56
Changes since v2:
57
- Move overcommit option parsing out of line
58
- Make enable_mlock an enum instead
59
60
Daniil Tatianin (4):
57
os: add an ability to lock memory on_fault
61
os: add an ability to lock memory on_fault
62
system/vl: extract overcommit option parsing into a helper
63
sysemu: introduce a new MlockState enum
58
overcommit: introduce mem-lock=on-fault
64
overcommit: introduce mem-lock=on-fault
59
65
66
hw/virtio/virtio-mem.c | 2 +-
60
include/sysemu/os-posix.h | 2 +-
67
include/sysemu/os-posix.h | 2 +-
61
include/sysemu/os-win32.h | 3 ++-
68
include/sysemu/os-win32.h | 3 ++-
62
include/sysemu/sysemu.h | 1 +
69
include/sysemu/sysemu.h | 12 ++++++++-
63
migration/postcopy-ram.c | 4 ++--
70
migration/postcopy-ram.c | 4 +--
64
os-posix.c | 10 +++++++--
71
os-posix.c | 10 ++++++--
65
qemu-options.hx | 14 +++++++-----
72
qemu-options.hx | 14 +++++++----
66
system/globals.c | 1 +
73
system/globals.c | 12 ++++++++-
67
system/vl.c | 46 +++++++++++++++++++++++++++++++--------
74
system/vl.c | 52 +++++++++++++++++++++++++++++++--------
68
8 files changed, 61 insertions(+), 20 deletions(-)
75
9 files changed, 87 insertions(+), 24 deletions(-)
69
76
70
--
77
--
71
2.34.1
78
2.34.1
diff view generated by jsdifflib
1
This will be used in the following commits to make it possible to only
1
This will be used in the following commits to make it possible to only
2
lock memory on fault instead of right away.
2
lock memory on fault instead of right away.
3
3
4
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
5
Reviewed-by: Peter Xu <peterx@redhat.com>
4
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
6
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
5
---
7
---
6
include/sysemu/os-posix.h | 2 +-
8
include/sysemu/os-posix.h | 2 +-
7
include/sysemu/os-win32.h | 3 ++-
9
include/sysemu/os-win32.h | 3 ++-
8
migration/postcopy-ram.c | 2 +-
10
migration/postcopy-ram.c | 2 +-
...
...
diff view generated by jsdifflib
New patch
1
This will be extended in the future commits, let's move it out of line
2
right away so that it's easier to read.
1
3
4
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
5
---
6
system/vl.c | 21 ++++++++++++++-------
7
1 file changed, 14 insertions(+), 7 deletions(-)
8
9
diff --git a/system/vl.c b/system/vl.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/system/vl.c
12
+++ b/system/vl.c
13
@@ -XXX,XX +XXX,XX @@ static void object_option_parse(const char *str)
14
visit_free(v);
15
}
16
17
+static void overcommit_parse(const char *str)
18
+{
19
+ QemuOpts *opts;
20
+
21
+ opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
22
+ str, false);
23
+ if (!opts) {
24
+ exit(1);
25
+ }
26
+ enable_mlock = qemu_opt_get_bool(opts, "mem-lock", enable_mlock);
27
+ enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
28
+}
29
+
30
/*
31
* Very early object creation, before the sandbox options have been activated.
32
*/
33
@@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv)
34
object_option_parse(optarg);
35
break;
36
case QEMU_OPTION_overcommit:
37
- opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
38
- optarg, false);
39
- if (!opts) {
40
- exit(1);
41
- }
42
- enable_mlock = qemu_opt_get_bool(opts, "mem-lock", enable_mlock);
43
- enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
44
+ overcommit_parse(optarg);
45
break;
46
case QEMU_OPTION_compat:
47
{
48
--
49
2.34.1
diff view generated by jsdifflib
New patch
1
Replace the boolean value enable_mlock with an enum and add a helper to
2
decide whether we should be calling os_mlock.
1
3
4
This is a stepping stone towards introducing a new mlock mode, which
5
will be the third possible state of this enum.
6
7
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
8
---
9
hw/virtio/virtio-mem.c | 2 +-
10
include/sysemu/sysemu.h | 10 +++++++++-
11
migration/postcopy-ram.c | 2 +-
12
system/globals.c | 7 ++++++-
13
system/vl.c | 9 +++++++--
14
5 files changed, 24 insertions(+), 6 deletions(-)
15
16
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/virtio/virtio-mem.c
19
+++ b/hw/virtio/virtio-mem.c
20
@@ -XXX,XX +XXX,XX @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
21
return;
22
}
23
24
- if (enable_mlock) {
25
+ if (should_mlock(mlock_state)) {
26
error_setg(errp, "Incompatible with mlock");
27
return;
28
}
29
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/include/sysemu/sysemu.h
32
+++ b/include/sysemu/sysemu.h
33
@@ -XXX,XX +XXX,XX @@ extern int display_opengl;
34
extern const char *keyboard_layout;
35
extern int old_param;
36
extern uint8_t *boot_splash_filedata;
37
-extern bool enable_mlock;
38
extern bool enable_cpu_pm;
39
extern QEMUClockType rtc_clock;
40
41
+typedef enum {
42
+ MLOCK_OFF = 0,
43
+ MLOCK_ON,
44
+} MlockState;
45
+
46
+bool should_mlock(MlockState);
47
+
48
+extern MlockState mlock_state;
49
+
50
#define MAX_OPTION_ROMS 16
51
typedef struct QEMUOptionRom {
52
const char *name;
53
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/migration/postcopy-ram.c
56
+++ b/migration/postcopy-ram.c
57
@@ -XXX,XX +XXX,XX @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)
58
mis->have_fault_thread = false;
59
}
60
61
- if (enable_mlock) {
62
+ if (should_mlock(mlock_state)) {
63
if (os_mlock(false) < 0) {
64
error_report("mlock: %s", strerror(errno));
65
/*
66
diff --git a/system/globals.c b/system/globals.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/system/globals.c
69
+++ b/system/globals.c
70
@@ -XXX,XX +XXX,XX @@
71
#include "sysemu/cpus.h"
72
#include "sysemu/sysemu.h"
73
74
+bool should_mlock(MlockState state)
75
+{
76
+ return state == MLOCK_ON;
77
+}
78
+
79
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
80
int display_opengl;
81
const char* keyboard_layout;
82
-bool enable_mlock;
83
+MlockState mlock_state;
84
bool enable_cpu_pm;
85
int autostart = 1;
86
int vga_interface_type = VGA_NONE;
87
diff --git a/system/vl.c b/system/vl.c
88
index XXXXXXX..XXXXXXX 100644
89
--- a/system/vl.c
90
+++ b/system/vl.c
91
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_run_with_opts = {
92
93
static void realtime_init(void)
94
{
95
- if (enable_mlock) {
96
+ if (should_mlock(mlock_state)) {
97
if (os_mlock(false) < 0) {
98
error_report("locking memory failed");
99
exit(1);
100
@@ -XXX,XX +XXX,XX @@ static void object_option_parse(const char *str)
101
static void overcommit_parse(const char *str)
102
{
103
QemuOpts *opts;
104
+ bool enable_mlock;
105
106
opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
107
str, false);
108
if (!opts) {
109
exit(1);
110
}
111
- enable_mlock = qemu_opt_get_bool(opts, "mem-lock", enable_mlock);
112
+
113
+ enable_mlock = qemu_opt_get_bool(opts, "mem-lock",
114
+ should_mlock(mlock_state));
115
+ mlock_state = enable_mlock ? MLOCK_ON : MLOCK_OFF;
116
+
117
enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
118
}
119
120
--
121
2.34.1
diff view generated by jsdifflib
...
...
5
only lock pages lazily as they're faulted by the process by using
5
only lock pages lazily as they're faulted by the process by using
6
MCL_ONFAULT if asked.
6
MCL_ONFAULT if asked.
7
7
8
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
8
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
9
---
9
---
10
include/sysemu/sysemu.h | 1 +
10
include/sysemu/sysemu.h | 2 ++
11
migration/postcopy-ram.c | 4 ++--
11
migration/postcopy-ram.c | 2 +-
12
qemu-options.hx | 14 +++++++-----
12
qemu-options.hx | 14 +++++++++-----
13
system/globals.c | 1 +
13
system/globals.c | 7 ++++++-
14
system/vl.c | 46 ++++++++++++++++++++++++++++++++--------
14
system/vl.c | 34 +++++++++++++++++++++++++++-------
15
5 files changed, 50 insertions(+), 16 deletions(-)
15
5 files changed, 45 insertions(+), 14 deletions(-)
16
16
17
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
17
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/sysemu/sysemu.h
19
--- a/include/sysemu/sysemu.h
20
+++ b/include/sysemu/sysemu.h
20
+++ b/include/sysemu/sysemu.h
21
@@ -XXX,XX +XXX,XX @@ extern const char *keyboard_layout;
21
@@ -XXX,XX +XXX,XX @@ extern QEMUClockType rtc_clock;
22
extern int old_param;
22
typedef enum {
23
extern uint8_t *boot_splash_filedata;
23
MLOCK_OFF = 0,
24
extern bool enable_mlock;
24
MLOCK_ON,
25
+extern bool enable_mlock_onfault;
25
+ MLOCK_ON_FAULT,
26
extern bool enable_cpu_pm;
26
} MlockState;
27
extern QEMUClockType rtc_clock;
27
28
bool should_mlock(MlockState);
29
+bool is_mlock_on_fault(MlockState);
30
31
extern MlockState mlock_state;
28
32
29
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
33
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
30
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
31
--- a/migration/postcopy-ram.c
35
--- a/migration/postcopy-ram.c
32
+++ b/migration/postcopy-ram.c
36
+++ b/migration/postcopy-ram.c
33
@@ -XXX,XX +XXX,XX @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)
37
@@ -XXX,XX +XXX,XX @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)
34
mis->have_fault_thread = false;
35
}
38
}
36
39
37
- if (enable_mlock) {
40
if (should_mlock(mlock_state)) {
38
- if (os_mlock(false) < 0) {
41
- if (os_mlock(false) < 0) {
39
+ if (enable_mlock || enable_mlock_onfault) {
42
+ if (os_mlock(is_mlock_on_fault(mlock_state)) < 0) {
40
+ if (os_mlock(enable_mlock_onfault) < 0) {
41
error_report("mlock: %s", strerror(errno));
43
error_report("mlock: %s", strerror(errno));
42
/*
44
/*
43
* It doesn't feel right to fail at this point, we have a valid
45
* It doesn't feel right to fail at this point, we have a valid
44
diff --git a/qemu-options.hx b/qemu-options.hx
46
diff --git a/qemu-options.hx b/qemu-options.hx
45
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
...
...
78
for other processes on the same host cpu, but decreasing latency for
80
for other processes on the same host cpu, but decreasing latency for
79
diff --git a/system/globals.c b/system/globals.c
81
diff --git a/system/globals.c b/system/globals.c
80
index XXXXXXX..XXXXXXX 100644
82
index XXXXXXX..XXXXXXX 100644
81
--- a/system/globals.c
83
--- a/system/globals.c
82
+++ b/system/globals.c
84
+++ b/system/globals.c
83
@@ -XXX,XX +XXX,XX @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
85
@@ -XXX,XX +XXX,XX @@
84
int display_opengl;
86
85
const char* keyboard_layout;
87
bool should_mlock(MlockState state)
86
bool enable_mlock;
88
{
87
+bool enable_mlock_onfault;
89
- return state == MLOCK_ON;
88
bool enable_cpu_pm;
90
+ return state == MLOCK_ON || state == MLOCK_ON_FAULT;
89
int autostart = 1;
91
+}
90
int vga_interface_type = VGA_NONE;
92
+
93
+bool is_mlock_on_fault(MlockState state)
94
+{
95
+ return state == MLOCK_ON_FAULT;
96
}
97
98
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
91
diff --git a/system/vl.c b/system/vl.c
99
diff --git a/system/vl.c b/system/vl.c
92
index XXXXXXX..XXXXXXX 100644
100
index XXXXXXX..XXXXXXX 100644
93
--- a/system/vl.c
101
--- a/system/vl.c
94
+++ b/system/vl.c
102
+++ b/system/vl.c
95
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_overcommit_opts = {
103
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_overcommit_opts = {
...
...
100
+ .type = QEMU_OPT_STRING,
108
+ .type = QEMU_OPT_STRING,
101
},
109
},
102
{
110
{
103
.name = "cpu-pm",
111
.name = "cpu-pm",
104
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_run_with_opts = {
112
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_run_with_opts = {
105
106
static void realtime_init(void)
113
static void realtime_init(void)
107
{
114
{
108
- if (enable_mlock) {
115
if (should_mlock(mlock_state)) {
109
- if (os_mlock(false) < 0) {
116
- if (os_mlock(false) < 0) {
110
+ if (enable_mlock || enable_mlock_onfault) {
117
+ if (os_mlock(is_mlock_on_fault(mlock_state)) < 0) {
111
+ if (os_mlock(enable_mlock_onfault) < 0) {
112
error_report("locking memory failed");
118
error_report("locking memory failed");
113
exit(1);
119
exit(1);
114
}
120
}
115
@@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv)
121
@@ -XXX,XX +XXX,XX @@ static void object_option_parse(const char *str)
116
object_option_parse(optarg);
122
static void overcommit_parse(const char *str)
117
break;
123
{
118
case QEMU_OPTION_overcommit:
124
QemuOpts *opts;
119
- opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
125
- bool enable_mlock;
120
- optarg, false);
126
+ const char *mem_lock_opt;
121
- if (!opts) {
127
122
+ {
128
opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
123
+ const char *mem_lock_opt;
129
str, false);
130
@@ -XXX,XX +XXX,XX @@ static void overcommit_parse(const char *str)
131
exit(1);
132
}
133
134
- enable_mlock = qemu_opt_get_bool(opts, "mem-lock",
135
- should_mlock(mlock_state));
136
- mlock_state = enable_mlock ? MLOCK_ON : MLOCK_OFF;
137
-
138
enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
124
+
139
+
125
+ opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
140
+ mem_lock_opt = qemu_opt_get(opts, "mem-lock");
126
+ optarg, false);
141
+ if (!mem_lock_opt) {
127
+ if (!opts) {
142
+ return;
128
+ exit(1);
143
+ }
129
+ }
130
+
144
+
131
+ enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
145
+ if (strcmp(mem_lock_opt, "on") == 0) {
146
+ mlock_state = MLOCK_ON;
147
+ return;
148
+ }
132
+
149
+
133
+ mem_lock_opt = qemu_opt_get(opts, "mem-lock");
150
+ if (strcmp(mem_lock_opt, "off") == 0) {
134
+ if (!mem_lock_opt) {
151
+ mlock_state = MLOCK_OFF;
135
+ break;
152
+ return;
136
+ }
153
+ }
137
+
154
+
138
+ if (strcmp(mem_lock_opt, "on") == 0) {
155
+ if (strcmp(mem_lock_opt, "on-fault") == 0) {
139
+ enable_mlock = true;
156
+ mlock_state = MLOCK_ON_FAULT;
140
+ break;
157
+ return;
141
+ }
158
+ }
142
+
159
+
143
+ if (strcmp(mem_lock_opt, "off") == 0) {
160
+ error_report("parameter 'mem-lock' expects one of "
144
+ enable_mlock = false;
161
+ "'on', 'off', 'on-fault'");
145
+ enable_mlock_onfault = false;
162
+ exit(1);
146
+ break;
163
}
147
+ }
164
148
+
165
/*
149
+ if (strcmp(mem_lock_opt, "on-fault") == 0) {
150
+ enable_mlock_onfault = true;
151
+ break;
152
+ }
153
+
154
+ error_report("parameter 'mem-lock' expects one of "
155
+ "'on', 'off', 'on-fault'");
156
exit(1);
157
}
158
- enable_mlock = qemu_opt_get_bool(opts, "mem-lock", enable_mlock);
159
- enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm);
160
- break;
161
case QEMU_OPTION_compat:
162
{
163
CompatPolicy *opts_policy;
164
--
166
--
165
2.34.1
167
2.34.1
diff view generated by jsdifflib