Skip to content

Commit

Permalink
memory: avoid ref/unref in memory_region_find
Browse files Browse the repository at this point in the history
Do the entire lookup under RCU, which avoids atomic operations
in flatview_ref and flatview_unref.

Reviewed-by: Fam Zheng <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Feb 2, 2015
1 parent 374f298 commit 2b64766
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,11 +1828,11 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
}
range = addrrange_make(int128_make64(addr), int128_make64(size));

view = address_space_get_flatview(as);
rcu_read_lock();
view = atomic_rcu_read(&as->current_map);
fr = flatview_lookup(view, range);
if (!fr) {
flatview_unref(view);
return ret;
goto out;
}

while (fr > view->ranges && addrrange_intersects(fr[-1].addr, range)) {
Expand All @@ -1849,8 +1849,8 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
ret.offset_within_address_space = int128_get64(range.start);
ret.readonly = fr->readonly;
memory_region_ref(ret.mr);

flatview_unref(view);
out:
rcu_read_unlock();
return ret;
}

Expand Down

0 comments on commit 2b64766

Please sign in to comment.