From: Paolo Bonzini <pbonzini@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH qemu v2 11/13] memory: Share FlatView's and dispatch trees between address spaces
Date: Fri, 15 Sep 2017 11:25:59 +0200 [thread overview]
Message-ID: <165a7fa9-6ebb-3e95-2d95-7df2f550f1de@redhat.com> (raw)
In-Reply-To: <20170915084030.40988-12-aik@ozlabs.ru>
On 15/09/2017 10:40, Alexey Kardashevskiy wrote:
> +
> +static bool flatview_can_share(FlatView *old_view, FlatView *new_view)
> +{
> + MemoryRegion *old_root = memory_region_unalias_entire(old_view->root);
> + MemoryRegion *new_root = memory_region_unalias_entire(new_view->root);
> +
> + if (old_root == new_root) {
> + return true;
> + }
> +
> + if (!old_root->enabled && !new_root->enabled) {
> + return true;
> + }
> +
> + return false;
> +}
> +
I think you can improve this by keeping the root in the address space
(removing the previous patch). Instead, the FlatView's root can be the
one with resolved aliases. Then old_root is just old_view->root, and if
an empty FlatView has a NULL root this just becomes
the_other_view->root == memory_region_unalias_entire(as->root);
>
> +
> + /* Build list of unique FlatViews, FV::root is the key */
> + QTAILQ_FOREACH(old_view, &flat_views, flat_views_link) {
> + found = false;
> + QTAILQ_FOREACH(new_view, &fvs_tmp, flat_views_link) {
> + if (flatview_can_share(old_view, new_view)) {
> + found = true;
> + break;
> + }
> + }
> + if (found) {
> + continue;
> + }
> +
> + new_view = generate_memory_topology(old_view->root);
> + flatview_render_new(old_view, new_view);
> + QTAILQ_INSERT_TAIL(&fvs_tmp, new_view, flat_views_link);
> + }
I don't understand the algorithm here. Why is it visiting &flat_views
rather than the list of address spaces? I would have thought it enough
to do
for each address space
if there is a (new) flat view that we can share
add a reference
else
render a new flat view and add it to fvs_tmp
flat_views = fvs_tmp;
for each address space
old_view = address_space_to_flatview(as);
find the new flat view to use in fvs_tmp
address_space_update_topology_pass(..., false);
address_space_update_topology_pass(..., true);
QTAILQ_REMOVE(&old_view->address_spaces, ...);
atomic_rcu_set(&as->current_map, new_view);
flatview_unref(old_view);
QTAILQ_INSERT_TAIL(&new_view->address_spaces, ...);
It's also not clear to me what you need the FlatView's address_spaces
list for. (It's probably something trivial that I'm missing, or maybe
it goes away with the previous change).
>
> AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)
> {
> AddressSpace *as;
>
> - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> - if (root == address_space_root(as) && as->malloced) {
> - as->ref_count++;
> - return as;
> - }
> - }
> -
> as = g_malloc0(sizeof *as);
> address_space_init(as, root, name);
> - as->malloced = true;
> +
> return as;
> }
>
This belongs in the next patch; leaving as->malloced in
do_address_space_destroy and the reference count in
address_space_destroy is not a big complication.
Paolo
next prev parent reply other threads:[~2017-09-15 9:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-15 8:40 [Qemu-devel] [PATCH qemu v2 00/13] memory: Reduce memory use Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 01/13] memory: Postpone flatview and dispatch tree building till all devices are added Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 02/13] exec: Explicitely export target AS from address_space_translate_internal Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 03/13] memory: Open code FlatView rendering Alexey Kardashevskiy
2017-09-15 8:59 ` Paolo Bonzini
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 04/13] memory: Move FlatView allocation to a helper Alexey Kardashevskiy
2017-09-15 9:02 ` Paolo Bonzini
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 05/13] memory: Move AddressSpaceDispatch from AddressSpace to FlatView Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 06/13] memory: Remove AddressSpace pointer from AddressSpaceDispatch Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 07/13] memory: Switch memory from using AddressSpace to FlatView Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 08/13] memory: Cleanup after switching " Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 09/13] memory: Rename mem_begin/mem_commit/mem_add helpers Alexey Kardashevskiy
2017-09-15 9:10 ` Paolo Bonzini
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 10/13] memory: Move root MR from AddressSpace to FlatView Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 11/13] memory: Share FlatView's and dispatch trees between address spaces Alexey Kardashevskiy
2017-09-15 9:25 ` Paolo Bonzini [this message]
2017-09-16 0:58 ` Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 12/13] memory: Get rid of address_space_init_shareable Alexey Kardashevskiy
2017-09-15 8:40 ` [Qemu-devel] [PATCH qemu v2 13/13] memory: Add flat views to HMP "info mtree" Alexey Kardashevskiy
2017-09-15 9:39 ` [Qemu-devel] [PATCH qemu v2 00/13] memory: Reduce memory use no-reply
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=165a7fa9-6ebb-3e95-2d95-7df2f550f1de@redhat.com \
--to=pbonzini@redhat.com \
--cc=aik@ozlabs.ru \
--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).