From: Paolo Bonzini <pbonzini@redhat.com>
To: "Xu, Anthony" <anthony.xu@intel.com>,
Igor Mammedov <imammedo@redhat.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] Memory: use memory address space for cpu-memory
Date: Thu, 18 May 2017 23:38:40 +0200 [thread overview]
Message-ID: <6eff688c-b62e-8796-f852-a855079f3175@redhat.com> (raw)
In-Reply-To: <4712D8F4B26E034E80552F30A67BE0B1ACB970@ORSMSX112.amr.corp.intel.com>
On 17/05/2017 19:01, Xu, Anthony wrote:
>>> - AddressSpace *as = address_space_init_shareable(cpu->memory,
>>> - "cpu-memory");
>>> + AddressSpace *as;
>>> + if (cpu->memory == address_space_memory.root) {
>>> + address_space_memory.ref_count++;
>> probably this would cause reference leak when vcpu is destroyed
> I thought address_space_destroy is called when vcpu is unplugged,
> seems that's not the case, then ref_count++ is not needed.
It should be called. Alternatively you could try adding a new function
to mark address_space_memory as a never-destroyed AddressSpace:
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 99e0f54d86..b27b288c8f 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -290,6 +290,7 @@ struct AddressSpace {
MemoryRegion *root;
int ref_count;
bool malloced;
+ bool shared;
/* Accessed via RCU. */
struct FlatView *current_map;
diff --git a/memory.c b/memory.c
index b727f5ec0e..190cd3d5ce 100644
--- a/memory.c
+++ b/memory.c
@@ -2432,6 +2432,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
as->ref_count = 1;
as->root = root;
as->malloced = false;
+ as->shared = false;
as->current_map = g_new(FlatView, 1);
flatview_init(as->current_map);
as->ioeventfd_nb = 0;
@@ -2460,12 +2461,18 @@ static void do_address_space_destroy(AddressSpace *as)
}
}
+void address_space_init_static(AddressSpace *as, MemoryRegion *root, const char *name)
+{
+ address_space_init(as, root, name);
+ as->shared = true;
+}
+
AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)
{
AddressSpace *as;
QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
- if (root == as->root && as->malloced) {
+ if (root == as->root && as->shared) {
as->ref_count++;
return as;
}
@@ -2474,6 +2481,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)
as = g_malloc0(sizeof *as);
address_space_init(as, root, name);
as->malloced = true;
+ as->shared = true;
return as;
}
@@ -2485,6 +2493,8 @@ void address_space_destroy(AddressSpace *as)
if (as->ref_count) {
return;
}
+ assert(!as->shared || as->malloced);
+
/* Flush out anything from MemoryListeners listening in on this */
memory_region_transaction_begin();
as->root = NULL;
then CPUs can keep using address_space_init_shareable.
Paolo
next prev parent reply other threads:[~2017-05-18 21:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 22:15 [Qemu-devel] [PATCH] Memory: use memory address space for cpu-memory Anthony Xu
2017-05-17 9:27 ` Igor Mammedov
2017-05-17 17:01 ` Xu, Anthony
2017-05-18 21:38 ` Paolo Bonzini [this message]
2017-05-18 21:48 ` Xu, Anthony
2017-05-18 21:49 ` Paolo Bonzini
2017-05-18 23:28 ` Xu, Anthony
2017-05-19 9:30 ` Paolo Bonzini
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=6eff688c-b62e-8796-f852-a855079f3175@redhat.com \
--to=pbonzini@redhat.com \
--cc=anthony.xu@intel.com \
--cc=imammedo@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).