[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen stable-4.10] xen/shim: modify shim_mem parameter behaviour



commit 9d60bc96bef01444e30a9653ebf06b24c5bc8be5
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Thu Jan 11 11:41:20 2018 +0000
Commit:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Fri Jan 12 15:47:32 2018 +0000

    xen/shim: modify shim_mem parameter behaviour
    
    shim_mem will now account for both the memory used by the hypervisor
    loaded in memory and the free memory slack given to the shim for
    runtime usage.
    
    From experimental testing it seems like the total amount of MiB used
    by the shim (giving it ~1MB of free memory for runtime) is:
    
    memory/113 + 20
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 docs/misc/xen-command-line.markdown | 13 +++++++------
 xen/arch/x86/dom0_build.c           | 14 +++-----------
 xen/arch/x86/pv/shim.c              | 30 +++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 28 deletions(-)

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:<size> | max:<size> | <size> )`
 
-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:<size>` specifies the minimum amount of memory. Ignored if greater
-   than max. Default: 10M.
-* `max:<size>` specifies the maximum amount of memory. Default: 128M.
+   than max.
+* `max:<size>` specifies the maximum amount of memory.
 * `<size>` 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
 > `= <integer>`
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:<min_amt>,][max:<max_amt>,][<amt>]
@@ -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 ( total_pages - avail > shim_nrpages )
+        panic("pages used by shim > shim_nrpages (%#lx > %#lx)",
+              total_pages - avail, shim_nrpages);
 
-    if ( shim_nrpages )
-        return shim_nrpages;
+    shim_nrpages -= total_pages - avail;
 
-    if ( shim_min_nrpages <= shim_max_nrpages )
-        rsvd = max(rsvd, shim_min_nrpages);
+    printk("shim used pages %#lx reserving %#lx free pages\n",
+           total_pages - avail, shim_nrpages);
 
-    return rsvd;
+    return shim_nrpages;
 }
 
 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.10

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.