From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 09/20] memory: compress phys_map node pointers to 16 bits
Date: Tue, 14 Feb 2012 11:27:39 +0200 [thread overview]
Message-ID: <1329211670-11548-10-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1329211670-11548-1-git-send-email-avi@redhat.com>
Use an expanding vector to store nodes. Allocation is baroque to g_renew()
potentially invalidating pointers; this will be addressed later.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
exec.c | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/exec.c b/exec.c
index 957bc6d..0756919 100644
--- a/exec.c
+++ b/exec.c
@@ -201,13 +201,19 @@
struct PhysPageEntry {
union {
uint16_t leaf; /* index into phys_sections */
- PhysPageEntry *node;
+ uint16_t node; /* index into phys_map_nodes */
} u;
};
+/* Simple allocator for PhysPageEntry nodes */
+static PhysPageEntry (*phys_map_nodes)[L2_SIZE];
+static unsigned phys_map_nodes_nb, phys_map_nodes_nb_alloc;
+
+#define PHYS_MAP_NODE_NIL ((uint16_t)~0)
+
/* This is a multi-level map on the physical address space.
The bottom level has pointers to PhysPageDesc. */
-static PhysPageEntry phys_map;
+static PhysPageEntry phys_map = { .u.node = PHYS_MAP_NODE_NIL };
static void io_mem_init(void);
static void memory_map_init(void);
@@ -403,6 +409,32 @@ static inline PageDesc *page_find(tb_page_addr_t index)
}
#if !defined(CONFIG_USER_ONLY)
+
+static PhysPageEntry *phys_map_node_alloc(uint16_t *ptr)
+{
+ unsigned i;
+ uint16_t ret;
+
+ /* Assign early to avoid the pointer being invalidated by g_renew() */
+ *ptr = ret = phys_map_nodes_nb++;
+ assert(ret != PHYS_MAP_NODE_NIL);
+ if (ret == phys_map_nodes_nb_alloc) {
+ typedef PhysPageEntry Node[L2_SIZE];
+ phys_map_nodes_nb_alloc = MAX(phys_map_nodes_nb_alloc * 2, 16);
+ phys_map_nodes = g_renew(Node, phys_map_nodes,
+ phys_map_nodes_nb_alloc);
+ }
+ for (i = 0; i < L2_SIZE; ++i) {
+ phys_map_nodes[ret][i].u.node = PHYS_MAP_NODE_NIL;
+ }
+ return phys_map_nodes[ret];
+}
+
+static void phys_map_nodes_reset(void)
+{
+ phys_map_nodes_nb = 0;
+}
+
static uint16_t *phys_page_find_alloc(target_phys_addr_t index, int alloc)
{
PhysPageEntry *lp, *p;
@@ -412,18 +444,20 @@ static uint16_t *phys_page_find_alloc(target_phys_addr_t index, int alloc)
/* Level 1..N. */
for (i = P_L2_LEVELS - 1; i >= 0; i--) {
- if (lp->u.node == NULL) {
+ if (lp->u.node == PHYS_MAP_NODE_NIL) {
if (!alloc) {
return NULL;
}
- lp->u.node = p = g_malloc0(sizeof(PhysPageEntry) * L2_SIZE);
+ p = phys_map_node_alloc(&lp->u.node);
if (i == 0) {
for (j = 0; j < L2_SIZE; j++) {
p[j].u.leaf = phys_section_unassigned;
}
}
+ } else {
+ p = phys_map_nodes[lp->u.node];
}
- lp = &lp->u.node[(index >> (i * L2_BITS)) & (L2_SIZE - 1)];
+ lp = &p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)];
}
return &lp->u.leaf;
@@ -2538,12 +2572,13 @@ static void destroy_page_desc(uint16_t section_index)
static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level)
{
unsigned i;
- PhysPageEntry *p = lp->u.node;
+ PhysPageEntry *p;
- if (!p) {
+ if (lp->u.node == PHYS_MAP_NODE_NIL) {
return;
}
+ p = phys_map_nodes[lp->u.node];
for (i = 0; i < L2_SIZE; ++i) {
if (level > 0) {
destroy_l2_mapping(&p[i], level - 1);
@@ -2551,13 +2586,13 @@ static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level)
destroy_page_desc(p[i].u.leaf);
}
}
- g_free(p);
- lp->u.node = NULL;
+ lp->u.node = PHYS_MAP_NODE_NIL;
}
static void destroy_all_mappings(void)
{
destroy_l2_mapping(&phys_map, P_L2_LEVELS - 1);
+ phys_map_nodes_reset();
}
static uint16_t phys_section_add(MemoryRegionSection *section)
@@ -3543,6 +3578,7 @@ static void core_begin(MemoryListener *listener)
{
destroy_all_mappings();
phys_sections_clear();
+ phys_map.u.node = PHYS_MAP_NODE_NIL;
phys_section_unassigned = dummy_section(&io_mem_unassigned);
}
--
1.7.9
next prev parent reply other threads:[~2012-02-14 9:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 9:27 [Qemu-devel] [PATCH 00/20] Reduce storage overhead of memory core Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 01/20] memory: allow MemoryListeners to observe a specific address space Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 02/20] xen: ignore I/O memory regions Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 03/20] memory: split memory listener for the two address spaces Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 04/20] memory: support stateless memory listeners Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 05/20] memory: change memory registration to rebuild the memory map on each change Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 06/20] memory: remove first level of l1_phys_map Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 07/20] memory: unify phys_map last level with intermediate levels Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 08/20] memory: store MemoryRegionSection pointers in phys_map Avi Kivity
2012-03-07 17:49 ` Peter Maydell
2012-03-07 19:32 ` Peter Maydell
2012-03-08 9:50 ` Avi Kivity
2012-03-08 10:09 ` Peter Maydell
2012-03-08 11:11 ` Avi Kivity
2012-03-08 11:25 ` Peter Maydell
2012-02-14 9:27 ` Avi Kivity [this message]
2012-02-14 9:27 ` [Qemu-devel] [PATCH 10/20] memory: fix RAM subpages in newly initialized pages Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 11/20] memory: unify the two branches of cpu_register_physical_memory_log() Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 12/20] memory: move tlb flush to MemoryListener commit callback Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 13/20] memory: make phys_page_find() return a MemoryRegionSection Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 14/20] memory: give phys_page_find() its own tree search loop Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 15/20] memory: simplify multipage/subpage registration Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 16/20] memory: replace phys_page_find_alloc() with phys_page_set() Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 17/20] memory: switch phys_page_set() to a recursive implementation Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 18/20] memory: change phys_page_set() to set multiple pages Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 19/20] memory: unify PhysPageEntry::node and ::leaf Avi Kivity
2012-02-14 9:27 ` [Qemu-devel] [PATCH 20/20] memory: allow phys_map tree paths to terminate early Avi Kivity
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=1329211670-11548-10-git-send-email-avi@redhat.com \
--to=avi@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).