[v3.1,74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
diff mbox series

Message ID 1580112408-93354-1-git-send-email-imammedo@redhat.com
State New
Headers show
Series
  • Untitled series #155393
Related show

Commit Message

Igor Mammedov Jan. 27, 2020, 8:06 a.m. UTC
Since all RAM is backed by hostmem backends, drop
global -mem-path invariant and simplify code.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v4:
  * fix access to uninitialized pagesize/hpsize
    (David Gibson <david@gibson.dropbear.id.au>)

CC: thuth@redhat.com
CC: aik@ozlabs.ru
CC: mdroth@linux.vnet.ibm.com
CC: david@gibson.dropbear.id.au
CC: qemu-ppc@nongnu.org
CC: pbonzini@redhat.com
CC: rth@twiddle.net
---
 exec.c | 49 ++++---------------------------------------------
 1 file changed, 4 insertions(+), 45 deletions(-)

Comments

David Gibson Jan. 27, 2020, 8:18 a.m. UTC | #1
On Mon, Jan 27, 2020 at 09:06:48AM +0100, Igor Mammedov wrote:
> Since all RAM is backed by hostmem backends, drop
> global -mem-path invariant and simplify code.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v4:
>   * fix access to uninitialized pagesize/hpsize
>     (David Gibson <david@gibson.dropbear.id.au>)

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> CC: thuth@redhat.com
> CC: aik@ozlabs.ru
> CC: mdroth@linux.vnet.ibm.com
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> CC: pbonzini@redhat.com
> CC: rth@twiddle.net
> ---
>  exec.c | 49 ++++---------------------------------------------
>  1 file changed, 4 insertions(+), 45 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 67e520d..9f5421c 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1668,59 +1668,18 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
>  long qemu_minrampagesize(void)
>  {
>      long hpsize = LONG_MAX;
> -    long mainrampagesize;
> -    Object *memdev_root;
> -    MachineState *ms = MACHINE(qdev_get_machine());
> -
> -    mainrampagesize = qemu_mempath_getpagesize(mem_path);
> -
> -    /* it's possible we have memory-backend objects with
> -     * hugepage-backed RAM. these may get mapped into system
> -     * address space via -numa parameters or memory hotplug
> -     * hooks. we want to take these into account, but we
> -     * also want to make sure these supported hugepage
> -     * sizes are applicable across the entire range of memory
> -     * we may boot from, so we take the min across all
> -     * backends, and assume normal pages in cases where a
> -     * backend isn't backed by hugepages.
> -     */
> -    memdev_root = object_resolve_path("/objects", NULL);
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
> -    }
> -    if (hpsize == LONG_MAX) {
> -        /* No additional memory regions found ==> Report main RAM page size */
> -        return mainrampagesize;
> -    }
> -
> -    /* If NUMA is disabled or the NUMA nodes are not backed with a
> -     * memory-backend, then there is at least one node using "normal" RAM,
> -     * so if its page size is smaller we have got to report that size instead.
> -     */
> -    if (hpsize > mainrampagesize &&
> -        (ms->numa_state == NULL ||
> -         ms->numa_state->num_nodes == 0 ||
> -         ms->numa_state->nodes[0].node_memdev == NULL)) {
> -        static bool warned;
> -        if (!warned) {
> -            error_report("Huge page support disabled (n/a for main memory).");
> -            warned = true;
> -        }
> -        return mainrampagesize;
> -    }
> +    Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> +    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
>      return hpsize;
>  }
>  
>  long qemu_maxrampagesize(void)
>  {
> -    long pagesize = qemu_mempath_getpagesize(mem_path);
> +    long pagesize = 0;
>      Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_max_backend_pagesize,
> -                             &pagesize);
> -    }
> +    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
>      return pagesize;
>  }
>  #else

Patch
diff mbox series

diff --git a/exec.c b/exec.c
index 67e520d..9f5421c 100644
--- a/exec.c
+++ b/exec.c
@@ -1668,59 +1668,18 @@  static int find_max_backend_pagesize(Object *obj, void *opaque)
 long qemu_minrampagesize(void)
 {
     long hpsize = LONG_MAX;
-    long mainrampagesize;
-    Object *memdev_root;
-    MachineState *ms = MACHINE(qdev_get_machine());
-
-    mainrampagesize = qemu_mempath_getpagesize(mem_path);
-
-    /* it's possible we have memory-backend objects with
-     * hugepage-backed RAM. these may get mapped into system
-     * address space via -numa parameters or memory hotplug
-     * hooks. we want to take these into account, but we
-     * also want to make sure these supported hugepage
-     * sizes are applicable across the entire range of memory
-     * we may boot from, so we take the min across all
-     * backends, and assume normal pages in cases where a
-     * backend isn't backed by hugepages.
-     */
-    memdev_root = object_resolve_path("/objects", NULL);
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
-    }
-    if (hpsize == LONG_MAX) {
-        /* No additional memory regions found ==> Report main RAM page size */
-        return mainrampagesize;
-    }
-
-    /* If NUMA is disabled or the NUMA nodes are not backed with a
-     * memory-backend, then there is at least one node using "normal" RAM,
-     * so if its page size is smaller we have got to report that size instead.
-     */
-    if (hpsize > mainrampagesize &&
-        (ms->numa_state == NULL ||
-         ms->numa_state->num_nodes == 0 ||
-         ms->numa_state->nodes[0].node_memdev == NULL)) {
-        static bool warned;
-        if (!warned) {
-            error_report("Huge page support disabled (n/a for main memory).");
-            warned = true;
-        }
-        return mainrampagesize;
-    }
+    Object *memdev_root = object_resolve_path("/objects", NULL);
 
+    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
     return hpsize;
 }
 
 long qemu_maxrampagesize(void)
 {
-    long pagesize = qemu_mempath_getpagesize(mem_path);
+    long pagesize = 0;
     Object *memdev_root = object_resolve_path("/objects", NULL);
 
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_max_backend_pagesize,
-                             &pagesize);
-    }
+    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
     return pagesize;
 }
 #else