qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [Qemu-devel] [PATCH] memory: reduce heap Rss size around 3M
  2017-03-08 15:11 [Qemu-devel] [PATCH] memory: reduce heap Rss size around 3M Yang Zhong
@ 2017-03-08 11:17 ` Philippe Mathieu-Daudé
  2017-03-09 16:34   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-08 11:17 UTC (permalink / raw)
  To: Yang Zhong, qemu-devel; +Cc: pbonzini, anthony.xu

On 03/08/2017 12:11 PM, Yang Zhong wrote:
> 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 <yang.zhong@intel.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  memory.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/memory.c b/memory.c
> index 284894b..799ca4c 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2422,8 +2422,10 @@ 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) {
> -            as->ref_count++;
> +        if (root == as->root) {
> +            if (as->malloced) {
> +                as->ref_count++;
> +            }
>              return as;
>          }
>      }
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH] memory: reduce heap Rss size around 3M
@ 2017-03-08 15:11 Yang Zhong
  2017-03-08 11:17 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Zhong @ 2017-03-08 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, anthony.xu, 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 <yang.zhong@intel.com>
---
 memory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index 284894b..799ca4c 100644
--- a/memory.c
+++ b/memory.c
@@ -2422,8 +2422,10 @@ 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) {
-            as->ref_count++;
+        if (root == as->root) {
+            if (as->malloced) {
+                as->ref_count++;
+            }
             return as;
         }
     }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] memory: reduce heap Rss size around 3M
  2017-03-08 11:17 ` Philippe Mathieu-Daudé
@ 2017-03-09 16:34   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2017-03-09 16:34 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Yang Zhong, qemu-devel; +Cc: anthony.xu



On 08/03/2017 12:17, Philippe Mathieu-Daudé wrote:
> On 03/08/2017 12:11 PM, Yang Zhong wrote:
>> 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 <yang.zhong@intel.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
>> ---
>>  memory.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/memory.c b/memory.c
>> index 284894b..799ca4c 100644
>> --- a/memory.c
>> +++ b/memory.c
>> @@ -2422,8 +2422,10 @@ 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) {
>> -            as->ref_count++;
>> +        if (root == as->root) {
>> +            if (as->malloced) {
>> +                as->ref_count++;
>> +            }
>>              return as;
>>          }
>>      }
>>

This is wrong.  If as->malloced is false, the AddressSpace might be
embedded in another struct.  This other struct could be freed when
as->ref_count is still greater than 0, causing a use-after-free bug.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-09 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-08 15:11 [Qemu-devel] [PATCH] memory: reduce heap Rss size around 3M Yang Zhong
2017-03-08 11:17 ` Philippe Mathieu-Daudé
2017-03-09 16:34   ` Paolo Bonzini

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).