All of lore.kernel.org
 help / color / mirror / Atom feed
* Swapping out kvm pages
@ 2007-04-11 13:34 Chen Haogang
       [not found] ` <c4ebe0280704110634h19ddc60egbff264b8e3dbc503-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Haogang @ 2007-04-11 13:34 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f


[-- Attachment #1.1: Type: text/plain, Size: 1159 bytes --]

In kvm's TODO page, I saw the item "attach kvm memory to a Linux
address_space so that guest memory can be paged out". But I don't think it
is as simple as this. Because both host part page fault and guest part page
fault interact.

As I know, the creation of guest's shadow PTEs don't go through host's PTEs.
When a shadow PTE is to be created, it always assumes the page pointer
stored in memory region is vaild, and use the page struct to calcuate host
physical address.

So, if we want to implement a swap mechanism. It is important to mark the
page struct pointer as invalid when host frame is swapped out. And replace
the page pointer with the new one when a frame is swapped in.

Moreover, we should not swapped out pages that are currently mapped by
shadow PTEs unless we got a way to invalidate them. On the guest part, when
a shadow PTE is to be created, we should make sure the page pointer in
memory regeion is vaild (i.e. the page is not swapped out), if not, we
should ask to host to bring in the page before guest can resume.

I want to know if I misunderstood anything, and wonder if there's any easier
way to implement guest pages' swapping?

[-- Attachment #1.2: Type: text/html, Size: 1255 bytes --]

[-- Attachment #2: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Swapping out kvm pages
       [not found] ` <c4ebe0280704110634h19ddc60egbff264b8e3dbc503-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-04-11 14:41   ` Avi Kivity
  2007-04-15  6:00   ` Chen Haogang
  1 sibling, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-04-11 14:41 UTC (permalink / raw)
  To: Chen Haogang; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Chen Haogang wrote:
>
> In kvm's TODO page, I saw the item "attach kvm memory to a Linux 
> address_space so that guest memory can be paged out". But I don't 
> think it is as simple as this. Because both host part page fault and 
> guest part page fault interact.
>
> As I know, the creation of guest's shadow PTEs don't go through host's 
> PTEs. When a shadow PTE is to be created, it always assumes the page 
> pointer stored in memory region is vaild, and use the page struct to 
> calcuate host physical address.
>
> So, if we want to implement a swap mechanism. It is important to mark 
> the page struct pointer as invalid when host frame is swapped out. And 
> replace the page pointer with the new one when a frame is swapped in.
>
> Moreover, we should not swapped out pages that are currently mapped by 
> shadow PTEs unless we got a way to invalidate them. On the guest part, 
> when a shadow PTE is to be created, we should make sure the page 
> pointer in memory regeion is vaild ( i.e. the page is not swapped 
> out), if not, we should ask to host to bring in the page before guest 
> can resume.
>
> I want to know if I misunderstood anything, and wonder if there's any 
> easier way to implement guest pages' swapping?
>
>

That's what I had in mind.  I don't know exactly how you prevent a page 
from being swapped; maybe it involves the page locked page flag, or 
maybe just incrementing its reference count is enough.  Paging in is 
probably simpler; if the page isn't in the page cache, bring it in and 
attach it to the shadow page table.

The only complication I see is with the upcoming nested/extended page 
tables, which want shadow page tables for *all* guest pages, making this 
scheme fail.  We can make npt/ept demand paged like current shadow 
paging, but it seems to be a pessimization.


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Swapping out kvm pages
       [not found] ` <c4ebe0280704110634h19ddc60egbff264b8e3dbc503-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2007-04-11 14:41   ` Avi Kivity
@ 2007-04-15  6:00   ` Chen Haogang
       [not found]     ` <c4ebe0280704142300x379fb7b8u2a8df7101292b414-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Chen Haogang @ 2007-04-15  6:00 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

I encountered another problem. Because guest uses its own PTEs, host
cannot track page usage of the guest, including dirty flag in guest
PTEs. So host will consider those pages clean and reclaim them without
writing back.

What I currently think to walk around this is set the PG_dirty flag
manually, but this involves tracking every guest write, and may
introduce heavy overhead. I wonder if kvm & qemu already have such
machanism and how about its overhead?

I also found many pages used by guest will be referenced by host. But
I don't know whether EVERY active guest pages will be mapped to host's
qemu. Do you know when and how will the host make references to those
guest pages?


2007/4/11, Chen Haogang <chg-fuK+BI7+yZkjr28BhZ4uKczWQAQhF3cR@public.gmane.org>:
>
>
> In kvm's TODO page, I saw the item "attach kvm memory to a Linux address_space so that guest memory can be paged out". But I don't think it is as simple as this. Because both host part page fault and guest part page fault interact.
>
> As I know, the creation of guest's shadow PTEs don't go through host's PTEs. When a shadow PTE is to be created, it always assumes the page pointer stored in memory region is vaild, and use the page struct to calcuate host physical address.
>
> So, if we want to implement a swap mechanism. It is important to mark the page struct pointer as invalid when host frame is swapped out. And replace the page pointer with the new one when a frame is swapped in.
>
> Moreover, we should not swapped out pages that are currently mapped by shadow PTEs unless we got a way to invalidate them. On the guest part, when a shadow PTE is to be created, we should make sure the page pointer in memory regeion is vaild ( i.e. the page is not swapped out), if not, we should ask to host to bring in the page before guest can resume.
>
> I want to know if I misunderstood anything, and wonder if there's any easier way to implement guest pages' swapping?
>
>



-- 
Best regards,
Chen Haogang

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Swapping out kvm pages
       [not found]     ` <c4ebe0280704142300x379fb7b8u2a8df7101292b414-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-04-15 17:13       ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-04-15 17:13 UTC (permalink / raw)
  To: Chen Haogang; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Chen Haogang wrote:
> I encountered another problem. Because guest uses its own PTEs, host
> cannot track page usage of the guest, including dirty flag in guest
> PTEs. So host will consider those pages clean and reclaim them without
> writing back.
>
> What I currently think to walk around this is set the PG_dirty flag
> manually, but this involves tracking every guest write, and may
> introduce heavy overhead. I wonder if kvm & qemu already have such
> machanism and how about its overhead?
>   

You don't need to track writes, only transitions of pte writable bits to
1.  These occur much more rarely than writes, and are quite easy to trap.

More difficult is the reverse operation: before the host cleans a page,
it must make it read-only for the guest.  It's doable but complex,
especially as the writeout operation and the guest may execute concurrently.

> I also found many pages used by guest will be referenced by host. But
> I don't know whether EVERY active guest pages will be mapped to host's
> qemu. Do you know when and how will the host make references to those
> guest pages?
>   

I expect most are due to dma by the network card and the disk
controller.  Also, operations like live migration will touch every page.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-04-15 17:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-11 13:34 Swapping out kvm pages Chen Haogang
     [not found] ` <c4ebe0280704110634h19ddc60egbff264b8e3dbc503-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-04-11 14:41   ` Avi Kivity
2007-04-15  6:00   ` Chen Haogang
     [not found]     ` <c4ebe0280704142300x379fb7b8u2a8df7101292b414-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-04-15 17:13       ` Avi Kivity

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.