linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: fluxion <flukshun@gmail.com>
To: Jidong Xiao <jidong.xiao@gmail.com>
Cc: virtualization@lists.linux-foundation.org, linux-mm@kvack.org
Subject: Re: Strange finding about kernel samepage merging
Date: Mon, 6 Feb 2012 23:46:41 -0600	[thread overview]
Message-ID: <CANAOKxsFYCW7EzrbNn4jc3wOq6dmDE-pnpn0khxvb4C0iP3DtA@mail.gmail.com> (raw)
In-Reply-To: <CAG4AFWZGr8SQF0rV+iys04HWmQ5WEGvXNcSZ9qJ7Jj9+FRbjCg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1518 bytes --]

On Feb 6, 2012 10:14 PM, "Jidong Xiao" <jidong.xiao@gmail.com> wrote:
>
> On Mon, Feb 6, 2012 at 10:35 PM, Michael Roth <mdroth@linux.vnet.ibm.com>
wrote:
> > My guess is you end up with 2 copies of each page on the guest: the
copy in
> > the guest's page cache, and the copy in the buffer you allocated. From
the
> > perspective of the host this all looks like anonymous memory, so ksm
merges
> > the pages.
>
> Yes, the result definitely shows that there two copies. But I don't
> understand why there would be two copies. So whenever you allocate
> memory in a guest OS, you will always create two copies of the same
> memory?

Well, not just guests, hosts as well. Most operating systems will, by
default, cache the data read from disks in memory to speed up subsequent
access. In your case you're also creating a copy by allocating a second
buffer and storing the data there as well.

Ksm only merges anonymous pages, not disk/page cache, but since your
guest's pagecache looks like anonymous memory to the host, ksm is able to
merge the dupes.

>
> An interesting thing is, if I replace the posix_memalign() function
> with the malloc() function (See the original program, the commented
> line.) there would be only one copy, i.e., no merging happens,
> however, since I need to have some page-aligned memory, that's why I
> use posix_memalign().

Yup, ksm can only detect duplicate pages, so if your buffer isn't page
aligned it's unable to merge with the copy in the guest's page cache

>
> Regards
> Jidong
>

[-- Attachment #2: Type: text/html, Size: 1889 bytes --]

      reply	other threads:[~2012-02-07  5:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 22:44 Jidong Xiao
2012-02-07  3:35 ` Michael Roth
2012-02-07  4:13   ` Jidong Xiao
2012-02-07  5:46     ` fluxion [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=CANAOKxsFYCW7EzrbNn4jc3wOq6dmDE-pnpn0khxvb4C0iP3DtA@mail.gmail.com \
    --to=flukshun@gmail.com \
    --cc=jidong.xiao@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=virtualization@lists.linux-foundation.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