From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Weil" <sw@weilnetz.de>, "Peter Xu" <peterx@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
qemu-devel@nongnu.org
Subject: Re: [PATCH v5 1/4] os: add an ability to lock memory on_fault
Date: Wed, 12 Feb 2025 15:30:21 +0000 [thread overview]
Message-ID: <Z6y-jdFOCVz8mEXo@redhat.com> (raw)
In-Reply-To: <20250212143920.1269754-2-d-tatianin@yandex-team.ru>
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-tatianin@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/include/system/os-posix.h b/include/system/os-posix.h
> index b881ac6c6f..ce5b3bccf8 100644
> --- a/include/system/os-posix.h
> +++ b/include/system/os-posix.h
> @@ -53,7 +53,7 @@ bool os_set_runas(const char *user_id);
> void os_set_chroot(const char *path);
> void os_setup_limits(void);
> void os_setup_post(void);
> -int os_mlock(void);
> +int os_mlock(bool on_fault);
>
> /**
> * qemu_alloc_stack:
> diff --git a/include/system/os-win32.h b/include/system/os-win32.h
> index b82a5d3ad9..cd61d69e10 100644
> --- a/include/system/os-win32.h
> +++ b/include/system/os-win32.h
> @@ -123,8 +123,9 @@ static inline bool is_daemonized(void)
> return false;
> }
>
> -static inline int os_mlock(void)
> +static inline int os_mlock(bool on_fault)
> {
> + (void)on_fault;
Is this really needed ? Our compiler flags don't enable warnings
about unused variables.
If they did, this would not be the way to hide them. Instead you
would use the "G_GNUC_UNUSED" annotation against the parameter.
eg
static inline int os_mlock(bool on_fault G_GNUC_UNUSED)
> return -ENOSYS;
> }
>
> 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
> +
> + ret = mlockall(flags);
> if (ret < 0) {
> error_report("mlockall: %s", strerror(errno));
> }
>
> return ret;
> #else
> + (void)on_fault;
> return -ENOSYS;
> #endif
Again casting to (void) should not be required AFAIK.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2025-02-12 15:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 14:39 [PATCH v5 0/4] overcommit: introduce mem-lock-onfault Daniil Tatianin
2025-02-12 14:39 ` [PATCH v5 1/4] os: add an ability to lock memory on_fault Daniil Tatianin
2025-02-12 14:47 ` Vladimir Sementsov-Ogievskiy
2025-02-12 14:48 ` Philippe Mathieu-Daudé
2025-02-12 14:51 ` Daniil Tatianin
2025-02-12 14:55 ` Philippe Mathieu-Daudé
2025-02-12 15:23 ` Peter Xu
2025-02-12 15:27 ` Daniil Tatianin
2025-02-12 15:46 ` Philippe Mathieu-Daudé
2025-02-12 15:30 ` Daniel P. Berrangé [this message]
2025-02-12 15:41 ` Peter Xu
2025-02-12 16:17 ` Daniil Tatianin
2025-02-12 16:42 ` Peter Xu
2025-02-12 16:46 ` Daniil Tatianin
2025-02-12 14:39 ` [PATCH v5 2/4] system/vl: extract overcommit option parsing into a helper Daniil Tatianin
2025-02-12 14:39 ` [PATCH v5 3/4] system: introduce a new MlockState enum Daniil Tatianin
2025-02-12 14:39 ` [PATCH v5 4/4] overcommit: introduce mem-lock=on-fault Daniil Tatianin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z6y-jdFOCVz8mEXo@redhat.com \
--to=berrange@redhat.com \
--cc=d-tatianin@yandex-team.ru \
--cc=farosas@suse.de \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.