1 | Currently, passing mem-lock=on to QEMU causes memory usage to grow by | 1 | Currently, passing mem-lock=on to QEMU causes memory usage to grow by |
---|---|---|---|
2 | huge amounts: | 2 | huge amounts: |
3 | 3 | ||
4 | no memlock: | 4 | no memlock: |
5 | $ qemu-system-x86_64 -overcommit mem-lock=off | 5 | $ ./qemu-system-x86_64 -overcommit mem-lock=off |
6 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= | 6 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= |
7 | 45652 | 7 | 45652 |
8 | 8 | ||
9 | $ ./qemu-system-x86_64 -overcommit mem-lock=off -enable-kvm | 9 | $ ./qemu-system-x86_64 -overcommit mem-lock=off -enable-kvm |
10 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= | 10 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= |
11 | 39756 | 11 | 39756 |
12 | 12 | ||
13 | memlock: | 13 | memlock: |
14 | $ qemu-system-x86_64 -overcommit mem-lock=on | 14 | $ ./qemu-system-x86_64 -overcommit mem-lock=on |
15 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= | 15 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= |
16 | 1309876 | 16 | 1309876 |
17 | 17 | ||
18 | $ ./qemu-system-x86_64 -overcommit mem-lock=on -enable-kvm | 18 | $ ./qemu-system-x86_64 -overcommit mem-lock=on -enable-kvm |
19 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= | 19 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= |
... | ... | ||
30 | active. | 30 | active. |
31 | 31 | ||
32 | mem-lock=on helps against this (given compact_unevictable_allowed is 0), | 32 | mem-lock=on helps against this (given compact_unevictable_allowed is 0), |
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 command line option called | 35 | is what this series allows to do with a new option for mem-lock called |
36 | mem-lock-onfault. | 36 | on-fault. |
37 | 37 | ||
38 | memlock-onfault: | 38 | memlock-onfault: |
39 | $ qemu-system-x86_64 -overcommit mem-lock-onfault=on | 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-onfault=on -enable-kvm | 43 | $ ./qemu-system-x86_64 -overcommit mem-lock=on-fault -enable-kvm |
44 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= | 44 | $ ps -p $(pidof ./qemu-system-x86_64) -o rss= |
45 | 47772 | 45 | 47772 |
46 | 46 | ||
47 | You may notice the memory usage is still slightly higher, in this case | 47 | You may notice the memory usage is still slightly higher, in this case |
48 | by a few megabytes over the mem-lock=off case. I was able to trace this | 48 | by a few megabytes over the mem-lock=off case. I was able to trace this |
49 | down to a bug in the linux kernel with MCL_ONFAULT not being honored for | 49 | down to a bug in the linux kernel with MCL_ONFAULT not being honored for |
50 | the early process heap (with brk(2) etc.) so it is still write-faulted in | 50 | the early process heap (with brk(2) etc.) so it is still write-faulted in |
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 | Daniil Tatianin (2): | 53 | Changes since v1: |
54 | - Don't make a separate mem-lock-onfault, add an on-fault option to mem-lock instead | ||
55 | |||
56 | Changes since v2: | ||
57 | - Move overcommit option parsing out of line | ||
58 | - Make enable_mlock an enum instead | ||
59 | |||
60 | Daniil Tatianin (4): | ||
54 | os: add an ability to lock memory on_fault | 61 | os: add an ability to lock memory on_fault |
55 | overcommit: introduce mem-lock-onfault | 62 | system/vl: extract overcommit option parsing into a helper |
63 | sysemu: introduce a new MlockState enum | ||
64 | overcommit: introduce mem-lock=on-fault | ||
56 | 65 | ||
66 | hw/virtio/virtio-mem.c | 2 +- | ||
57 | include/sysemu/os-posix.h | 2 +- | 67 | include/sysemu/os-posix.h | 2 +- |
58 | include/sysemu/os-win32.h | 3 ++- | 68 | include/sysemu/os-win32.h | 3 ++- |
59 | include/sysemu/sysemu.h | 1 + | 69 | include/sysemu/sysemu.h | 12 ++++++++- |
60 | migration/postcopy-ram.c | 4 ++-- | 70 | migration/postcopy-ram.c | 4 +-- |
61 | os-posix.c | 10 ++++++++-- | 71 | os-posix.c | 10 ++++++-- |
62 | qemu-options.hx | 13 ++++++++++--- | 72 | qemu-options.hx | 14 +++++++---- |
63 | system/globals.c | 1 + | 73 | system/globals.c | 12 ++++++++- |
64 | system/vl.c | 18 ++++++++++++++++-- | 74 | system/vl.c | 52 +++++++++++++++++++++++++++++++-------- |
65 | 8 files changed, 41 insertions(+), 11 deletions(-) | 75 | 9 files changed, 87 insertions(+), 24 deletions(-) |
66 | 76 | ||
67 | -- | 77 | -- |
68 | 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 | 13 ++++++++++--- | 12 | qemu-options.hx | 14 +++++++++----- |
13 | system/globals.c | 1 + | 13 | system/globals.c | 7 ++++++- |
14 | system/vl.c | 18 ++++++++++++++++-- | 14 | system/vl.c | 34 +++++++++++++++++++++++++++------- |
15 | 5 files changed, 30 insertions(+), 7 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 |
... | ... | ||
48 | @@ -XXX,XX +XXX,XX @@ SRST | 50 | @@ -XXX,XX +XXX,XX @@ SRST |
49 | ERST | 51 | ERST |
50 | 52 | ||
51 | DEF("overcommit", HAS_ARG, QEMU_OPTION_overcommit, | 53 | DEF("overcommit", HAS_ARG, QEMU_OPTION_overcommit, |
52 | - "-overcommit [mem-lock=on|off][cpu-pm=on|off]\n" | 54 | - "-overcommit [mem-lock=on|off][cpu-pm=on|off]\n" |
53 | + "-overcommit [mem-lock=on|off][mem-lock-onfault=on|off][cpu-pm=on|off]\n" | 55 | + "-overcommit [mem-lock=on|off|on-fault][cpu-pm=on|off]\n" |
54 | " run qemu with overcommit hints\n" | 56 | " run qemu with overcommit hints\n" |
55 | " mem-lock=on|off controls memory lock support (default: off)\n" | 57 | - " mem-lock=on|off controls memory lock support (default: off)\n" |
56 | + " mem-lock-onfault=on|off controls memory lock on fault support (default: off)\n" | 58 | + " mem-lock=on|off|on-fault controls memory lock support (default: off)\n" |
57 | " cpu-pm=on|off controls cpu power management (default: off)\n", | 59 | " cpu-pm=on|off controls cpu power management (default: off)\n", |
58 | QEMU_ARCH_ALL) | 60 | QEMU_ARCH_ALL) |
59 | SRST | 61 | SRST |
60 | ``-overcommit mem-lock=on|off`` | 62 | -``-overcommit mem-lock=on|off`` |
63 | +``-overcommit mem-lock=on|off|on-fault`` | ||
61 | \ | 64 | \ |
62 | +``-overcommit mem-lock-onfault=on|off`` | ||
63 | + \ | ||
64 | ``-overcommit cpu-pm=on|off`` | 65 | ``-overcommit cpu-pm=on|off`` |
65 | Run qemu with hints about host resource overcommit. The default is | 66 | Run qemu with hints about host resource overcommit. The default is |
66 | to assume that host overcommits all resources. | 67 | to assume that host overcommits all resources. |
67 | 68 | ||
68 | Locking qemu and guest memory can be enabled via ``mem-lock=on`` | 69 | Locking qemu and guest memory can be enabled via ``mem-lock=on`` |
69 | - (disabled by default). This works when host memory is not | 70 | - (disabled by default). This works when host memory is not |
70 | - overcommitted and reduces the worst-case latency for guest. | 71 | - overcommitted and reduces the worst-case latency for guest. |
71 | + or ``mem-lock-onfault=on`` (disabled by default). This works when | 72 | + or ``mem-lock=on-fault`` (disabled by default). This works when |
72 | + host memory is not overcommitted and reduces the worst-case latency for | 73 | + host memory is not overcommitted and reduces the worst-case latency for |
73 | + guest. The on-fault option is better for reducing the memory footprint | 74 | + guest. The on-fault option is better for reducing the memory footprint |
74 | + since it makes allocations lazy, but the pages still get locked in place | 75 | + since it makes allocations lazy, but the pages still get locked in place |
75 | + once faulted by the guest or QEMU. Note that the two options are mutually | 76 | + once faulted by the guest or QEMU. Note that the two options are mutually |
76 | + exclusive. | 77 | + exclusive. |
... | ... | ||
79 | 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 |
80 | diff --git a/system/globals.c b/system/globals.c | 81 | diff --git a/system/globals.c b/system/globals.c |
81 | index XXXXXXX..XXXXXXX 100644 | 82 | index XXXXXXX..XXXXXXX 100644 |
82 | --- a/system/globals.c | 83 | --- a/system/globals.c |
83 | +++ b/system/globals.c | 84 | +++ b/system/globals.c |
84 | @@ -XXX,XX +XXX,XX @@ enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; | 85 | @@ -XXX,XX +XXX,XX @@ |
85 | int display_opengl; | 86 | |
86 | const char* keyboard_layout; | 87 | bool should_mlock(MlockState state) |
87 | bool enable_mlock; | 88 | { |
88 | +bool enable_mlock_onfault; | 89 | - return state == MLOCK_ON; |
89 | bool enable_cpu_pm; | 90 | + return state == MLOCK_ON || state == MLOCK_ON_FAULT; |
90 | int autostart = 1; | 91 | +} |
91 | 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; | ||
92 | diff --git a/system/vl.c b/system/vl.c | 99 | diff --git a/system/vl.c b/system/vl.c |
93 | index XXXXXXX..XXXXXXX 100644 | 100 | index XXXXXXX..XXXXXXX 100644 |
94 | --- a/system/vl.c | 101 | --- a/system/vl.c |
95 | +++ b/system/vl.c | 102 | +++ b/system/vl.c |
96 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_overcommit_opts = { | 103 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_overcommit_opts = { |
104 | .desc = { | ||
105 | { | ||
97 | .name = "mem-lock", | 106 | .name = "mem-lock", |
98 | .type = QEMU_OPT_BOOL, | 107 | - .type = QEMU_OPT_BOOL, |
108 | + .type = QEMU_OPT_STRING, | ||
99 | }, | 109 | }, |
100 | + { | ||
101 | + .name = "mem-lock-onfault", | ||
102 | + .type = QEMU_OPT_BOOL, | ||
103 | + }, | ||
104 | { | 110 | { |
105 | .name = "cpu-pm", | 111 | .name = "cpu-pm", |
106 | .type = QEMU_OPT_BOOL, | ||
107 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_run_with_opts = { | 112 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_run_with_opts = { |
108 | |||
109 | static void realtime_init(void) | 113 | static void realtime_init(void) |
110 | { | 114 | { |
111 | - if (enable_mlock) { | 115 | if (should_mlock(mlock_state)) { |
112 | - if (os_mlock(false) < 0) { | 116 | - if (os_mlock(false) < 0) { |
113 | + if (enable_mlock || enable_mlock_onfault) { | 117 | + if (os_mlock(is_mlock_on_fault(mlock_state)) < 0) { |
114 | + if (os_mlock(enable_mlock_onfault) < 0) { | ||
115 | error_report("locking memory failed"); | 118 | error_report("locking memory failed"); |
116 | exit(1); | 119 | exit(1); |
117 | } | 120 | } |
118 | @@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv) | 121 | @@ -XXX,XX +XXX,XX @@ static void object_option_parse(const char *str) |
119 | if (!opts) { | 122 | static void overcommit_parse(const char *str) |
120 | exit(1); | 123 | { |
121 | } | 124 | QemuOpts *opts; |
125 | - bool enable_mlock; | ||
126 | + const char *mem_lock_opt; | ||
127 | |||
128 | opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"), | ||
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); | ||
122 | + | 139 | + |
123 | enable_mlock = qemu_opt_get_bool(opts, "mem-lock", enable_mlock); | 140 | + mem_lock_opt = qemu_opt_get(opts, "mem-lock"); |
124 | + enable_mlock_onfault = qemu_opt_get_bool(opts, | 141 | + if (!mem_lock_opt) { |
125 | + "mem-lock-onfault", | 142 | + return; |
126 | + enable_mlock_onfault); | 143 | + } |
127 | + if (enable_mlock && enable_mlock_onfault) { | ||
128 | + error_report("mem-lock and mem-lock-onfault are mutually" | ||
129 | + "exclusive"); | ||
130 | + exit(1); | ||
131 | + } | ||
132 | + | 144 | + |
133 | enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", enable_cpu_pm); | 145 | + if (strcmp(mem_lock_opt, "on") == 0) { |
134 | break; | 146 | + mlock_state = MLOCK_ON; |
135 | case QEMU_OPTION_compat: | 147 | + return; |
148 | + } | ||
149 | + | ||
150 | + if (strcmp(mem_lock_opt, "off") == 0) { | ||
151 | + mlock_state = MLOCK_OFF; | ||
152 | + return; | ||
153 | + } | ||
154 | + | ||
155 | + if (strcmp(mem_lock_opt, "on-fault") == 0) { | ||
156 | + mlock_state = MLOCK_ON_FAULT; | ||
157 | + return; | ||
158 | + } | ||
159 | + | ||
160 | + error_report("parameter 'mem-lock' expects one of " | ||
161 | + "'on', 'off', 'on-fault'"); | ||
162 | + exit(1); | ||
163 | } | ||
164 | |||
165 | /* | ||
136 | -- | 166 | -- |
137 | 2.34.1 | 167 | 2.34.1 | diff view generated by jsdifflib |