qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "jack.chen" <zhunxun@gmail.com>
Cc: qemu <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] qemu memory manage question
Date: Mon, 17 Apr 2017 18:26:07 +0800	[thread overview]
Message-ID: <20170417102607.GE16703@pxdev.xzpeter.org> (raw)
In-Reply-To: <CADUDsAo4-QypkwSR9p8ABpBRqtvCO886fec2BGdq1JtgCgt-6w@mail.gmail.com>

On Mon, Apr 17, 2017 at 06:09:11PM +0800, jack.chen wrote:
> hello,I have some questions about memory allocation in qemu for
> virtual machine.I found when configure_accelerator function was called
> ,memory slots  were registered to KVM,but at that time address_space
> have not been initialized and ram have not been allocated,it is really
> confused me,Thanks a lot!!

Here's how I understand it...

configure_accelerator() does not register memory slots in KVM.
Instead, it registers memory listeners. See
kvm_memory_listener_register(), especially:

    kml->listener.region_add = kvm_region_add;

That's the hook function to be called when there are new memory region
added to the system.

Further, when RAM is initialzed, it'll modify the address space layout
of system_memory, and the registered listener of KVM (kvm_region_add)
will be invoked, it'll further sync with kvm. It should be in the
following path if you break at kvm_region_add in gdb:

#0  0x00005555557ba13a in kvm_region_add (listener=0x5555568330c0, section=0x7fffffffd310) at /root/git/qemu/kvm-all.c:859
#1  0x00005555557c1910 in address_space_update_topology_pass (as=0x55555629e240 <address_space_memory>, old_view=0x5555567a7090, new_view=0x5555568d3460, adding=true) at /root/git/qemu/memory.c:871
#2  0x00005555557c19f3 in address_space_update_topology (as=0x55555629e240 <address_space_memory>) at /root/git/qemu/memory.c:886
#3  0x00005555557c1b41 in memory_region_transaction_commit () at /root/git/qemu/memory.c:922
#4  0x00005555557c4bfd in memory_region_update_container_subregions (subregion=0x5555568d2fc0) at /root/git/qemu/memory.c:2075
#5  0x00005555557c4c64 in memory_region_add_subregion_common (mr=0x5555567a5830, offset=0, subregion=0x5555568d2fc0) at /root/git/qemu/memory.c:2085
#6  0x00005555557c4ca0 in memory_region_add_subregion (mr=0x5555567a5830, offset=0, subregion=0x5555568d2fc0) at /root/git/qemu/memory.c:2093
#7  0x000055555583fd68 in pc_memory_init (pcms=0x5555567a4100, system_memory=0x5555567a5830, rom_memory=0x5555568d21a0, ram_memory=0x7fffffffd550) at /root/git/qemu/hw/i386/pc.c:1383
#8  0x0000555555847363 in pc_q35_init (machine=0x5555567a4100) at /root/git/qemu/hw/i386/pc_q35.c:147
#9  0x0000555555847cac in pc_init_v2_9 (machine=0x5555567a4100) at /root/git/qemu/hw/i386/pc_q35.c:310
#10 0x00005555558f7cf8 in main (argc=11, argv=0x7fffffffda78, envp=0x7fffffffdad8) at /root/git/qemu/vl.c:4557

Hope this helps. Thanks.

-- 
Peter Xu

  reply	other threads:[~2017-04-17 10:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-17 10:09 [Qemu-devel] qemu memory manage question jack.chen
2017-04-17 10:26 ` Peter Xu [this message]
2017-04-17 10:55   ` jack.chen
2017-04-17 11:19     ` 李强
2017-04-18  2:25       ` jack.chen
2017-04-18 10:48         ` jack.chen
2017-04-17 11:19     ` Peter Xu

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=20170417102607.GE16703@pxdev.xzpeter.org \
    --to=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhunxun@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;
as well as URLs for NNTP newsgroup(s).