All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Bob Liu <lliubbo@gmail.com>
Cc: keir@xen.org, ian.campbell@citrix.com, jbeulich@suse.com,
	xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com
Subject: Re: [RFC PATCH] xen: free_domheap_pages: delay page scrub to tasklet
Date: Mon, 19 May 2014 10:59:08 +0100	[thread overview]
Message-ID: <5379D5EC.3040604@citrix.com> (raw)
In-Reply-To: <1400468276-8683-1-git-send-email-bob.liu@oracle.com>

On 19/05/14 03:57, Bob Liu wrote:
> Because of page scrub, it's very slow to destroy a domain with large
> memory.
> It took around 10 minutes when destroy a guest of nearly 1 TB of memory.
>
> [root@ca-test111 ~]# time xm des 5
> real    10m51.582s
> user    0m0.115s
> sys     0m0.039s
> [root@ca-test111 ~]#
>
> Use perf we can see what happened, thanks for Boris's help and provide this
> useful tool for xen.
> [root@x4-4 bob]# perf report
>     22.32%       xl  [xen.syms]            [k] page_get_owner_and_reference
>     20.82%       xl  [xen.syms]            [k] relinquish_memory
>     20.63%       xl  [xen.syms]            [k] put_page
>     17.10%       xl  [xen.syms]            [k] scrub_one_page
>      4.74%       xl  [xen.syms]            [k] unmap_domain_page
>      2.24%       xl  [xen.syms]            [k] get_page
>      1.49%       xl  [xen.syms]            [k] free_heap_pages
>      1.06%       xl  [xen.syms]            [k] _spin_lock
>      0.78%       xl  [xen.syms]            [k] __put_page_type
>      0.75%       xl  [xen.syms]            [k] map_domain_page
>      0.57%       xl  [xen.syms]            [k] free_page_type
>      0.52%       xl  [xen.syms]            [k] is_iomem_page
>      0.42%       xl  [xen.syms]            [k] free_domheap_pages
>      0.31%       xl  [xen.syms]            [k] put_page_from_l1e
>      0.27%       xl  [xen.syms]            [k] check_lock
>      0.27%       xl  [xen.syms]            [k] __mfn_valid
>
> This patch try to delay scrub_one_page() to a tasklet which will be scheduled on
> all online physical cpus, so that it's much faster to return from 'xl/xm
> destroy xxx'.
>
> Tested on a guest with 30G memory.
> Before this patch:
> [root@x4-4 bob]# time xl des PV-30G
>
> real 0m16.014s
> user 0m0.010s
> sys  0m13.976s
> [root@x4-4 bob]#
>
> After:
> [root@x4-4 bob]# time xl des PV-30G
>
> real 0m3.581s
> user 0m0.003s
> sys  0m1.554s
> [root@x4-4 bob]#
>
> The destroy time reduced from 16s to 3s.
>
> Signed-off-by: Bob Liu <bob.liu@oracle.com>
> ---
>  xen/common/page_alloc.c |   39 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> index 601319c..2ca59a1 100644
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -79,6 +79,10 @@ PAGE_LIST_HEAD(page_offlined_list);
>  /* Broken page list, protected by heap_lock. */
>  PAGE_LIST_HEAD(page_broken_list);
>  
> +PAGE_LIST_HEAD(page_scrub_list);
> +static DEFINE_SPINLOCK(scrub_list_spinlock);
> +static struct tasklet scrub_page_tasklet;
> +
>  /*************************
>   * BOOT-TIME ALLOCATOR
>   */
> @@ -1417,6 +1421,25 @@ void free_xenheap_pages(void *v, unsigned int order)
>  #endif
>  
>  
> +static void scrub_free_pages(unsigned long unuse)
> +{
> +    struct page_info *pg;
> +
> +    for ( ; ; )
> +    {

A tasklet function is expected to return.  I don't see how this works at
all...

> +        while ( page_list_empty(&page_scrub_list) )
> +            cpu_relax();
> +
> +        spin_lock(&scrub_list_spinlock);
> +        pg = page_list_remove_head(&page_scrub_list);
> +        spin_unlock(&scrub_list_spinlock);
> +        if (pg)
> +        {
> +            scrub_one_page(pg);
> +            free_heap_pages(pg, 0);
> +        }
> +    }
> +}
>  
>  /*************************
>   * DOMAIN-HEAP SUB-ALLOCATOR
> @@ -1425,6 +1448,7 @@ void free_xenheap_pages(void *v, unsigned int order)
>  void init_domheap_pages(paddr_t ps, paddr_t pe)
>  {
>      unsigned long smfn, emfn;
> +    unsigned int cpu;
>  
>      ASSERT(!in_irq());
>  
> @@ -1435,6 +1459,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe)
>          return;
>  
>      init_heap_pages(mfn_to_page(smfn), emfn - smfn);
> +    tasklet_init(&scrub_page_tasklet, scrub_free_pages, 0);
> +    for_each_online_cpu(cpu)
> +        tasklet_schedule_on_cpu(&scrub_page_tasklet, cpu);

So now you have an infinite loop doing nothing, running on all cpus in
tasklet context ?

>  }
>  
>  
> @@ -1564,8 +1591,17 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
>           * domain has died we assume responsibility for erasure.
>           */
>          if ( unlikely(d->is_dying) )
> +        {
> +            /*
> +             * Add page to page_scrub_list to speed up domain destroy, those
> +	     * pages will be zeroed later by scrub_page_tasklet.
> +             */

Spaces/tabs

~Andrew

> +            spin_lock(&scrub_list_spinlock);
>              for ( i = 0; i < (1 << order); i++ )
> -                scrub_one_page(&pg[i]);
> +                page_list_add_tail(&pg[i], &page_scrub_list);
> +            spin_unlock(&scrub_list_spinlock);
> +            goto out;
> +        }
>  
>          free_heap_pages(pg, order);
>      }
> @@ -1583,6 +1619,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
>          drop_dom_ref = 0;
>      }
>  
> +out:
>      if ( drop_dom_ref )
>          put_domain(d);
>  }

  reply	other threads:[~2014-05-19  9:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19  2:57 [RFC PATCH] xen: free_domheap_pages: delay page scrub to tasklet Bob Liu
2014-05-19  9:59 ` Andrew Cooper [this message]
2014-05-19 10:10 ` Konrad Rzeszutek Wilk
2014-05-19 11:34 ` Jan Beulich
2014-05-20  2:14   ` Bob Liu
2014-05-20  6:27     ` Jan Beulich
2014-05-20  7:11       ` Bob Liu
2014-05-20  7:26         ` Jan Beulich
2014-05-20  8:14           ` Bob Liu

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=5379D5EC.3040604@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=lliubbo@gmail.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.