memory: reduce heap Rss size around 3M
PATCH v3 1/1 memory: reduce heap Rss size around 3M
Since cpu-memory and memory have same address space,one malloced memory is enough. This patch will skip memory malloc for memory address space,which will reduce around 3M physical memory in heap.
--- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
memory.c +1 -1
@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && as == &address_space_memory) { as->ref_count++;return as; }
Signature · 1 line
1.9.1
Quoted 14 lines · Yang Zhong
Since cpu-memory and memory have same address space,one malloced memory is enough. This patch will skip memory malloc for memory address space,which will reduce around 3M physical memory in heap.
Signed-off-by Yang Zhong <[email protected]>--- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)memory.c +0
-0
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2425
Quoted 5 lines
memory.c +1
-1@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && as == &address_space_memory) {
Of course you need to keep the as->malloced check, don't you?
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2428
Quoted 4 lines
memory.c +0
-0as->ref_count++;return as; }
This is not really beautiful, but compared to v1 and v2 it has the advantage that it works (with the as->malloced check reintroduced). Peter, you introduced address_space_init_shareable, what do you think?
Paolo
Hello Paolo&peter,
Maybe below patch is much more better, I also did the verification. Please all of you give some comments, many thanks!
memory.c +1 -1
@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && (as->malloced || as == &address_space_memory)) { as->ref_count++;return as; }
Regards,
ZhongYang
-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]]
Sent: Wednesday, March 15, 2017 4:13 PM
To: Zhong, Yang <[email protected]>; [email protected]
Cc: Xu, Anthony <[email protected]>; Peter Maydell <[email protected]>
Subject: Re: [PATCH v3] memory: reduce heap Rss size around 3M
Quoted 14 lines · Yang Zhong
Since cpu-memory and memory have same address space,one malloced memory is enough. This patch will skip memory malloc for memory address space,which will reduce around 3M physical memory in heap.
Signed-off-by Yang Zhong <[email protected]>--- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)memory.c +0
-0
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2425
Quoted 5 lines
memory.c +1
-1@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && as == &address_space_memory) {
Of course you need to keep the as->malloced check, don't you?
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2428
Quoted 4 lines
memory.c +0
-0as->ref_count++;return as; }
This is not really beautiful, but compared to v1 and v2 it has the advantage that it works (with the as->malloced check reintroduced). Peter, you introduced address_space_init_shareable, what do you think?
Paolo
Quoted 25 lines · Paolo Bonzini
Quoted 14 lines · Yang Zhong
Since cpu-memory and memory have same address space,one malloced memory is enough. This patch will skip memory malloc for memory address space,which will reduce around 3M physical memory in heap.
Signed-off-by Yang Zhong <[email protected]>--- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)memory.c +0
-0memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2425
Quoted 5 lines
memory.c +1
-1@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && as == &address_space_memory) {Of course you need to keep the
as->mallocedcheck, don't you?
Quoted 8 lines
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2428
Quoted 4 lines
memory.c +0
-0as->ref_count++;return as; }This is not really beautiful, but compared to v1 and v2 it has the advantage that it works (with the
as->mallocedcheck reintroduced). Peter, you introducedaddress_space_init_shareable, what do you think?
It looks wrong to me. address_space_memory is not allocated via address_space_init_shareable(), so it's not correct to treat it that way (we're implicitly relying on it never being destroyed). It works by accident, not by design.
If we want to support sharing of address spaces which are constant and exist for the lifetime of QEMU then we should probably do it with a new function something like
address_space_init_static_shareable()
which marks the AS as being (1) shareable and (2) invalid to ever try to destroy. Then you could use that for both address_space_memory and address_space_io.
thanks
-- PMM
Hello Peter,
The cpu-memory and memory have same address space through info mtree tool.
address-space: memory
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-000000007fffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-000000007fffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000c0000-00000000000dffff (prio 1, ram): pc.rom
00000000000e0000-00000000000fffff (prio 1, i/o): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.biosaddress-space: cpu-memory
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-000000007fffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-000000007fffffff
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000c0000-00000000000dffff (prio 1, ram): pc.rom
00000000000e0000-00000000000fffff (prio 1, i/o): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.biosSo we can omit the cpu-memory address space allocated in the address_space_init_shareable(), which will same around 3M physical memory.
Maybe the below patch is much better, please help review, thanks!
memory.c +1 -1
@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && (as->malloced || as == &address_space_memory)) { as->ref_count++;return as; }
Regards,
ZhongYang
memory.c +1 -1
@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && (as->malloced || as == &address_space_memory)) { as->ref_count++;return as; }
-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Wednesday, March 15, 2017 6:42 PM
To: Paolo Bonzini <[email protected]>
Cc: Zhong, Yang <[email protected]>; QEMU Developers <[email protected]>; Xu, Anthony <[email protected]>
Subject: Re: [PATCH v3] memory: reduce heap Rss size around 3M
Quoted 25 lines · Paolo Bonzini
Quoted 14 lines · Yang Zhong
Since cpu-memory and memory have same address space,one malloced memory is enough. This patch will skip memory malloc for memory address space,which will reduce around 3M physical memory in heap.
Signed-off-by Yang Zhong <[email protected]>--- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)memory.c +0
-0memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2425
Quoted 5 lines
memory.c +1
-1@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && as == &address_space_memory) {Of course you need to keep the
as->mallocedcheck, don't you?
Quoted 8 lines
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2428
Quoted 4 lines
memory.c +0
-0as->ref_count++;return as; }This is not really beautiful, but compared to v1 and v2 it has the advantage that it works (with the
as->mallocedcheck reintroduced). Peter, you introducedaddress_space_init_shareable, what do you think?
It looks wrong to me. address_space_memory is not allocated via address_space_init_shareable(), so it's not correct to treat it that way (we're implicitly relying on it never being destroyed). It works by accident, not by design.
If we want to support sharing of address spaces which are constant and exist for the lifetime of QEMU then we should probably do it with a new function something like
address_space_init_static_shareable()
which marks the AS as being (1) shareable and (2) invalid to ever try to destroy. Then you could use that for both address_space_memory and address_space_io.
thanks
-- PMM
Quoted 1 line · Yang
So we can omit the cpu-memory address space allocated in the
address_space_init_shareable(), which will same around 3M physical memory.
I see what you want to do...
Quoted 7 lines
Maybe the below patch is much better, please help review, thanks!
memory.c +0
-0
memory.c AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) · line 2428
Quoted 8 lines
memory.c +1
-1@@ -2422,7 +2422,7 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)AddressSpace *as; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { +if (root == as->root && (as->malloced || as == &address_space_memory)) { as->ref_count++;return as; }
...but all the stuff I said below applies to this patch.
Quoted 5 lines
It looks wrong to me.
address_space_memoryis not allocated viaaddress_space_init_shareable(), so it's not correct to treat it that way (we're implicitly relying on it never being destroyed). It works by accident, not by design.If we want to support sharing of address spaces which are constant and exist for the lifetime of QEMU then we should probably do it with a new function something like
address_space_init_static_shareable()
which marks the AS as being (1) shareable and (2) invalid to ever try to destroy. Then you could use that for bothaddress_space_memoryandaddress_space_io.
We should not be special casing address_space_memory here:
if you want a mechanism for allowing static "exists for lifetime of QEMU" address spaces to be included in the set which can be shared, then you need to create one.
thanks
-- PMM