Skip to contentSkip to conversation

alloc_heap_pages is low efficient with more CPUs

DISCUSSION Applied tupeng212 4 participants 8 messages Oct 13, 2012 – Oct 16, 2012 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CC9EC91B.41A16%[email protected]

tupeng212

author
#1 lore raw

What if you replace tlbflush_filter() call with cpus_clear(&extra_cpus_mask)?
: you mean just clear it, maybe a little violent.., you 'd like to do it at any other place.

I assume you see lots of looping in one of those two functions, but only single-page-at-a-time calls into alloc_domheap_pages()->alloc_heap_pages()? : In populate_physmap, all pages are 2M size,
static void populate_physmap(struct memop_args *a)

{
    for ( i = a->nr_done; i < a->nr_extents; i++ )
    {

page = alloc_domheap_pages(d, a->extent_order, a->memflags) ->alloc_heap_pages ; //a->extent_order = 9, always 2M size }
//you mean move that block and TLB-flush here to avoid for loop ?
}

tupeng212

From: Keir Fraser
Date: 2012-10-13 14:30
To: tupeng212
Subject: Re: [Xen-devel] alloc_heap_pages is low efficient with more CPUs
What if you replace tlbflush_filter() call with cpus_clear(&extra_cpus_mask)? Seems a bit silly to do, but I’d like to know how much a few cpumask operations per page is costing (most are of course much quicker than tlbflush_filter as they operate on 64 bits per iteration, rather than one bit per iteration).

If that is suitably fast, I think we can have a go at fixing this by pulling the TLB-flush logic out of alloc_heap_pages() and into the loops in increwase_reservation() and populate_physmap() in common/memory.c. I assume you see lots of looping in one of those two functions, but only single-page-at-a-time calls into alloc_domheap_pages()->alloc_heap_pages()?

-- Keir

On 13/10/2012 07:21, "tupeng212" <[email protected]> wrote:

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?
: You mean removing these code from alloc_heap_pages, then try it.
I didn't do it as you said, but I calculated the whole time of if(need_tlbflush) block by using time1=NOW() ...block ... time2=NOW(), time=time2-time1, its unit is ns, and s = ns * 10^9 it occupy high rate of the whole time. whole starting time is 30s, then this block may be 29s.

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?
: fortunately, other groups have to use xen-4.2, we have repeated this experiment on that source code too, it changed nothing, time is still very long in second starting.

tupeng

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

#2 lore raw

If the allocations are 2M size, we can do better quite easily I think. Please try the attached patch.

-- Keir

Quoted 35 lines · On 13/10/2012 07:46, "tupeng212" <[email protected]> wrote:

What if you replace tlbflush_filter() call with cpus_clear(&extra_cpus_mask)? : you mean just clear it, maybe a little violent.., you 'd like to do it at any other place.

I assume you see lots of looping in one of those two functions, but only single-page-at-a-time calls into alloc_domheap_pages()->alloc_heap_pages()? : In populate_physmap, all pages are 2M size,
static void populate_physmap(struct memop_args *a)

{
    for ( i = a->nr_done; i < a->nr_extents; i++ )
    {

page = alloc_domheap_pages(d, a->extent_order, a->memflags) ->alloc_heap_pages ; //a->extent_order = 9, always 2M size
}
//you mean move that block and TLB-flush here to avoid for loop ? }

tupeng212

From: Keir Fraser <mailto:[email protected]>
Date: 2012-10-13 14:30
To: tupeng212 <mailto:[email protected]>
Subject: Re: [Xen-devel] alloc_heap_pages is low efficient with more CPUs What if you replace tlbflush_filter() call with cpus_clear(&extra_cpus_mask)? Seems a bit silly to do, but I¹d like to know how much a few cpumask operations per page is costing (most are of course much quicker than tlbflush_filter as they operate on 64 bits per iteration, rather than one bit per iteration).

If that is suitably fast, I think we can have a go at fixing this by pulling the TLB-flush logic out of alloc_heap_pages() and into the loops in increwase_reservation() and populate_physmap() in common/memory.c. I assume you see lots of looping in one of those two functions, but only single-page-at-a-time calls into alloc_domheap_pages()->alloc_heap_pages()?

Quoted 29 lines

-- Keir

Quoted 24 lines · On 13/10/2012 07:21, "tupeng212" <[email protected]> wrote:

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?
: You mean removing these code from alloc_heap_pages, then try it. I didn't do it as you said, but I calculated the whole time of if(need_tlbflush) block
by using time1=NOW() ...block ... time2=NOW(), time=time2-time1, its unit is ns, and s = ns * 10^9
it occupy high rate of the whole time. whole starting time is 30s, then this block may be 29s.

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?
: fortunately, other groups have to use xen-4.2, we have repeated this experiment on
that source code too, it changed nothing, time is still very long in second starting.

tupeng

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

author
#3 lore raw

Please try the attached patch.
: Great! you have done a good job, needless time decreases badly to 1s.

If anybody has no proposal, I suggest you to commit this patch.

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

Applied
#4 lore raw
Quoted 4 lines · On 15/10/2012 14:27, "tupeng212" <[email protected]> wrote:

Please try the attached patch.
: Great! you have done a good job, needless time decreases badly to 1s.

If anybody has no proposal, I suggest you to commit this patch.

I have applied it to xen-unstable. It probably makes sense to put it in 4.1 and 4.2 as well (cc'ed Jan, and attaching the backport for 4.1 again).

-- Keir

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

#5 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 4 lines · On 15/10/2012 14:27, "tupeng212" <[email protected]> wrote:

Please try the attached patch.
: Great! you have done a good job, needless time decreases badly to 1s.

If anybody has no proposal, I suggest you to commit this patch.

I have applied it to xen-unstable. It probably makes sense to put it in 4.1 and 4.2 as well (cc'ed Jan, and attaching the backport for 4.1 again).

Will do, but do you have an explanation how this simple, memory only operation (64 CPUs isn't that many) has this dramatic an effect on performance. Are we bouncing cache lines this badly? If so, which one(s)? I don't see what would be written frequently from multiple CPUs here - tlbflush_filter() itself only reads global variables, but never writes them.

Jan

#6 lore raw
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 4 lines · On 15/10/2012 14:27, "tupeng212" <[email protected]> wrote:

Please try the attached patch.
: Great! you have done a good job, needless time decreases badly to 1s.

If anybody has no proposal, I suggest you to commit this patch.

I have applied it to xen-unstable. It probably makes sense to put it in 4.1 and 4.2 as well (cc'ed Jan, and attaching the backport for 4.1 again).

Quoted 6 lines

Will do, but do you have an explanation how this simple, memory only operation (64 CPUs isn't that many) has this dramatic an effect on performance. Are we bouncing cache lines this badly? If so, which one(s)? I don't see what would be written frequently from multiple CPUs here - tlbflush_filter() itself only reads global variables, but never writes them.

It's just the small factors multiplying up. A 40G domain is 10M page allocations, each of which does 64x per-cpu cpumask bitops and timestamp compares. That's going on for a billion (10^9) times round tlbflush_filter()s loop. Each iteration need only take a few CPU cycles for the effect to actually be noticeable. If the stuff being touched were not in the cache (which of course it is, since this path is so hot and not touching much memory) it would probably take an hour to create the domain!

-- Keir

Quoted 2 lines

Jan

#7 lore raw
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 4 lines · On 15/10/2012 14:27, "tupeng212" <[email protected]> wrote:

Please try the attached patch.
: Great! you have done a good job, needless time decreases badly to 1s.

If anybody has no proposal, I suggest you to commit this patch.

I have applied it to xen-unstable. It probably makes sense to put it in 4.1 and 4.2 as well (cc'ed Jan, and attaching the backport for 4.1 again).

Quoted 6 lines

Will do, but do you have an explanation how this simple, memory only operation (64 CPUs isn't that many) has this dramatic an effect on performance. Are we bouncing cache lines this badly? If so, which one(s)? I don't see what would be written frequently from multiple CPUs here - tlbflush_filter() itself only reads global variables, but never writes them.

Quoted 7 lines

It's just the small factors multiplying up. A 40G domain is 10M page allocations, each of which does 64x per-cpu cpumask bitops and timestamp compares. That's going on for a billion (10^9) times round tlbflush_filter()s loop. Each iteration need only take a few CPU cycles for the effect to actually be noticeable. If the stuff being touched were not in the cache (which of course it is, since this path is so hot and not touching much memory) it would probably take an hour to create the domain!

Which means that your TODO remark in the change description is more than a nice-to-have, since
- in the fallback case using 4k allocations your change doesn't win anything
- even larger domains would still suffer from this very problem (albeit in 4.2 we try 1G allocations first, so your change should have an even more visible effect there, as long as falling back to smaller chunks isn't needed)

One question of course is whether, for sufficiently large allocation requests on sufficiently large systems, trying to avoid the TLB flush is worth it at all, considering that determining where to skip the flushes is costing so much more than the flushes themselves.

Jan

#8 lore raw
Quoted 8 lines · Jan Beulich
Quoted 7 lines

It's just the small factors multiplying up. A 40G domain is 10M page allocations, each of which does 64x per-cpu cpumask bitops and timestamp compares. That's going on for a billion (10^9) times round tlbflush_filter()s loop. Each iteration need only take a few CPU cycles for the effect to actually be noticeable. If the stuff being touched were not in the cache (which of course it is, since this path is so hot and not touching much memory) it would probably take an hour to create the domain!

Quoted 8 lines

Which means that your TODO remark in the change description is more than a nice-to-have, since
- in the fallback case using 4k allocations your change doesn't win anything
- even larger domains would still suffer from this very problem (albeit in 4.2 we try 1G allocations first, so your change should have an even more visible effect there, as long as falling back to smaller chunks isn't needed)

Agreed. This is a simple starting point which is also easy to backport though, and solves the immediate observed problem.

Quoted 4 lines

One question of course is whether, for sufficiently large allocation requests on sufficiently large systems, trying to avoid the TLB flush is worth it at all, considering that determining where to skip the flushes is costing so much more than the flushes themselves.

It might be a simpler option. I'll see how doing it the filtering way looks.

-- Keir