qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3] rcu: reduce more than 7MB heap memory by mal


From: Yang Zhong
Subject: Re: [Qemu-devel] [PATCH v3] rcu: reduce more than 7MB heap memory by malloc_trim()
Date: Fri, 8 Dec 2017 19:06:59 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Wed, Dec 06, 2017 at 10:48:45AM +0100, Paolo Bonzini wrote:
> On 06/12/2017 10:26, Yang Zhong wrote:
> >   Hello Paolo,
> > 
> >   The best option is only trim one time after guest kernel bootup or VM 
> > bootup, and as for
> >   hotplug/unhotplug operations during the VM running, the trim still can do 
> > for each batch
> >   memory free because trim will not impact VM performance during VM running 
> > status.
> > 
> >   So, the key point is qemu is hard to know when guest ernel bootup is 
> > over. If you have some 
> >   suggestions, please let me know. thanks!
> 
> It shouldn't be hard.  Does QEMU's RCU thread actually get any
> significant activity after bootup?  Hence the suggestion of keeping
> malloc_trim in the RCU thread, but only do it if some time has passed
> since the last time.
> 
> Maybe something like this every time the RCU thread runs:
> 
>  static uint64_t next_trim_time, last_trim_time;
>  if (current time < next_trim_time) {
>      next_trim_time -= last_trim_time / 2    /* or higher */
>      last_trim_time -= last_trim_time / 2    /* same as previous line */
>  } else {
>      trim_start_time = current time
>      malloc_trim(...)
>      last_trim_time = current time - trim_start_time
>      next_trim_time = current time + last_trim_time
>  }
> 
> Where the "2" factor should be tuned so that both your and Shannon's
> scenario work fine.
>
  Hello Paolo,

  As for your patch, i have commented on another mail.

  Please help check below TEMP patch.

  +++ b/util/rcu.c
  @@ -32,7 +32,7 @@
  #include "qemu/atomic.h"
  #include "qemu/thread.h"
  #include "qemu/main-loop.h"
 -
+#if defined(CONFIG_MALLOC_TRIM)
+#include <malloc.h>
+#endif
  /*
   * Global grace period counter.  Bit 0 is always one in rcu_gp_ctr.
   * Bits 1 and above are defined in synchronize_rcu.
  @@ -246,6 +246,7 @@ static void *call_rcu_thread(void *opaque)
                  qemu_event_reset(&rcu_call_ready_event);
                  n = atomic_read(&rcu_call_count);
                  if (n == 0) {
 +                    #if defined(CONFIG_MALLOC_TRIM)
 +                       malloc_trim(4 * 1024 * 1024);
 +                    #endif
                      qemu_event_wait(&rcu_call_ready_event);
                  }
              }

  If there is no rcu_call(), the n=0 and call_rcu_thread() will trim memory 
  and then enter sleep to wait for rcu_call() to wakeup this thread.

  Once the VM bootup, if there is not any activity like hotplug, rcu thread
  is always in sleep status.

  As for the VM bootup, if the n!=0, the rcu thread will not call trim.

  If use this method, the trim times will decrease to around 1/2 of previous. 

  Regards,

  Yang
 
> Thanks,
> 
> Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]