Skip to contentSkip to conversation

Converting heap page_infos to contiguous virtual

DISCUSSION Boris Ostrovsky 6 participants 20 messages Jul 13, 2016 – Aug 1, 2016

lore
Share & tools
lore
#0 lore raw

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this? Do I need to account for the PDX hole?

Thanks.
-boris

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

#1 lore raw
Quoted 8 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

Quoted 7 lines

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Quoted 1 line

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

~Andrew

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

#2 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));
Quoted 5 lines
Quoted 1 line

Would it be valid to this?

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 5 lines
Quoted 2 lines

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

Quoted 7 lines

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

So I would be OK with finding which mfn of my range points to beginning of the hole and break the mfn range into two sections --- one below the hole and one above. With hope that both ranges can be mapped contiguously --- something that I don't know whether is true.

-boris

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

#3 lore raw
Quoted 34 lines · Boris Ostrovsky
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));
Quoted 5 lines
Quoted 1 line

Would it be valid to this?

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines
Quoted 1 line

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

Quoted 7 lines
Quoted 3 lines

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

So I would be OK with finding which mfn of my range points to beginning of the hole and break the mfn range into two sections --- one below the hole and one above. With hope that both ranges can be mapped contiguously --- something that I don't know whether is true.

In fact, I am OK with breaking the range into many chunks. My goal is to be able to map something like a few megabytes (maybe few tens of megabytes at most) contiguously.

-boris

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

#4 lore raw
In reply to Boris Ostrovsky
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

Quoted 7 lines
Quoted 3 lines

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

So I would be OK with finding which mfn of my range points to beginning of the hole and break the mfn range into two sections --- one below the hole and one above. With hope that both ranges can be mapped contiguously --- something that I don't know whether is true.

If you have a struct page_info * in your hand, and know from the E820 where the next non RAM boundary is, I think you should be safe to clear memory over a contiguous range of the directmap. There shouldn't be any discontinuities over that range.

Be aware of memory_guard() though which does shoot holes in the directmap. However, only allocated pages should be guarded, so you should never be in the position of scrubbing pages with a missing mapping in the directmap. For RAM above the 5TB boundary, map_domain_page() will DTRT, but we might want to see about making a variant which can make mappings spanning more than 4k.

(You probably want someone else to sanity check my logic here.)

~Andrew

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

#5 lore raw
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

Quoted 8 lines
Quoted 4 lines

So I would be OK with finding which mfn of my range points to beginning of the hole and break the mfn range into two sections --- one below the hole and one above. With hope that both ranges can be mapped contiguously --- something that I don't know whether is true.

If you have a struct page_info * in your hand, and know from the E820 where the next non RAM boundary is, I think you should be safe to clear memory over a contiguous range of the directmap. There shouldn't be any discontinuities over that range.

OK, I'll look at this, thanks.

Quoted 7 lines

Be aware of memory_guard() though which does shoot holes in the directmap. However, only allocated pages should be guarded, so you should never be in the position of scrubbing pages with a missing mapping in the directmap. For RAM above the 5TB boundary, map_domain_page() will DTRT, but we might want to see about making a variant which can make mappings spanning more than 4k.

Maybe have it at least attempt to map a larger range, i.e. not try to cover all corner cases. Something like map_domain_page_fast(order).

-boris

Quoted 9 lines

(You probably want someone else to sanity check my logic here.)

~Andrew

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

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

#6 lore raw
Quoted 35 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 4 lines

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Being free is not relevant. It depends whether current is a 64bit PV guest or not. Even in the idle loop, we don't context switch away from current's pagetables.

Realistically, you must at all times use map_domain_page() (or an alternative thereabouts), as the 5TB limit with 64bit PV guests turns into a 3.5TB limit depending on CONFIG_BIGMEM.

Quoted 24 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

PDX compression is used to reduce the size of the frametable when there are large unused ranges of mfns. Without paying attention to the PDX shift, you don't know where the discontinuities lie.

However, because the PDX shift is an aligned power of two, there are likely to be struct page_info*'s in the frame_table which don't point at real RAM, and won't have a virtual mapping even in the directmap.

Quoted 8 lines
Quoted 4 lines

So I would be OK with finding which mfn of my range points to beginning of the hole and break the mfn range into two sections --- one below the hole and one above. With hope that both ranges can be mapped contiguously --- something that I don't know whether is true.

If you have a struct page_info * in your hand, and know from the E820 where the next non RAM boundary is, I think you should be safe to clear memory over a contiguous range of the directmap. There shouldn't be any discontinuities over that range.

OK, I'll look at this, thanks.

Quoted 8 lines
Quoted 6 lines

Be aware of memory_guard() though which does shoot holes in the directmap. However, only allocated pages should be guarded, so you should never be in the position of scrubbing pages with a missing mapping in the directmap. For RAM above the 5TB boundary, map_domain_page() will DTRT, but we might want to see about making a variant which can make mappings spanning more than 4k.

Maybe have it at least attempt to map a larger range, i.e. not try to cover all corner cases. Something like map_domain_page_fast(order).

map_domain_page() is fast if it can use the directmap. (However, it doesn't on a debug build to test the highmem logic.)

I expect the exceedingly common case for RAM above the 5TB (or 3.5TB) boundary will be for it to already align on a 1GB boundary, at which point 2M or 1G superpages will work just fine for a temporary mapping.

~Andrew

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

#7 lore raw
Quoted 36 lines · Andrew Cooper
Quoted 35 lines · Boris Ostrovsky
Quoted 34 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 7 lines
Quoted 4 lines

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Being free is not relevant. It depends whether current is a 64bit PV guest or not. Even in the idle loop, we don't context switch away from current's pagetables.

Can we force switch to idle (i.e. a non-64b PV guest) when we know it would be useful for mapping/scrubbing? The cost of TLB flush (if that was the reason) may be small compared to advantages brought by fast mapping during scrubbing.

-boris

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

#8 lore raw
Quoted 41 lines · Boris Ostrovsky
Quoted 40 lines · Andrew Cooper
Quoted 39 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Quoted 8 lines
Quoted 3 lines

Being free is not relevant. It depends whether current is a 64bit PV guest or not. Even in the idle loop, we don't context switch away from current's pagetables.

Can we force switch to idle (i.e. a non-64b PV guest) when we know it would be useful for mapping/scrubbing? The cost of TLB flush (if that was the reason) may be small compared to advantages brought by fast mapping during scrubbing.

It sounds like a plausible option, but would need some numbers to back it up.

However, I would recommend getting something functioning first, before trying to optimise it.

There is probably a lot to be gained simply by improving clear_page().

~Andrew

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

#9 lore raw
Quoted 3 lines · Andrew Cooper

However, I would recommend getting something functioning first, before trying to optimise it.

There are two fairly independent parts to improving scrubbing: one is making it asynchronous and second is improving clear_page() performance. Whole-RAM mapping is needed for the latter.

Quoted 2 lines

There is probably a lot to be gained simply by improving clear_page().

The biggest improvement comes from switching to AVX(2) when available. It's been a while since I ran those tests so I will have to re-measure it but my recollection is that 4K was too small to see significant changes.

A potential improvement might come from dropping (or, rather, deferring) sfence in clear_page_sse2. I don't know how much this would buy us though.

-boris

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

#10 lore raw
Quoted 11 lines · Boris Ostrovsky
Quoted 2 lines · Andrew Cooper

However, I would recommend getting something functioning first, before trying to optimise it.

There are two fairly independent parts to improving scrubbing: one is making it asynchronous and second is improving clear_page() performance. Whole-RAM mapping is needed for the latter.

Quoted 1 line

There is probably a lot to be gained simply by improving clear_page().

The biggest improvement comes from switching to AVX(2) when available. It's been a while since I ran those tests so I will have to re-measure it but my recollection is that 4K was too small to see significant changes.

There is also the new clzero on AMD Zen processors, which looks like an interesting option which doesn't involve context switching SIMD state.

Quoted 3 lines

A potential improvement might come from dropping (or, rather, deferring) sfence in clear_page_sse2. I don't know how much this would buy us though.

The sfence is mandatory because of the movnti. It cannot be dropped, or the zeroes might be stuck in the Write Combining buffer when something else comes to access the page.

~Andrew

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

#11 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Boris Ostrovsky
Quoted 2 lines · Andrew Cooper

However, I would recommend getting something functioning first, before trying to optimise it.

There are two fairly independent parts to improving scrubbing: one is making it asynchronous and second is improving clear_page() performance. Whole-RAM mapping is needed for the latter.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

There is probably a lot to be gained simply by improving clear_page().

The biggest improvement comes from switching to AVX(2) when available. It's been a while since I ran those tests so I will have to re-measure it but my recollection is that 4K was too small to see significant changes.

There is also the new clzero on AMD Zen processors, which looks like an interesting option which doesn't involve context switching SIMD state.

Yes, this looks like a good option. I am not aware of Zen HW being available to me on the near future though ;-)

Quoted 6 lines
Quoted 3 lines

A potential improvement might come from dropping (or, rather, deferring) sfence in clear_page_sse2. I don't know how much this would buy us though.

The sfence is mandatory because of the movnti. It cannot be dropped, or the zeroes might be stuck in the Write Combining buffer when something else comes to access the page.

Right, but while the chunk of pages is being scrubbed, those pages are not available for anyone to access. Before they are (as a set) declared available an sfence will be issued. That's what I meant by "deferring".

-boris

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

#12 lore raw
In reply to Boris Ostrovsky
Quoted 8 lines · Boris Ostrovsky
Quoted 3 lines · Andrew Cooper

However, I would recommend getting something functioning first, before trying to optimise it.

There are two fairly independent parts to improving scrubbing: one is making it asynchronous and second is improving clear_page() performance. Whole-RAM mapping is needed for the latter.

Attaching a nice graph of different memset on Broadwell (credits go to Joao for doing the testing). Skylake is 10% faster than Broadwell.

Quoted 11 lines
Quoted 3 lines

There is probably a lot to be gained simply by improving clear_page().

The biggest improvement comes from switching to AVX(2) when available. It's been a while since I ran those tests so I will have to re-measure it but my recollection is that 4K was too small to see significant changes.

A potential improvement might come from dropping (or, rather, deferring) sfence in clear_page_sse2. I don't know how much this would buy us though.

Quoted 8 lines

-boris

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

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

#13 lore raw
Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · Boris Ostrovsky
Quoted 2 lines · Andrew Cooper

However, I would recommend getting something functioning first, before trying to optimise it.

There are two fairly independent parts to improving scrubbing: one is making it asynchronous and second is improving clear_page() performance. Whole-RAM mapping is needed for the latter.

Attaching a nice graph of different memset on Broadwell (credits go to Joao for doing the testing). Skylake is 10% faster than Broadwell.

Graph says memcpy() not memset().

Either way, it looks like we would do very well to "borrow" a different implementation.

~Andrew

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

#14 lore raw
In reply to Boris Ostrovsky
Quoted 36 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 4 lines

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Is this start-of-day scrubbing (when there are no guests), or scrubbing on guest destruction?

If the former, it seems like it might not be too difficult to arrange that we're in a context that has all the RAM mapped.

-George

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

#15 lore raw
Quoted 40 lines · George Dunlap
Quoted 35 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 4 lines

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Quoted 5 lines

Is this start-of-day scrubbing (when there are no guests), or scrubbing on guest destruction?

If the former, it seems like it might not be too difficult to arrange that we're in a context that has all the RAM mapped.

This will be runtime scrubbing of pages. This topic has come up at several hackathons.

Currently, domain destroy on a 1TB VM takes ~10 mins of synchronously scrubbing RAM in continuations of the domain_kill() hypercall (and those databases VMs really like their RAM).

ISTR the plan was to have a page_info "dirty" flag and a dirty page list which is scrubbed while idle (or per-node, more likely). alloc_{dom/xen}_heap_pages() can pull off the dirty or free list, doing a small synchronous scrub if it was dirty and needs to be clean. domain_kill() can just do a pagelist_splice() to move all memory onto the dirty list, and save 10 minutes per TB. The boot time memory scrub can then be implemented in terms of setting the dirty flag by default, rather than being an explicit step.

(Although I really shouldn't be second-guessing what Boris is planning to implement ;p)

~Andrew

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

#16 lore raw

Hi,

Quoted 41 lines · Andrew Cooper
Quoted 40 lines · George Dunlap
Quoted 39 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));
     char *va = mfn_to_virt(mfn_x(mfn));
     memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Quoted 8 lines
Quoted 5 lines

Is this start-of-day scrubbing (when there are no guests), or scrubbing on guest destruction?

If the former, it seems like it might not be too difficult to arrange that we're in a context that has all the RAM mapped.

This will be runtime scrubbing of pages. This topic has come up at several hackathons.

Is it a feature that will be implemented in common code? If so, bear in mind that ARM 32-bit hypervisor does not have all the memory mapped (actually only Xen heap is mapped).

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#17 lore raw
Quoted 55 lines · Julien Grall

Hi,

Quoted 52 lines · Andrew Cooper
Quoted 50 lines · George Dunlap
Quoted 38 lines · Boris Ostrovsky
Quoted 29 lines · Andrew Cooper
Quoted 20 lines · Boris Ostrovsky
Quoted 19 lines · Andrew Cooper
Quoted 9 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

Quoted 7 lines

mfn_t mfn =

_mfn(page_to_mfn(pg));
     char *va = mfn_to_virt(mfn_x(mfn));
     memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

In principle, yes. The frame_table is in order.

Quoted 8 lines
Quoted 3 lines

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You
need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

Quoted 6 lines

I don't know whether it would make any difference but the pages that I am
talking about are not in use by any guest, they are free. (This question
is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Is this start-of-day scrubbing (when there are no guests), or scrubbing on guest destruction?

If the former, it seems like it might not be too difficult to arrange that we're in a context that has all the RAM mapped.

Quoted 6 lines
Quoted 2 lines

This will be runtime scrubbing of pages. This topic has come up at several hackathons.

Is it a feature that will be implemented in common code? If so, bear in mind that ARM 32-bit hypervisor does not have all the memory mapped (actually only Xen heap is mapped).

Nor does x86, on boxes with more than 5TB of RAM.

Where possible, we should try to make it common, but it will depend on exactly how similar the heap implementations are.

~Andrew

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

#18 lore raw
In reply to Andrew Cooper
Quoted 41 lines · Andrew Cooper
Quoted 40 lines · George Dunlap
Quoted 39 lines · Boris Ostrovsky
Quoted 26 lines · Andrew Cooper
Quoted 17 lines · Boris Ostrovsky
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Boris Ostrovsky

I would like to clear a bunch of Xen heap pages at once (i.e. not page-by-page).

Greatly simplifying things, let's say I grab (in common/page_alloc.c)
pg = page_list_remove_head(&heap(node, zone, order)

and then

mfn_t mfn =

_mfn(page_to_mfn(pg));                                        
    char *va = mfn_to_virt(mfn_x(mfn));
    memset(va, 0, 4096 * (1 << order));

Would it be valid to this?

Quoted 8 lines
Quoted 4 lines

In principle, yes. The frame_table is in order.

However, mfn_to_virt() will blow up for RAM above the 5TB boundary. You need to map_domain_page() to get a mapping.

Right, but that would mean going page-by-page, which I want to avoid.

Now, DIRECTMAP_SIZE is ~128TB (if my math is correct) --- doesn't it imply that it maps this big a range contiguously (modulo PDX hole)?

Quoted 8 lines

Your maths is correct, and yet you will end up with problems if you trust it.

That is the magic mode for the idle and monitor pagetables. In the context of a 64bit PV guest, the cutoff is at 5TB, at which point you venture into the virtual address space reserved for guest kernel use. (It is rather depressing that the 64bit PV guest ABI is the factor limiting Xen's maximum RAM usage.)

I don't know whether it would make any difference but the pages that I am talking about are not in use by any guest, they are free. (This question is for scrubbing rewrite that I am working on. Which apparently you figured out judged by what you are saying below)

Quoted 6 lines
Quoted 5 lines

Is this start-of-day scrubbing (when there are no guests), or scrubbing on guest destruction?

If the former, it seems like it might not be too difficult to arrange that we're in a context that has all the RAM mapped.

This will be runtime scrubbing of pages.

Actually, both. My prototype (apparently, mistakenly) assumed whole RAM mapping and so I used the same clearing code during both system boot and guest destruction.

In the former case with a 6TB box scrubbing time went from minutes to seconds. This was a while ago so I don't remember exact numbers (or whether the system had 6 or fewer TB). This was using AVX instructions.

Quoted 16 lines

This topic has come up at
several hackathons.

Currently, domain destroy on a 1TB VM takes ~10 mins of synchronously scrubbing RAM in continuations of the domain_kill() hypercall (and those databases VMs really like their RAM).

ISTR the plan was to have a page_info "dirty" flag and a dirty page list which is scrubbed while idle (or per-node, more likely). alloc_{dom/xen}_heap_pages() can pull off the dirty or free list, doing a small synchronous scrub if it was dirty and needs to be clean. domain_kill() can just do a pagelist_splice() to move all memory onto the dirty list, and save 10 minutes per TB. The boot time memory scrub can then be implemented in terms of setting the dirty flag by default, rather than being an explicit step.

Quoted 2 lines

(Although I really shouldn't be second-guessing what Boris is planning to implement ;p)

Not exactly this, but something along those lines.

-boris

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

#19 lore raw
In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.07.16 at 22:02, <[email protected]> wrote:
Quoted 1 line · Boris Ostrovsky

Do I need to account for the PDX hole?

Jan is probably the best person to ask about this, but I am failure sure there are lurking dragons here.

I don't think there are - contiguous chunks of pages can't have a PDX hole in their middle. There would be two parts (before and after the hole), and no allocation can return two such parts.

Furthermore PDX compression actually _reduces_ holes, i.e. there might only be a case where physical addresses are discontiguous yet virtual ones are contiguous, but never the other way around.

Jan

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