Skip to contentSkip to conversation

system/physmem: Improve guest memory allocation failure diagnostics

PATCH Applied Bin Meng 3 participants 4 messages Aug 22 – Aug 24

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v2 cover system/physmem: Improve guest memory allocation failure diagnostics

This revives Philippe Mathieu-Daudé's patch from 2021. The original posting and discussion are available at:

https://lore.kernel.org/r/[email protected]

When host memory allocation fails, QEMU reports the affected memory region and host error, but not the size of the failed allocation. This makes accidental requests harder to spot. In particular, a bare value passed to '-m' is interpreted as MiB, so a user expecting bytes can unintentionally request tens of TiB.

The patch adds the human-readable RAMBlock size to the existing error. This does not try to explain host-specific overcommit, cgroup, or NUMA policy. It provides the most useful portable fact available at the failure site and makes both user mistakes and support reports easier to diagnose.

Changes in v2:
- Rebase onto current master
- Update the source path from softmmu/physmem.c to system/physmem.c
- Fix a typo in the commit message
- Collect Peter Xu's Reviewed-by and Bin Meng's Tested-by

Philippe Mathieu-Daudé (1):
system/physmem: Improve guest memory allocation failure error message

 system/physmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

---
base-commit: eea8fe61b8be8f3016e522e6af24924a0266ca95
branch: virt

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v2 1/1 system/physmem: Improve guest memory allocation failure error message

From: Philippe Mathieu-Daudé <[email protected]>

When Linux refuses to overcommit a seriously wild allocation we get:

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: cannot set up guest memory 'pc.ram':
  Cannot allocate memory

Slightly improve the error message, displaying the memory size requested (in case the user didn't expect unspecified memory size unit is in MiB):

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: Cannot set up 38.1 TiB of guest memory 'pc.ram':
  Cannot allocate memory

---

Changes in v2:
- Rebase onto current master
- Update the source path from softmmu/physmem.c to system/physmem.c
- Fix a typo in the commit message
- Collect Peter Xu's Reviewed-by and Bin Meng's Tested-by

 system/physmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
system/physmem.c +3 -1
index 362a00f76c..89ce6479f1 100644
@@ -2171,8 +2171,10 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
                                                   &new_block->mr->align,
                                                   shared, noreserve);
             if (!new_block->host) {
+                g_autofree char *size_s = size_to_str(new_block->max_length);
                 error_setg_errno(errp, errno,
-                                 "cannot set up guest memory '%s'",
+                                 "Cannot set up %s of guest memory '%s'",
+                                 size_s,
                                  memory_region_name(new_block->mr));
                 qemu_mutex_unlock_ramlist();
                 return;
Signature · 1 line
2.53.0
Applied
#2 lore raw

Re: [PATCH v2 1/1] system/physmem: Improve guest memory allocation failure error message

Quoted 22 lines · Bin Meng

From: Philippe Mathieu-Daudé <[email protected]>

When Linux refuses to overcommit a seriously wild allocation we get:

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: cannot set up guest memory 'pc.ram':
  Cannot allocate memory

Slightly improve the error message, displaying the memory size requested (in case the user didn't expect unspecified memory size unit is in MiB):

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: Cannot set up 38.1 TiB of guest memory 'pc.ram':
  Cannot allocate memory
Quoted 7 lines

---

Changes in v2:
- Rebase onto current master
- Update the source path from softmmu/physmem.c to system/physmem.c
- Fix a typo in the commit message
- Collect Peter Xu's Reviewed-by and Bin Meng's Tested-by

queued, thanks.

Signature · 1 line
Peter Xu
Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2 1/1] system/physmem: Improve guest memory allocation failure error message

In reply to Bin Meng
Quoted 22 lines · Bin Meng

From: Philippe Mathieu-Daudé <[email protected]>

When Linux refuses to overcommit a seriously wild allocation we get:

   $ qemu-system-i386 -m 40000000
   qemu-system-i386: cannot set up guest memory 'pc.ram':
   Cannot allocate memory

Slightly improve the error message, displaying the memory size requested (in case the user didn't expect unspecified memory size unit is in MiB):

   $ qemu-system-i386 -m 40000000
   qemu-system-i386: Cannot set up 38.1 TiB of guest memory 'pc.ram':
   Cannot allocate memory
Quoted 7 lines

---

Changes in v2:
- Rebase onto current master
- Update the source path from softmmu/physmem.c to system/physmem.c
- Fix a typo in the commit message
- Collect Peter Xu's Reviewed-by and Bin Meng's Tested-by

Thanks! :)

Quoted 3 lines
  system/physmem.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)