From: David Hildenbrand <david@redhat.com>
To: Andrew Deason <adeason@sinenomine.net>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Peter Xu" <peterx@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH] softmmu/physmem: Use qemu_madvise
Date: Wed, 16 Mar 2022 08:51:36 +0100 [thread overview]
Message-ID: <9c36fe6b-39e1-0bfc-d2bb-97b106828ee1@redhat.com> (raw)
In-Reply-To: <20220316040405.4131-1-adeason@sinenomine.net>
On 16.03.22 05:04, Andrew Deason wrote:
> We have a thin wrapper around madvise, called qemu_madvise, which
> provides consistent behavior for the !CONFIG_MADVISE case, and works
> around some platform-specific quirks (some platforms only provide
> posix_madvise, and some don't offer all 'advise' types). This specific
> caller of madvise has never used it, tracing back to its original
> introduction in commit e0b266f01dd2 ("migration_completion: Take
> current state").
>
> Call qemu_madvise here, to follow the same logic as all of our other
> madvise callers. This slightly changes the behavior for
> !CONFIG_MADVISE (EINVAL instead of ENOSYS, and a slightly different
> error message), but this is now more consistent with other callers
> that use qemu_madvise.
>
> Signed-off-by: Andrew Deason <adeason@sinenomine.net>
> ---
> Looking at the history of commits that touch this madvise() call, it
> doesn't _look_ like there's any reason to be directly calling madvise vs
> qemu_advise (I don't see anything mentioned), but I'm not sure.
>
> softmmu/physmem.c | 12 ++----------
> 1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index 43ae70fbe2..900c692b5e 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -3584,40 +3584,32 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
> rb->idstr, start, length, ret);
> goto err;
> #endif
> }
> if (need_madvise) {
> /* For normal RAM this causes it to be unmapped,
> * for shared memory it causes the local mapping to disappear
> * and to fall back on the file contents (which we just
> * fallocate'd away).
> */
> -#if defined(CONFIG_MADVISE)
> if (qemu_ram_is_shared(rb) && rb->fd < 0) {
> - ret = madvise(host_startaddr, length, QEMU_MADV_REMOVE);
> + ret = qemu_madvise(host_startaddr, length, QEMU_MADV_REMOVE);
> } else {
> - ret = madvise(host_startaddr, length, QEMU_MADV_DONTNEED);
> + ret = qemu_madvise(host_startaddr, length, QEMU_MADV_DONTNEED);
posix_madvise(QEMU_MADV_DONTNEED) has completely different semantics
then madvise() -- it's not a discard that we need here.
So ram_block_discard_range() would now succeed in environments (BSD?)
where it's supposed to fail.
So AFAIKs this isn't sane.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-03-16 7:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-16 4:04 [PATCH] softmmu/physmem: Use qemu_madvise Andrew Deason
2022-03-16 4:14 ` Peter Xu
2022-03-16 7:51 ` David Hildenbrand [this message]
2022-03-16 9:26 ` Peter Maydell
2022-03-16 9:37 ` Dr. David Alan Gilbert
2022-03-16 9:41 ` David Hildenbrand
2022-03-16 14:29 ` Andrew Deason
2022-03-22 16:39 ` Andrew Deason
2022-03-22 16:43 ` David Hildenbrand
2022-03-22 16:53 ` Dr. David Alan Gilbert
2022-03-22 17:34 ` Andrew Deason
2022-03-22 17:58 ` Dr. David Alan Gilbert
2022-03-22 19:35 ` Andrew Deason
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=9c36fe6b-39e1-0bfc-d2bb-97b106828ee1@redhat.com \
--to=david@redhat.com \
--cc=adeason@sinenomine.net \
--cc=dgilbert@redhat.com \
--cc=f4bug@amsat.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).