提交 3d8e6bf9 编写于 作者: A Avi Kivity 提交者: Anthony Liguori

memory: merge adjacent segments of a single memory region

Simple implementations of memory routers, for example the Cirrus VGA memory banks
or the 440FX PAM registers can generate adjacent memory regions which are contiguous.
Detect these and merge them; this saves kvm memory slots and shortens lookup times.
Signed-off-by: NAvi Kivity <avi@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 5a583347
......@@ -122,6 +122,34 @@ static void flatview_destroy(FlatView *view)
qemu_free(view->ranges);
}
static bool can_merge(FlatRange *r1, FlatRange *r2)
{
return addrrange_end(r1->addr) == r2->addr.start
&& r1->mr == r2->mr
&& r1->offset_in_region + r1->addr.size == r2->offset_in_region
&& r1->dirty_log_mask == r2->dirty_log_mask;
}
/* Attempt to simplify a view by merging ajacent ranges */
static void flatview_simplify(FlatView *view)
{
unsigned i, j;
i = 0;
while (i < view->nr) {
j = i + 1;
while (j < view->nr
&& can_merge(&view->ranges[j-1], &view->ranges[j])) {
view->ranges[i].addr.size += view->ranges[j].addr.size;
++j;
}
++i;
memmove(&view->ranges[i], &view->ranges[j],
(view->nr - j) * sizeof(view->ranges[j]));
view->nr -= j - i;
}
}
/* Render a memory region into the global view. Ranges in @view obscure
* ranges in @mr.
*/
......@@ -209,6 +237,7 @@ static FlatView generate_memory_topology(MemoryRegion *mr)
flatview_init(&view);
render_memory_region(&view, mr, 0, addrrange_make(0, UINT64_MAX));
flatview_simplify(&view);
return view;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册