diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index 9f51710a46..68ec52b5c2 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -1461,16 +1461,17 @@ constructed into a plain unprivileged PV domain. ### shim\_mem (x86) > `= List of ( min: | max: | )` -Set the amount of memory that xen-shim reserves for itself. Only has effect -if pv-shim mode is enabled. +Set the amount of memory that xen-shim uses. Only has effect if pv-shim mode is +enabled. Note that this value accounts for the memory used by the shim itself +plus the free memory slack given to the shim for runtime allocations. * `min:` specifies the minimum amount of memory. Ignored if greater - than max. Default: 10M. -* `max:` specifies the maximum amount of memory. Default: 128M. + than max. +* `max:` specifies the maximum amount of memory. * `` specifies the exact amount of memory. Overrides both min and max. -By default, 1/16th of total HVM container's memory is reserved for xen-shim -with minimum amount being 10MB and maximum amount 128MB. +By default, the amount of free memory slack given to the shim for runtime usage +is 1MB. ### rcu-idle-timer-period-ms > `= ` diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index bc713fb2b5..d77c6b40de 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -290,17 +290,9 @@ unsigned long __init dom0_compute_nr_pages( * for things like DMA buffers. This reservation is clamped to a * maximum of 128MB. */ - if ( nr_pages == 0 ) - { - uint64_t rsvd = min(avail / 16, 128UL << (20 - PAGE_SHIFT)); - if ( pv_shim ) - { - rsvd = pv_shim_mem(avail); - printk("Reserved %lu pages for xen-shim\n", rsvd); - - } - nr_pages = -rsvd; - } + if ( !nr_pages ) + nr_pages = -(pv_shim ? pv_shim_mem(avail) + : min(avail / 16, 128UL << (20 - PAGE_SHIFT))); /* Negative specification means "all memory - specified amount". */ if ( (long)nr_pages < 0 ) nr_pages += avail; diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 4120cc550e..702249719e 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -57,9 +57,8 @@ static long pv_shim_grant_table_op(unsigned int cmd, unsigned int count); /* - * By default, 1/16th of total HVM container's memory is reserved for xen-shim - * with minimum amount being 10MB and maximum amount 128MB. Some users may wish - * to tune this constants for better memory utilization. This can be achieved + * By default give the shim 1MB of free memory slack. Some users may wish to + * tune this constants for better memory utilization. This can be achieved * using the following xen-shim's command line option: * * shim_mem=[min:,][max:,][] @@ -71,8 +70,8 @@ static long pv_shim_grant_table_op(unsigned int cmd, * (overrides both min and max) */ static uint64_t __initdata shim_nrpages; -static uint64_t __initdata shim_min_nrpages = 10UL << (20 - PAGE_SHIFT); -static uint64_t __initdata shim_max_nrpages = 128UL << (20 - PAGE_SHIFT); +static uint64_t __initdata shim_min_nrpages; +static uint64_t __initdata shim_max_nrpages; static int __init parse_shim_mem(const char *s) { @@ -91,15 +90,24 @@ custom_param("shim_mem", parse_shim_mem); uint64_t pv_shim_mem(uint64_t avail) { - uint64_t rsvd = min(avail / 16, shim_max_nrpages); + if ( !shim_nrpages ) + { + shim_nrpages = max(shim_min_nrpages, + total_pages - avail + (1UL << (20 - PAGE_SHIFT))); + if ( shim_max_nrpages ) + shim_max_nrpages = min(shim_nrpages, shim_max_nrpages); + } - if ( shim_nrpages ) - return shim_nrpages; + if ( total_pages - avail > shim_nrpages ) + panic("pages used by shim > shim_nrpages (%#lx > %#lx)", + total_pages - avail, shim_nrpages); - if ( shim_min_nrpages <= shim_max_nrpages ) - rsvd = max(rsvd, shim_min_nrpages); + shim_nrpages -= total_pages - avail; - return rsvd; + printk("shim used pages %#lx reserving %#lx free pages\n", + total_pages - avail, shim_nrpages); + + return shim_nrpages; } #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \