Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Nikita Kalyazin <kalyazin@amazon.com>
To: James Houghton <jthoughton@google.com>,
	"Kalyazin, Nikita" <kalyazin@amazon.co.uk>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"michael.day@amd.com" <michael.day@amd.com>,
	"david@redhat.com" <david@redhat.com>,
	"Roy, Patrick" <roypat@amazon.co.uk>,
	"Thomson, Jack" <jackabt@amazon.co.uk>,
	"Manwaring, Derek" <derekmn@amazon.com>,
	"Cali, Marco" <xmarcalx@amazon.co.uk>
Subject: Re: [PATCH v5 0/2] KVM: guest_memfd: use write for population
Date: Thu, 11 Sep 2025 11:15:17 +0100	[thread overview]
Message-ID: <ad56d448-4016-46d8-90ca-f0f17f7587c7@amazon.com> (raw)
In-Reply-To: <CADrL8HVEAUdg5eJrU+RveR1+s+9ArdO6wa7EntLQZMu_iwBm-w@mail.gmail.com>



On 10/09/2025 22:37, James Houghton wrote:
> On Tue, Sep 2, 2025 at 4:20 AM Kalyazin, Nikita <kalyazin@amazon.co.uk> wrote:
>>
>> [ based on kvm/next ]
>>
>> Implement guest_memfd allocation and population via the write syscall.
>> This is useful in non-CoCo use cases where the host can access guest
>> memory.  Even though the same can also be achieved via userspace mapping
>> and memcpying from userspace, write provides a more performant option
>> because it does not need to set page tables and it does not cause a page
>> fault for every page like memcpy would.  Note that memcpy cannot be
>> accelerated via MADV_POPULATE_WRITE as it is  not supported by
>> guest_memfd and relies on GUP.
>>
>> Populating 512MiB of guest_memfd on a x86 machine:
>>   - via memcpy: 436 ms
>>   - via write:  202 ms (-54%)
> 
> Silly question: can you remind me why this speed-up is important?

The speed-up is important for the Firecracker use case [1] because it is 
likely for the population to stand on the hot path of the snapshot 
restore process.  Even though we aim to prepopulate the guest memory 
before it gets accessed by the guest, for large VMs the guest has a good 
chance to hit a page that isn't yet populated triggering on-demand fault 
handling which is much slower, and we'd like to avoid those as much as 
we can.

[1]: 
https://github.com/firecracker-microvm/firecracker/blob/main/docs/snapshotting/handling-page-faults-on-snapshot-resume.md


> 
> Also, I think we can get the same effect as MADV_POPULATE_WRITE just
> by making a second VMA for the memory file and reading the first byte
> of each page. Is that a viable strategy for your use case?

If I understand correctly what you mean, it doesn't look much different 
from the memcpy option I mention above.  All those one-byte read 
accesses will trigger user mapping faults for every page, and they are 
quite slow.  write() allows to avoid them completely.


> 
> Seems fine to me to allow write() for guest_memfd anyway. :)

Glad to hear that!


      reply	other threads:[~2025-09-11 10:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 11:19 [PATCH v5 0/2] KVM: guest_memfd: use write for population Kalyazin, Nikita
2025-09-02 11:20 ` [PATCH v5 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
2025-09-10 21:23   ` James Houghton
2025-09-11 10:15     ` Nikita Kalyazin
2025-09-12 13:36       ` David Hildenbrand
2025-09-12 14:48         ` Nikita Kalyazin
2025-09-12 15:39           ` David Hildenbrand
2025-09-13  0:18             ` Vishal Annapurve
2025-09-15 11:01               ` Nikita Kalyazin
2025-09-12 22:34       ` James Houghton
2025-09-13  0:32         ` Vishal Annapurve
2025-09-15 11:00           ` Nikita Kalyazin
2025-09-16  1:08             ` Vishal Annapurve
2025-09-15 11:00         ` Nikita Kalyazin
2025-09-02 11:20 ` [PATCH v5 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita
2025-09-10 21:37 ` [PATCH v5 0/2] KVM: guest_memfd: use write for population James Houghton
2025-09-11 10:15   ` Nikita Kalyazin [this message]

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=ad56d448-4016-46d8-90ca-f0f17f7587c7@amazon.com \
    --to=kalyazin@amazon.com \
    --cc=david@redhat.com \
    --cc=derekmn@amazon.com \
    --cc=jackabt@amazon.co.uk \
    --cc=jthoughton@google.com \
    --cc=kalyazin@amazon.co.uk \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=michael.day@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=roypat@amazon.co.uk \
    --cc=shuah@kernel.org \
    --cc=xmarcalx@amazon.co.uk \
    /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