Skip to contentSkip to conversation

alloc_heap_pages is low efficient with more CPUs

DISCUSSION tupeng212 4 participants 7 messages Oct 11, 2012 – Oct 13, 2012

lore
Share & tools
lore

tupeng212

author
#0 lore raw

I am confused with a problem:
I have a blade with 64 physical CPUs and 64G physical RAM, and defined only one VM with 1 CPU and 40G RAM. For the first time I started the VM, it just took 3s, But for the second starting it took 30s. After studied it by printing log, I have located a place in the hypervisor where cost too much time, occupied 98% of the whole starting time.

xen/common/page_alloc.c
/* Allocate 2^@order contiguous pages. */
static struct page_info *alloc_heap_pages(
unsigned int zone_lo, unsigned int zone_hi, unsigned int node, unsigned int order, unsigned int memflags)

{
        if ( pg[i].u.free.need_tlbflush )
        {
            /* Add in extra CPUs that need flushing because of this page. */
            cpus_andnot(extra_cpus_mask, cpu_online_map, mask);
            tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);
            cpus_or(mask, mask, extra_cpus_mask);
        }

}

1 in the first starting, most of need_tlbflush=NULL, so cost little; in the second one, most of RAM have been used
thus makes need_tlbflush=true, so cost much.

2 but I repeated the same experiment in another blade which contains 16 physical CPUs and 64G physical RAM, the second
starting cost 3s. After I traced the process between the two second startings, found that count entering into the judgement of pg[i].u.free.need_tlbflush is the same, but number of CPUs leads to the difference.

3 The code I pasted aims to compute a mask to determine whether it should flush CPU's TLB. I traced the values in starting period below:

cpus_andnot(extra_cpus_mask, cpu_online_map, mask);
//after, mask=0, cpu_online_map=0xFFFFFFFFFFFFFFFF, extra_cpus_mask=0xFFFFFFFFFFFFFFFF tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);
//after, mask=0, extra_cpus_mask=0
cpus_or(mask, mask, extra_cpus_mask);
//after, mask=0, extra_cpus_mask=0

every time it starts with mask=0, and ends with the same result mask=0, so leads to flush CPU's TLB definitely, which seems meaningless in the staring process.

4 The problem is, this seemed meaningless code is very time-consuming, CPUs get more, time costs more, it takes 30s here in my blade
with 64 CPUs which may need some solution to improve the efficiency.

tupeng

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw

Not sure I understand. With 16 CPUs you find domain startup takes 3s always. With 64 CPUs you find it takes 3s first time, then 30s in future? And this is due to cost of tlbflush_filter() (not actual TLB flushes, because you always end up with mask=0)? If tlbflush_filter() were that expensive I¹d expect the 16-CPU case to have slowdown after the first domain startup, too.

-- Keir

Quoted 62 lines · On 11/10/2012 16:18, "tupeng212" <[email protected]> wrote:

I am confused with a problem:
I have a blade with 64 physical CPUs and 64G physical RAM, and defined only one VM with 1 CPU and 40G RAM.
For the first time I started the VM, it just took 3s, But for the second starting it took 30s.
After studied it by printing log, I have located a place in the hypervisor where cost too much time,
occupied 98% of the whole starting time.

xen/common/page_alloc.c
/* Allocate 2^@order contiguous pages. */
static struct page_info *alloc_heap_pages(
unsigned int zone_lo, unsigned int zone_hi, unsigned int node, unsigned int order, unsigned int memflags)

{
        if ( pg[i].u.free.need_tlbflush )
        {
            /* Add in extra CPUs that need flushing because of this page. */
            cpus_andnot(extra_cpus_mask, cpu_online_map, mask);
            tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);
            cpus_or(mask, mask, extra_cpus_mask);
        }

}

1 in the first starting, most of need_tlbflush=NULL, so cost little; in the second one, most of RAM have been used
thus makes need_tlbflush=true, so cost much.

2 but I repeated the same experiment in another blade which contains 16 physical CPUs and 64G physical RAM, the second
starting cost 3s. After I traced the process between the two second
startings, found that count entering into the judgement of
pg[i].u.free.need_tlbflush is the same, but number of CPUs leads to the
difference.

3 The code I pasted aims to compute a mask to determine whether it should flush CPU's TLB. I traced the values in starting period below:

Quoted 6 lines

cpus_andnot(extra_cpus_mask, cpu_online_map, mask);

//after, mask=0, cpu_online_map=0xFFFFFFFFFFFFFFFF, extra_cpus_mask=0xFFFFFFFFFFFFFFFF

Quoted 7 lines

tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);

//after, mask=0, extra_cpus_mask=0

cpus_or(mask, mask, extra_cpus_mask);

//after, mask=0, extra_cpus_mask=0

every time it starts with mask=0, and ends with the same result mask=0, so
leads to flush CPU's TLB definitely,
which seems meaningless in the staring process.

4 The problem is, this seemed meaningless code is very time-consuming, CPUs get more, time costs more, it takes 30s here in my blade
with 64 CPUs which may need some solution to improve the efficiency.

Quoted 7 lines

tupeng

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#2 lore raw

With 16 CPUs you find domain startup takes 3s always. :No
With 16CPUs, first 0.3s, second 3s
With 64CPUs, first 3s, second 30s.

With 64 CPUs you find it takes 3s first time, then 30s in future? : Yes

And this is due to cost of tlbflush_filter() (not actual TLB flushes, because you always end up with mask=0)? : Yes, it costs much in tlbflush_filter() in the judgement.
TLB flushing is really very fast, it just sends a IPI to related CPU.
In the starting process's allocation, it always ends up with mask=0 which seems needless.

If tlbflush_filter() were that expensive I’d expect the 16-CPU case to have slowdown after the first domain startup, too. : Yes, you are right, 16CPU slows down too after its first startup.

The reason is very clear, I have discussed it with others, tlbflush_filter() is low efficient is no doubt, But I don't know how to improve it .

and I also used xen oprofile to find the following two functions are called high frequently:
alloc_heap_pages: 40%
__next_cpu : 20%
others: 0.x%
.....
alloc_heap_pages -> tlbflush_filter -> for_each_cpu_mask next_cpu -> __next_cpu it seems traveling among CPUs is expensive.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 7 lines · On Fri, 12 Oct 2012 20:24:16 +0800 tupeng212 <[email protected]> wrote:

With 16 CPUs you find domain startup takes 3s always. :No
With 16CPUs, first 0.3s, second 3s
With 64CPUs, first 3s, second 30s.

With 64 CPUs you find it takes 3s first time, then 30s in future? : Yes

...........

I had seen this a while ago, it was always page scrubbing. That algoright was changed IIRC, so not sure if still could be the cause.

My 2 cents,
thanks
Mukesh

#4 lore raw
Quoted 8 lines · Mukesh Rathor
Quoted 5 lines · On Fri, 12 Oct 2012 20:24:16 +0800 tupeng212 <[email protected]> wrote:

With 16 CPUs you find domain startup takes 3s always. :No
With 16CPUs, first 0.3s, second 3s
With 64CPUs, first 3s, second 30s.

Quoted 7 lines
Quoted 2 lines

With 64 CPUs you find it takes 3s first time, then 30s in future? : Yes

...........

I had seen this a while ago, it was always page scrubbing. That algoright was changed IIRC, so not sure if still could be the cause.

Tupeng,

If the tlbflush_filter() and cpumask_or() lines are commented out from the if(need_tlbflush) block in alloc_heap_pages(), what are the domain creation times like then? By the way it looks like you are not using xen-unstable or xen-4.2, can you try with one of these later versions of Xen?

-- Keir

Quoted 3 lines

My 2 cents,
thanks
Mukesh

author
#5 lore raw

/* Allocate 2^@order contiguous pages. */
static struct page_info *alloc_heap_pages(
unsigned int zone_lo, unsigned int zone_hi, unsigned int node, unsigned int order, unsigned int memflags)

{
    cpus_clear(mask);
    for ( i = 0; i < (1 << order); i++ )
    {    
        if ( pg[i].u.free.need_tlbflush )
        {
            /* Add in extra CPUs that need flushing because of this page. */
            cpus_andnot(extra_cpus_mask, cpu_online_map, mask);
            tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);
            cpus_or(mask, mask, extra_cpus_mask);
        }
    }
    if ( unlikely(!cpus_empty(mask)) )
    {
        perfc_incr(need_flush_tlb_flush);
        flush_tlb_mask(&mask);
    }
    return pg;
}

Is this equal to : in pg[1<<order-1].u.free.need_tlbflush, if we compute mask=0, then flush TLB mask ?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw
Quoted 24 lines · On 13/10/2012 08:20, "tupeng212" <[email protected]> wrote:

/* Allocate 2^@order contiguous pages. */
static struct page_info *alloc_heap_pages(
unsigned int zone_lo, unsigned int zone_hi, unsigned int node, unsigned int order, unsigned int memflags)

{
    cpus_clear(mask);
    for ( i = 0; i < (1 << order); i++ )
    {    
        if ( pg[i].u.free.need_tlbflush )
        {
            /* Add in extra CPUs that need flushing because of this page. */
            cpus_andnot(extra_cpus_mask, cpu_online_map, mask);
            tlbflush_filter(extra_cpus_mask, pg[i].tlbflush_timestamp);
            cpus_or(mask, mask, extra_cpus_mask);
        }
    }
    if ( unlikely(!cpus_empty(mask)) )
    {
        perfc_incr(need_flush_tlb_flush);
        flush_tlb_mask(&mask);
    }
    return pg;
}
Quoted 2 lines

Is this equal to : in pg[1<<order-1].u.free.need_tlbflush, if we compute mask=0, then flush TLB mask ?

No!

-- Keir