On 12/2/25 16:23, Peter Xu wrote:
On Wed, Feb 12, 2025 at 05:39:17PM +0300, Daniil Tatianin wrote:
This will be used in the following commits to make it possible to only
lock memory on fault instead of right away.
Signed-off-by: Daniil Tatianin <d-tatia...@yandex-team.ru>
---
include/system/os-posix.h | 2 +-
include/system/os-win32.h | 3 ++-
meson.build | 6 ++++++
migration/postcopy-ram.c | 2 +-
os-posix.c | 14 ++++++++++++--
system/vl.c | 2 +-
6 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/os-posix.c b/os-posix.c
index 9cce55ff2f..17b144c0a2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -327,18 +327,28 @@ void os_set_line_buffering(void)
setvbuf(stdout, NULL, _IOLBF, 0);
}
-int os_mlock(void)
+int os_mlock(bool on_fault)
{
#ifdef HAVE_MLOCKALL
int ret = 0;
+ int flags = MCL_CURRENT | MCL_FUTURE;
- ret = mlockall(MCL_CURRENT | MCL_FUTURE);
+#ifdef HAVE_MLOCK_ONFAULT
+ if (on_fault) {
+ flags |= MCL_ONFAULT;
+ }
+#else
+ (void)on_fault;
+#endif
IIUC we should fail this when not supported.
Would you mind I squash this in?
diff --git a/os-posix.c b/os-posix.c
index 17b144c0a2..52925c23d3 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -333,13 +333,14 @@ int os_mlock(bool on_fault)
int ret = 0;
int flags = MCL_CURRENT | MCL_FUTURE;
-#ifdef HAVE_MLOCK_ONFAULT
if (on_fault) {
+#ifdef HAVE_MLOCK_ONFAULT
flags |= MCL_ONFAULT;
- }
#else
- (void)on_fault;
+ error_report("mlockall: on_fault not supported");
+ return -EINVAL;
Good point!
#endif
+ }
ret = mlockall(flags);
if (ret < 0) {