]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
xen/shim: modify shim_mem parameter behaviour
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 11 Jan 2018 11:41:20 +0000 (11:41 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 16 Jan 2018 18:34:05 +0000 (18:34 +0000)
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@citrix.com>
docs/misc/xen-command-line.markdown
xen/arch/x86/dom0_build.c
xen/arch/x86/pv/shim.c

index 164ff319094a9ea9d8f271e5dda03a39a649791d..f73990f7cda22eab38b33981810c6a38c7079b3a 100644 (file)
@@ -1489,16 +1489,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>`
index 2aac0803fc2dcfe89a2fb2863a8b728fae42e071..593bdbc18bc71f9ec16794f07a99f32481b306d8 100644 (file)
@@ -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;
index 4120cc550ed73af7f4249c8474cec7bcb50cf48d..702249719e840a9ba3c69178e4fe62127bac447b 100644 (file)
@@ -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| \