Skip to contentSkip to conversation

mempath: add option to specify minimum huge page size

PATCH In review Marcelo Tosatti 3 participants 6 messages Mar 7, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mempath: add option to specify minimum huge page size

Failing initialization in case hugepage path has
hugepage smaller than specified.

exec.c +7 -0
index b69fd29..c95a0f3 100644
@@ -1034,6 +1034,13 @@ static void *file_ram_alloc(RAMBlock *block,
         return NULL;
     }
 
+    if (mem_path_min_hpagesize && hpagesize < mem_path_min_hpagesize) {
+        fprintf(stderr, "mount point (%s) has page size "
+                "(%ld) < (%ld) = min_hpagesize\n", path, hpagesize,
+                mem_path_min_hpagesize);
+        exit(1);
+    }
+
     if (memory < hpagesize) {
         return NULL;
     }
include/exec/cpu-all.h +1 -0
index 4cb4b4a..cc9e28a 100644
@@ -470,6 +470,7 @@ extern RAMList ram_list;
 
 extern const char *mem_path;
 extern int mem_prealloc;
+extern unsigned long int mem_path_min_hpagesize;
 
 /* Flags stored in the low bits of the TLB virtual address.  These are
    defined so that fast path ram access is all zeros.  */
qemu-options.hx +2 -2
index 56e5fdf..36743e1 100644
@@ -221,9 +221,9 @@ gigabytes respectively.
 ETEXI
 
 DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
-    "-mem-path FILE  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+    "-mem-path [mem-path=]file[,min-hpage-size=value]  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
 STEXI
-@item -mem-path @var{path}
+@item -mem-path [mem-path=]@var{path}[,min-hpage-size=@var{min-hpage-size}]
 @findex -mem-path
 Allocate guest RAM from a temporarily created file in @var{path}.
 ETEXI
vl.c +27 -2
index 1d27b34..08f9bee 100644
@@ -136,6 +136,7 @@ static int display_remote;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
+unsigned long int mem_path_min_hpagesize;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -479,6 +480,22 @@ static QemuOptsList qemu_msg_opts = {
     },
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
+    .implied_opt_name = "mem-path",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_mempath_opts.head),
+    .desc = {
+        {
+            .name = "mem-path",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "min-hpage-size",
+            .type = QEMU_OPT_SIZE,
+        },
+        { /* end of list */ }
+    },
+};
+
 /**
  * Get machine options
  *
@@ -2863,6 +2880,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_tpmdev_opts);
     qemu_add_opts(&qemu_realtime_opts);
     qemu_add_opts(&qemu_msg_opts);
+    qemu_add_opts(&qemu_mempath_opts);
 
     runstate_init();
 
@@ -3189,9 +3207,16 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
 #endif
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
+                mem_path = qemu_opt_get(opts, "mem-path");
+                mem_path_min_hpagesize = qemu_opt_get_size(opts,
+                                                           "min-hpage-size", 0);
                 break;
+            }
             case QEMU_OPTION_mem_prealloc:
                 mem_prealloc = 1;
                 break;
#1 lore raw
Quoted 10 lines · Marcelo Tosatti

Failing initialization in case hugepage path has
hugepage smaller than specified.

exec.c +0 -0
index b69fd29..c95a0f3 100644

exec.c

Quoted 10 lines
exec.c +4 -2
 
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
 
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);

Pre-existing, but this is yet another inconsistent naming between C objects and the command line. If we were consistent, it should be named QEMU_OPTION_mem_path, and qemu_mem_path_options. (See my recent complaint about other misnamed options:
https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg01131.html)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 22 lines · Eric Blake
Quoted 10 lines · Marcelo Tosatti

Failing initialization in case hugepage path has
hugepage smaller than specified.

exec.c +0 -0
index b69fd29..c95a0f3 100644

exec.c

Quoted 10 lines
exec.c +4 -2
 
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
 
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);
Quoted 5 lines

Pre-existing, but this is yet another inconsistent naming between C objects and the command line. If we were consistent, it should be named QEMU_OPTION_mem_path, and qemu_mem_path_options. (See my recent complaint about other misnamed options:
https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg01131.html)

Hi Erik,

What is the practical effect of the mismatch?

#3 lore raw
Quoted 23 lines · Marcelo Tosatti
Quoted 22 lines · Eric Blake
Quoted 20 lines · Marcelo Tosatti

Failing initialization in case hugepage path has
hugepage smaller than specified.

exec.c +4 -2
index b69fd29..c95a0f3 100644
 
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
 
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);
Quoted 7 lines
Quoted 5 lines

Pre-existing, but this is yet another inconsistent naming between C objects and the command line. If we were consistent, it should be named QEMU_OPTION_mem_path, and qemu_mem_path_options. (See my recent complaint about other misnamed options:
https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg01131.html)

Hi Erik,

It's Eric, but you're not the first to be affected by finger memory :)

Quoted 2 lines

What is the practical effect of the mismatch?

Harder to grep for things like 'mem.path' (to see both -mem-path strings and mem_path variable names) when looking for all places in the code base related to a given command line or QMP spelling.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
In reply to Marcelo Tosatti

Il 07/03/2014 01:40, Marcelo Tosatti ha scritto:

Quoted 5 lines

Failing initialization in case hugepage path has
hugepage smaller than specified.

Why is this needed? Isn't it just operator error?

Perhaps libvirt could add an attribute to its <hugepages/> XML element, and could use it to find the appropriate hugetlbfs mount. But I don't think this check belongs in QEMU.

Also, see the series I posted recently for a complete (and more powerful + more extensible) replacement of -mem-path and -mem-prealloc.

Paolo

Quoted 110 lines
exec.c +7 -0
index b69fd29..c95a0f3 100644
@@ -1034,6 +1034,13 @@ static void *file_ram_alloc(RAMBlock *block,
         return NULL;
     }
 
+    if (mem_path_min_hpagesize && hpagesize < mem_path_min_hpagesize) {
+        fprintf(stderr, "mount point (%s) has page size "
+                "(%ld) < (%ld) = min_hpagesize\n", path, hpagesize,
+                mem_path_min_hpagesize);
+        exit(1);
+    }
+
     if (memory < hpagesize) {
         return NULL;
     }
include/exec/cpu-all.h +1 -0
index 4cb4b4a..cc9e28a 100644
@@ -470,6 +470,7 @@ extern RAMList ram_list;
 
 extern const char *mem_path;
 extern int mem_prealloc;
+extern unsigned long int mem_path_min_hpagesize;
 
 /* Flags stored in the low bits of the TLB virtual address.  These are
    defined so that fast path ram access is all zeros.  */
qemu-options.hx +2 -2
index 56e5fdf..36743e1 100644
@@ -221,9 +221,9 @@ gigabytes respectively.
 ETEXI
 
 DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
-    "-mem-path FILE  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+    "-mem-path [mem-path=]file[,min-hpage-size=value]  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
 STEXI
-@item -mem-path @var{path}
+@item -mem-path [mem-path=]@var{path}[,min-hpage-size=@var{min-hpage-size}]
 @findex -mem-path
 Allocate guest RAM from a temporarily created file in @var{path}.
 ETEXI
vl.c +27 -2
index 1d27b34..08f9bee 100644
@@ -136,6 +136,7 @@ static int display_remote;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
+unsigned long int mem_path_min_hpagesize;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -479,6 +480,22 @@ static QemuOptsList qemu_msg_opts = {
     },
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
+    .implied_opt_name = "mem-path",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_mempath_opts.head),
+    .desc = {
+        {
+            .name = "mem-path",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "min-hpage-size",
+            .type = QEMU_OPT_SIZE,
+        },
+        { /* end of list */ }
+    },
+};
+
 /**
  * Get machine options
  *
@@ -2863,6 +2880,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_tpmdev_opts);
     qemu_add_opts(&qemu_realtime_opts);
     qemu_add_opts(&qemu_msg_opts);
+    qemu_add_opts(&qemu_mempath_opts);
 
     runstate_init();
 
@@ -3189,9 +3207,16 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
 #endif
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
+                mem_path = qemu_opt_get(opts, "mem-path");
+                mem_path_min_hpagesize = qemu_opt_get_size(opts,
+                                                           "min-hpage-size", 0);
                 break;
+            }
             case QEMU_OPTION_mem_prealloc:
                 mem_prealloc = 1;
                 break;
#5 lore raw
Quoted 9 lines · Paolo Bonzini

Il 07/03/2014 01:40, Marcelo Tosatti ha scritto:

Quoted 5 lines

Failing initialization in case hugepage path has
hugepage smaller than specified.

Why is this needed? Isn't it just operator error?

Libvirt can be responsible for setting up the hugetlbfs mount.

Are you suggesting that enforcement of this property be moved to the software on top of libvirt?

Quoted 3 lines

Perhaps libvirt could add an attribute to its <hugepages/> XML element, and could use it to find the appropriate hugetlbfs mount. But I don't think this check belongs in QEMU.

http://www.spinics.net/linux/fedora/libvir/msg92526.html

Quoted 116 lines

Also, see the series I posted recently for a complete (and more powerful + more extensible) replacement of -mem-path and -mem-prealloc.

Paolo

Quoted 110 lines
exec.c +7 -0
index b69fd29..c95a0f3 100644
@@ -1034,6 +1034,13 @@ static void *file_ram_alloc(RAMBlock *block,
        return NULL;
    }
 
+    if (mem_path_min_hpagesize && hpagesize < mem_path_min_hpagesize) {
+        fprintf(stderr, "mount point (%s) has page size "
+                "(%ld) < (%ld) = min_hpagesize\n", path, hpagesize,
+                mem_path_min_hpagesize);
+        exit(1);
+    }
+
    if (memory < hpagesize) {
        return NULL;
    }
include/exec/cpu-all.h +1 -0
index 4cb4b4a..cc9e28a 100644
@@ -470,6 +470,7 @@ extern RAMList ram_list;
 
 extern const char *mem_path;
 extern int mem_prealloc;
+extern unsigned long int mem_path_min_hpagesize;
 
 /* Flags stored in the low bits of the TLB virtual address.  These are
   defined so that fast path ram access is all zeros.  */
qemu-options.hx +0 -0
index 56e5fdf..36743e1 100644
@@ -221,9 +221,9 @@ gigabytes respectively.

ETEXI

DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,

qemu-options.hx +1 -1
-    "-mem-path FILE  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+    "-mem-path [mem-path=]file[,min-hpage-size=value]  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)

STEXI
-@item -mem-path @var{path}
+@item -mem-path [mem-path=]@var{path}[,min-hpage-size=@var{min-hpage-size}] @findex -mem-path
Allocate guest RAM from a temporarily created file in @var{path}. ETEXI

vl.c +1 -0
index 1d27b34..08f9bee 100644
@@ -136,6 +136,7 @@ static int display_remote;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
+unsigned long int mem_path_min_hpagesize;

int mem_prealloc = 0; /* force preallocation of physical target memory */ int nb_nics;
NICInfo nd_table[MAX_NICS];

vl.c +26 -2
@@ -479,6 +480,22 @@ static QemuOptsList qemu_msg_opts = {
    },
 };
 
+static QemuOptsList qemu_mempath_opts = {
+    .name = "mem-path",
+    .implied_opt_name = "mem-path",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_mempath_opts.head),
+    .desc = {
+        {
+            .name = "mem-path",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "min-hpage-size",
+            .type = QEMU_OPT_SIZE,
+        },
+        { /* end of list */ }
+    },
+};
+
 /**
 * Get machine options
 *
@@ -2863,6 +2880,7 @@ int main(int argc, char **argv, char **envp)
    qemu_add_opts(&qemu_tpmdev_opts);
    qemu_add_opts(&qemu_realtime_opts);
    qemu_add_opts(&qemu_msg_opts);
+    qemu_add_opts(&qemu_mempath_opts);
 
    runstate_init();
 
@@ -3189,9 +3207,16 @@ int main(int argc, char **argv, char **envp)
                }
                break;
 #endif
-            case QEMU_OPTION_mempath:
-                mem_path = optarg;
+            case QEMU_OPTION_mempath: {
+                opts = qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
+                mem_path = qemu_opt_get(opts, "mem-path");
+                mem_path_min_hpagesize = qemu_opt_get_size(opts,
+                                                           "min-hpage-size", 0);
                break;
+            }
            case QEMU_OPTION_mem_prealloc:
                mem_prealloc = 1;
                break;