|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 03/14] x86/setup: special treatment of initrd for PVH Dom0
Dealing with large initrd-s is problematic in two ways: We needlessly
copy around a large chunk of data, and our calculation of how much
memory to give Dom0 assumes the space taken by the initrd is actually
available at the time of populating Dom0's P2M.
As a first step, make effort during early boot to try to place the initrd
in a chunk of memory that's a multiple of 1Gb (or, if not available / not
possibly going to fit, in a chunk a multiple of 2Mb in size). This may
(but generally won't) result in more copying, which we simply need to
accept. Record (and use) the extra space allocated in (as) headroom, which
then needs accouting for in pvh_load_kernel().
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
Not being able to check bm->kind is of course not very nice. The field is
only set quite a bit later, and that setting can - afaict - not be moved
ahead of the call to xsm_multiboot_init().
The bumping of mask to L3's in __start_xen() may transiently breaks
booting of Dom0 with overly much memory assigned to it (with the improved
heuristic it doesn't on my test systems anymore, though). That'll be
resolved when the headroom space is properly dealt with (consumed into
Dom0, or freed). Therefore this patch and everything up to the one adding
the consuming code want committing together, or addition of that
conditional wants delaying until that later change.
Simply using nr_ram_pages()' return value is of course a pretty raw
estimate. We could e.g. also subtract Xen's image size and, perhaps more
relevant, an estimate of frame_table[].
---
v2: Re-instate lost loop continuation condition. Improve and explain
heuristic for whether to look for a multi-Gb block of memory.
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -445,6 +445,20 @@ unsigned long __init dom0_compute_nr_pag
return nr_pages;
}
+/*
+ * A simplistic sibling of dom0_compute_nr_pages(), for obtaining a very early
+ * estimate.
+ */
+unsigned long __init get_dom0_size(unsigned long avail)
+{
+ if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set )
+ parse_dom0_mem(CONFIG_DOM0_MEM);
+
+ return get_memsize(memsize_gt_zero(&dom0_size) ? &dom0_size
+ : &dom0_max_size,
+ avail);
+}
+
static void __init process_dom0_ioports_disable(struct domain *dom0)
{
unsigned long io_from, io_to;
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -653,7 +653,8 @@ static int __init pvh_load_kernel(
void *image_base = bootstrap_map_bm(image);
void *image_start = image_base + image->arch.headroom;
unsigned long image_len = image->size;
- unsigned long initrd_len = initrd ? initrd->size : 0;
+ unsigned long initrd_len =
+ initrd ? initrd->size - initrd->arch.headroom : 0;
size_t cmdline_len = bd->cmdline ? strlen(bd->cmdline) + 1 : 0;
const char *initrd_cmdline = NULL;
struct elf_binary elf;
@@ -751,7 +752,8 @@ static int __init pvh_load_kernel(
if ( initrd != NULL )
{
- rc = hvm_copy_to_guest_phys(last_addr, __va(initrd->start),
+ rc = hvm_copy_to_guest_phys(last_addr,
+ __va(initrd->start +
initrd->arch.headroom),
initrd_len, v);
if ( rc )
{
--- a/xen/arch/x86/include/asm/setup.h
+++ b/xen/arch/x86/include/asm/setup.h
@@ -68,4 +68,6 @@ extern bool opt_dom0_verbose;
extern bool opt_dom0_cpuid_faulting;
extern bool opt_dom0_msr_relaxed;
+unsigned long get_dom0_size(unsigned long avail);
+
#endif
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1023,6 +1023,26 @@ static unsigned long __init nr_ram_pages
return nr_pages;
}
+static __init bool fits_in_low_ram(unsigned long size, unsigned long align)
+{
+ size = ROUNDUP(size, align);
+
+ for ( unsigned int i = 0; i < e820.nr_map; ++i )
+ {
+ unsigned long start = ROUNDUP(e820.map[i].addr, align);
+ unsigned long end = ROUNDDOWN(e820.map[i].addr + e820.map[i].size,
+ align);
+
+ if ( e820.map[i].type != E820_RAM || start >= GB(4) )
+ continue;
+
+ if ( end > start && end - start >= size )
+ return true;
+ }
+
+ return false;
+}
+
/*
* Calculate the maximum possible size of the dom0 cmdline. Pieces of the
* dom0 cmdline optionally come from the bootloader directly, from Xen's
@@ -1613,6 +1633,60 @@ void asmlinkage __init noreturn __start_
struct boot_module *bm = &bi->mods[j];
unsigned long size = PAGE_ALIGN(bm->arch.headroom + bm->size);
+ /*
+ * For PVH Dom0 try to place the initrd in a full multi-Gb (or
+ * multi-2Mb) chunk, such that assigning the pages directly can
+ * be done while still using superpage mappings.
+ */
+ if ( opt_dom0_pvh && j == 1 /* bm->kind == BOOTMOD_RAMDISK */ )
+ {
+ /*
+ * As we may come here more than once, and as bm->size includes
+ * headroom after relocation, unlike above we need to subtract
+ * headroom here. (The only module with incoming non-zero
+ * headroom is the kernel.)
+ */
+ size = PAGE_ALIGN(bm->size - bm->arch.headroom);
+
+ /*
+ * Heuristic, in an attempt to predict what will be decided
+ * when actually loading (mapping) the initrd: There's no point
+ * trying 1Gb mappings when Dom0 has less than 2Gb. There's
+ * also no point trying 1Gb mappings if the initrd fits in low
+ * memory, but there's no contiguous 1G-aligned range available
+ * there.
+ */
+ if ( get_dom0_size(nr_ram_pages()) >= PFN_DOWN(GB(2)) &&
+ (fits_in_low_ram(size, 1UL << L3_PAGETABLE_SHIFT) ||
+ !fits_in_low_ram(size, PAGE_SIZE)) )
+ mask = (1UL << L3_PAGETABLE_SHIFT) - 1;
+
+ for ( ; mask > PAGE_SIZE; mask >>= PAGETABLE_ORDER )
+ {
+ if ( !(bm->start & mask) && bm->arch.relocated )
+ break;
+
+ end = e;
+ do {
+ end = consider_modules((s + mask) & ~mask, end & ~mask,
+ (size + mask) & ~mask, bi->mods,
+ bi->nr_modules + relocated, j);
+ } while ( (end & mask) && end > s );
+
+ if ( end <= s )
+ continue;
+
+ if ( highmem_start && end > highmem_start )
+ break;
+
+ size = (size + mask) & ~mask;
+ bm->start += bm->arch.headroom;
+ bm->size -= bm->arch.headroom;
+ bm->arch.headroom = size - PAGE_ALIGN(bm->size);
+ goto move_module;
+ }
+ }
+
if ( bm->arch.relocated )
continue;
@@ -1625,6 +1699,7 @@ void asmlinkage __init noreturn __start_
if ( s < end && (bm->arch.headroom || (end - size) > bm->start) )
{
+ move_module:
move_memory(end - size + bm->arch.headroom, bm->start,
bm->size);
bm->start = (end - size);
bm->size += bm->arch.headroom;
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |