Skip to content

Commit

Permalink
memory: optimize empty transactions due to mutators
Browse files Browse the repository at this point in the history
The mutating memory APIs can easily cause empty transactions,
where the mutators don't actually change anything, or perhaps
only modify disabled regions.  Detect these conditions and
avoid regenerating the memory topology.

Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
avikivity committed Dec 5, 2011
1 parent 4703359 commit e87c099
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <assert.h>

unsigned memory_region_transaction_depth = 0;
static bool memory_region_update_pending = false;

typedef struct AddrRange AddrRange;

Expand Down Expand Up @@ -757,6 +758,7 @@ static void address_space_update_topology(AddressSpace *as)
static void memory_region_update_topology(MemoryRegion *mr)
{
if (memory_region_transaction_depth) {
memory_region_update_pending |= !mr || mr->enabled;
return;
}

Expand All @@ -770,6 +772,8 @@ static void memory_region_update_topology(MemoryRegion *mr)
if (address_space_io.root) {
address_space_update_topology(&address_space_io);
}

memory_region_update_pending = false;
}

void memory_region_transaction_begin(void)
Expand All @@ -781,7 +785,9 @@ void memory_region_transaction_commit(void)
{
assert(memory_region_transaction_depth);
--memory_region_transaction_depth;
memory_region_update_topology(NULL);
if (!memory_region_transaction_depth && memory_region_update_pending) {
memory_region_update_topology(NULL);
}
}

static void memory_region_destructor_none(MemoryRegion *mr)
Expand Down

0 comments on commit e87c099

Please sign in to comment.