... | ... | ||
---|---|---|---|
55 | 55 | ||
56 | Changes since v2: | 56 | Changes since v2: |
57 | - Move overcommit option parsing out of line | 57 | - Move overcommit option parsing out of line |
58 | - Make enable_mlock an enum instead | 58 | - Make enable_mlock an enum instead |
59 | 59 | ||
60 | Changes since v3: | ||
61 | - Rebase to latest master due to the recent sysemu -> system renames | ||
62 | |||
63 | Changes since v4: | ||
64 | - Fix compile errors under FreeBSD and MacOS | ||
65 | |||
60 | Daniil Tatianin (4): | 66 | Daniil Tatianin (4): |
61 | os: add an ability to lock memory on_fault | 67 | os: add an ability to lock memory on_fault |
62 | system/vl: extract overcommit option parsing into a helper | 68 | system/vl: extract overcommit option parsing into a helper |
63 | sysemu: introduce a new MlockState enum | 69 | system: introduce a new MlockState enum |
64 | overcommit: introduce mem-lock=on-fault | 70 | overcommit: introduce mem-lock=on-fault |
65 | 71 | ||
66 | hw/virtio/virtio-mem.c | 2 +- | 72 | hw/virtio/virtio-mem.c | 2 +- |
67 | include/sysemu/os-posix.h | 2 +- | 73 | include/system/os-posix.h | 2 +- |
68 | include/sysemu/os-win32.h | 3 ++- | 74 | include/system/os-win32.h | 3 ++- |
69 | include/sysemu/sysemu.h | 12 ++++++++- | 75 | include/system/system.h | 12 ++++++++- |
76 | meson.build | 6 +++++ | ||
70 | migration/postcopy-ram.c | 4 +-- | 77 | migration/postcopy-ram.c | 4 +-- |
71 | os-posix.c | 10 ++++++-- | 78 | os-posix.c | 14 +++++++++-- |
72 | qemu-options.hx | 14 +++++++---- | 79 | qemu-options.hx | 14 +++++++---- |
73 | system/globals.c | 12 ++++++++- | 80 | system/globals.c | 12 ++++++++- |
74 | system/vl.c | 52 +++++++++++++++++++++++++++++++-------- | 81 | system/vl.c | 52 +++++++++++++++++++++++++++++++-------- |
75 | 9 files changed, 87 insertions(+), 24 deletions(-) | 82 | 10 files changed, 97 insertions(+), 24 deletions(-) |
76 | 83 | ||
77 | -- | 84 | -- |
78 | 2.34.1 | 85 | 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> | ||
6 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> | 4 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> |
7 | --- | 5 | --- |
8 | include/sysemu/os-posix.h | 2 +- | 6 | include/system/os-posix.h | 2 +- |
9 | include/sysemu/os-win32.h | 3 ++- | 7 | include/system/os-win32.h | 3 ++- |
8 | meson.build | 6 ++++++ | ||
10 | migration/postcopy-ram.c | 2 +- | 9 | migration/postcopy-ram.c | 2 +- |
11 | os-posix.c | 10 ++++++++-- | 10 | os-posix.c | 14 ++++++++++++-- |
12 | system/vl.c | 2 +- | 11 | system/vl.c | 2 +- |
13 | 5 files changed, 13 insertions(+), 6 deletions(-) | 12 | 6 files changed, 23 insertions(+), 6 deletions(-) |
14 | 13 | ||
15 | diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h | 14 | diff --git a/include/system/os-posix.h b/include/system/os-posix.h |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/sysemu/os-posix.h | 16 | --- a/include/system/os-posix.h |
18 | +++ b/include/sysemu/os-posix.h | 17 | +++ b/include/system/os-posix.h |
19 | @@ -XXX,XX +XXX,XX @@ bool os_set_runas(const char *user_id); | 18 | @@ -XXX,XX +XXX,XX @@ bool os_set_runas(const char *user_id); |
20 | void os_set_chroot(const char *path); | 19 | void os_set_chroot(const char *path); |
21 | void os_setup_limits(void); | 20 | void os_setup_limits(void); |
22 | void os_setup_post(void); | 21 | void os_setup_post(void); |
23 | -int os_mlock(void); | 22 | -int os_mlock(void); |
24 | +int os_mlock(bool on_fault); | 23 | +int os_mlock(bool on_fault); |
25 | 24 | ||
26 | /** | 25 | /** |
27 | * qemu_alloc_stack: | 26 | * qemu_alloc_stack: |
28 | diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h | 27 | diff --git a/include/system/os-win32.h b/include/system/os-win32.h |
29 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/include/sysemu/os-win32.h | 29 | --- a/include/system/os-win32.h |
31 | +++ b/include/sysemu/os-win32.h | 30 | +++ b/include/system/os-win32.h |
32 | @@ -XXX,XX +XXX,XX @@ static inline bool is_daemonized(void) | 31 | @@ -XXX,XX +XXX,XX @@ static inline bool is_daemonized(void) |
33 | return false; | 32 | return false; |
34 | } | 33 | } |
35 | 34 | ||
36 | -static inline int os_mlock(void) | 35 | -static inline int os_mlock(void) |
37 | +static inline int os_mlock(bool on_fault) | 36 | +static inline int os_mlock(bool on_fault) |
38 | { | 37 | { |
39 | + (void)on_fault; | 38 | + (void)on_fault; |
40 | return -ENOSYS; | 39 | return -ENOSYS; |
41 | } | 40 | } |
42 | 41 | ||
42 | diff --git a/meson.build b/meson.build | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/meson.build | ||
45 | +++ b/meson.build | ||
46 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('HAVE_MLOCKALL', cc.links(gnu_source_prefix + ''' | ||
47 | return mlockall(MCL_FUTURE); | ||
48 | }''')) | ||
49 | |||
50 | +config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(gnu_source_prefix + ''' | ||
51 | + #include <sys/mman.h> | ||
52 | + int main(void) { | ||
53 | + return mlockall(MCL_FUTURE | MCL_ONFAULT); | ||
54 | + }''')) | ||
55 | + | ||
56 | have_l2tpv3 = false | ||
57 | if get_option('l2tpv3').allowed() and have_system | ||
58 | have_l2tpv3 = cc.has_type('struct mmsghdr', | ||
43 | diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c | 59 | diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c |
44 | index XXXXXXX..XXXXXXX 100644 | 60 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/migration/postcopy-ram.c | 61 | --- a/migration/postcopy-ram.c |
46 | +++ b/migration/postcopy-ram.c | 62 | +++ b/migration/postcopy-ram.c |
47 | @@ -XXX,XX +XXX,XX @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) | 63 | @@ -XXX,XX +XXX,XX @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) |
... | ... | ||
67 | #ifdef HAVE_MLOCKALL | 83 | #ifdef HAVE_MLOCKALL |
68 | int ret = 0; | 84 | int ret = 0; |
69 | + int flags = MCL_CURRENT | MCL_FUTURE; | 85 | + int flags = MCL_CURRENT | MCL_FUTURE; |
70 | 86 | ||
71 | - ret = mlockall(MCL_CURRENT | MCL_FUTURE); | 87 | - ret = mlockall(MCL_CURRENT | MCL_FUTURE); |
88 | +#ifdef HAVE_MLOCK_ONFAULT | ||
72 | + if (on_fault) { | 89 | + if (on_fault) { |
73 | + flags |= MCL_ONFAULT; | 90 | + flags |= MCL_ONFAULT; |
74 | + } | 91 | + } |
92 | +#else | ||
93 | + (void)on_fault; | ||
94 | +#endif | ||
75 | + | 95 | + |
76 | + ret = mlockall(flags); | 96 | + ret = mlockall(flags); |
77 | if (ret < 0) { | 97 | if (ret < 0) { |
78 | error_report("mlockall: %s", strerror(errno)); | 98 | error_report("mlockall: %s", strerror(errno)); |
79 | } | 99 | } |
... | ... | diff view generated by jsdifflib |
1 | This will be extended in the future commits, let's move it out of line | 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. | 2 | right away so that it's easier to read. |
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 | system/vl.c | 21 ++++++++++++++------- | 8 | system/vl.c | 21 ++++++++++++++------- |
7 | 1 file changed, 14 insertions(+), 7 deletions(-) | 9 | 1 file changed, 14 insertions(+), 7 deletions(-) |
8 | 10 | ||
... | ... | diff view generated by jsdifflib |
1 | Replace the boolean value enable_mlock with an enum and add a helper to | 1 | Replace the boolean value enable_mlock with an enum and add a helper to |
---|---|---|---|
2 | decide whether we should be calling os_mlock. | 2 | decide whether we should be calling os_mlock. |
3 | 3 | ||
4 | This is a stepping stone towards introducing a new mlock mode, which | 4 | This is a stepping stone towards introducing a new mlock mode, which |
5 | will be the third possible state of this enum. | 5 | will be the third possible state of this enum. |
6 | 6 | ||
7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> | ||
8 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
7 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> | 9 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> |
8 | --- | 10 | --- |
9 | hw/virtio/virtio-mem.c | 2 +- | 11 | hw/virtio/virtio-mem.c | 2 +- |
10 | include/sysemu/sysemu.h | 10 +++++++++- | 12 | include/system/system.h | 10 +++++++++- |
11 | migration/postcopy-ram.c | 2 +- | 13 | migration/postcopy-ram.c | 2 +- |
12 | system/globals.c | 7 ++++++- | 14 | system/globals.c | 7 ++++++- |
13 | system/vl.c | 9 +++++++-- | 15 | system/vl.c | 9 +++++++-- |
14 | 5 files changed, 24 insertions(+), 6 deletions(-) | 16 | 5 files changed, 24 insertions(+), 6 deletions(-) |
15 | 17 | ||
... | ... | ||
24 | - if (enable_mlock) { | 26 | - if (enable_mlock) { |
25 | + if (should_mlock(mlock_state)) { | 27 | + if (should_mlock(mlock_state)) { |
26 | error_setg(errp, "Incompatible with mlock"); | 28 | error_setg(errp, "Incompatible with mlock"); |
27 | return; | 29 | return; |
28 | } | 30 | } |
29 | diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h | 31 | diff --git a/include/system/system.h b/include/system/system.h |
30 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/include/sysemu/sysemu.h | 33 | --- a/include/system/system.h |
32 | +++ b/include/sysemu/sysemu.h | 34 | +++ b/include/system/system.h |
33 | @@ -XXX,XX +XXX,XX @@ extern int display_opengl; | 35 | @@ -XXX,XX +XXX,XX @@ extern int display_opengl; |
34 | extern const char *keyboard_layout; | 36 | extern const char *keyboard_layout; |
35 | extern int old_param; | 37 | extern int old_param; |
36 | extern uint8_t *boot_splash_filedata; | 38 | extern uint8_t *boot_splash_filedata; |
37 | -extern bool enable_mlock; | 39 | -extern bool enable_mlock; |
... | ... | ||
66 | diff --git a/system/globals.c b/system/globals.c | 68 | diff --git a/system/globals.c b/system/globals.c |
67 | index XXXXXXX..XXXXXXX 100644 | 69 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/system/globals.c | 70 | --- a/system/globals.c |
69 | +++ b/system/globals.c | 71 | +++ b/system/globals.c |
70 | @@ -XXX,XX +XXX,XX @@ | 72 | @@ -XXX,XX +XXX,XX @@ |
71 | #include "sysemu/cpus.h" | 73 | #include "system/cpus.h" |
72 | #include "sysemu/sysemu.h" | 74 | #include "system/system.h" |
73 | 75 | ||
74 | +bool should_mlock(MlockState state) | 76 | +bool should_mlock(MlockState state) |
75 | +{ | 77 | +{ |
76 | + return state == MLOCK_ON; | 78 | + return state == MLOCK_ON; |
77 | +} | 79 | +} |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
3 | overhead in terms of memory usage when all you want to do is to prevent | 3 | overhead in terms of memory usage when all you want to do is to prevent |
4 | kcompactd from migrating and compacting QEMU pages. Add an option to | 4 | kcompactd from migrating and compacting QEMU pages. Add an option to |
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 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> | ||
9 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
8 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> | 10 | Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> |
9 | --- | 11 | --- |
10 | include/sysemu/sysemu.h | 2 ++ | 12 | include/system/system.h | 2 ++ |
11 | migration/postcopy-ram.c | 2 +- | 13 | migration/postcopy-ram.c | 2 +- |
12 | qemu-options.hx | 14 +++++++++----- | 14 | qemu-options.hx | 14 +++++++++----- |
13 | system/globals.c | 7 ++++++- | 15 | system/globals.c | 7 ++++++- |
14 | system/vl.c | 34 +++++++++++++++++++++++++++------- | 16 | system/vl.c | 34 +++++++++++++++++++++++++++------- |
15 | 5 files changed, 45 insertions(+), 14 deletions(-) | 17 | 5 files changed, 45 insertions(+), 14 deletions(-) |
16 | 18 | ||
17 | diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h | 19 | diff --git a/include/system/system.h b/include/system/system.h |
18 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/sysemu/sysemu.h | 21 | --- a/include/system/system.h |
20 | +++ b/include/sysemu/sysemu.h | 22 | +++ b/include/system/system.h |
21 | @@ -XXX,XX +XXX,XX @@ extern QEMUClockType rtc_clock; | 23 | @@ -XXX,XX +XXX,XX @@ extern QEMUClockType rtc_clock; |
22 | typedef enum { | 24 | typedef enum { |
23 | MLOCK_OFF = 0, | 25 | MLOCK_OFF = 0, |
24 | MLOCK_ON, | 26 | MLOCK_ON, |
25 | + MLOCK_ON_FAULT, | 27 | + MLOCK_ON_FAULT, |
... | ... | diff view generated by jsdifflib |