public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <andrea@qumranet.com>
To: Sukanto Ghosh <sukanto.cse.iitb@gmail.com>
Cc: dor.laor@qumranet.com, kvm@vger.kernel.org
Subject: Re: Need advice on timed access to guest pages
Date: Thu, 3 Jul 2008 17:41:46 +0200	[thread overview]
Message-ID: <20080703154146.GG21788@duo.random> (raw)
In-Reply-To: <a85e78f50807030804u28c65b8fk1703429be105fa6@mail.gmail.com>

Hi Sukanto,

On Thu, Jul 03, 2008 at 08:34:58PM +0530, Sukanto Ghosh wrote:
> > The current kvm without mmu-notifiers, can transparently swap guest
> > pages only if they are not pointed by the shadow page tables.
> > One a spte is instantiated the page cannot go to swap.
> 
> Can you explain why spte's must be unmapped as well ?

Whenever a linux pagetable or a kvm spte is established, the page
mapped by them has its reference count increased by 1. That tells the
VM the page is referenced by someone and it prevents it to be swapped
out.

The page will look like it was swapped because the pte is successfully
removed, the page will go in swapcache, but it will remain in ram as
long as there's any spte still mapping it. mmu notifiers fixes this.

> The memory region occupied by the structures maintaining the spte's
> (kvm_mmu_page) they are also part of Linux VM. So why won't they be
> swapped by Linux VM.
> I didn't get the problem behind secondary MMU.

sptes, ptes and all kernel data structures are never swapped. Only the
userland memory (and in this case the guest physical ram) is entirely
swapped. And any sptes still mapping a swapcache page prevents the
swapcache to be written to disk and later freed.

It's similar to O_DIRECT, when you do zerocopy dma to a page, you
can't allow the page to be swapped out or the DMA will happen on freed
ram. The page pinning mechanism works fine for temporary pins like
O_DIRECT, but for sptes the pin can last forever if they're
successfully cached.

> ( I was going through the slides of presentation "Integrating  with
> the KVM Linux Memory Management" by Andrea Arcangeli : KVM Forum 2008
> )

You can check the picture, it shows the page being unmapped by the
linux pte when linux swaps, but its reference count being still pinned
if there are spte still mapping it.

It also shows that with mmu notifiers the sptes don't take refcount
anymore (or alternatively depending on the implementation the spte pin
is removed at the same time the linux pte is zapped) and that allows
the whole guest physical memory to be swapped as any other malloc.

  reply	other threads:[~2008-07-03 15:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03 15:04 Need advice on timed access to guest pages Sukanto Ghosh
2008-07-03 15:41 ` Andrea Arcangeli [this message]
2008-07-04  7:10   ` Sukanto Ghosh
  -- strict thread matches above, loose matches on Subject: below --
2008-07-02  6:11 Arn
2008-07-02 11:41 ` Dor Laor
2008-07-02 21:06   ` Arn

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=20080703154146.GG21788@duo.random \
    --to=andrea@qumranet.com \
    --cc=dor.laor@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --cc=sukanto.cse.iitb@gmail.com \
    /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