Skip to content

RAM_NORESERVE, MAP_NORESERVE and hostmem "reserve" property

David Hildenbrand qemu-devel 8 versions – Applied

Status from this message: Queued both the dependent series and this one, thanks. Sorry for the delay.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest15 patches 2 repliesApplied
  2. v715 patches 13 repliesSuperseded
  3. v615 patches 31 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v514 patches17 repliesSuperseded
v414 patches10 repliesSuperseded
v312 patches18 repliesSuperseded
v29 patches10 repliesSuperseded
v19 patches20 repliesSuperseded

Changes in v8 from the cover letter

- "hostmem: Wire up RAM_NORESERVE via "reserve" property"
-- Make the "reserve" property depend on CONFIG_LINUX
-- Add missing (since 6.1) to qom json
- "qmp: Include "reserve" property of memory backends"
-- Make the "reserve" value optional, depending on availability of the
"reserve" property
- "hmp: Print "reserve" property of memory backends with "info memdev"" -- Print only with "has_reserve"

Patches in v8 Applied

#Subject and filesSizeRepliesApplied
1/15util/mmap-alloc: Factor out calculation of the pagesize for the guard pageutil/mmap-alloc.c+16 -150 replies
2/15util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve()util/mmap-alloc.c+33 -250 replies
3/15util/mmap-alloc: Factor out activating of memory to mmap_activate()util/mmap-alloc.c+50 -440 replies
4/15softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd()backends/hostmem-memfd.c hw/misc/ivshmem.c include/exec/memory.h +2 more+13 -210 replies
5/15softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate()backends/hostmem-ram.c hw/m68k/next-cube.c include/exec/memory.h +2 more+31 -290 replies
6/15softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal()include/exec/ram_addr.h softmmu/memory.c softmmu/physmem.c+15 -200 replies
7/15util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap()include/qemu/mmap-alloc.h include/qemu/osdep.h softmmu/physmem.c +2 more+42 -180 replies
8/15memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()include/exec/cpu-common.h include/exec/memory.h include/exec/ram_addr.h +6 more+59 -130 replies
9/15util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linuxinclude/qemu/osdep.h softmmu/physmem.c util/mmap-alloc.c+71 -20 replies
10/15hostmem: Wire up RAM_NORESERVE via "reserve" propertybackends/hostmem-file.c backends/hostmem-memfd.c backends/hostmem-ram.c +3 more+55 -60 replies
11/15qmp: Clarify memory backend properties returned via query-memdevqapi/machine.json+3 -30 replies
12/15qmp: Include "share" property of memory backendshw/core/machine-qmp-cmds.c qapi/machine.json+4 -00 replies
13/15hmp: Print "share" property of memory backends with "info memdev"hw/core/machine-hmp-cmds.c+2 -00 replies
14/15qmp: Include "reserve" property of memory backendshw/core/machine-qmp-cmds.c qapi/machine.json+14 -00 replies
15/15hmp: Print "reserve" property of memory backends with "info memdev"hw/core/machine-hmp-cmds.c+4 -00 replies

Reviews trailers per patch

All 15 patches have a Reviewed-by or Acked-by.

PatchPeter XuMurilo Opsfelder AraujoEduardo HabkostIgor KotrasinskiRichard HendersonPhilippe Mathieu-DaudéMarkus ArmbrusterDr. David Alan Gilbert
1/15R-b A-b A-b
2/15R-b A-b A-b R-b R-b
3/15R-b A-b A-b R-b
4/15R-b A-b R-b
5/15R-b A-b R-b
6/15A-b R-b
7/15R-b A-b R-b
8/15R-b A-b R-b
9/15R-b A-b
10/15R-b R-b A-b R-b
11/15R-b A-b R-b R-b
12/15R-b A-b R-b R-b
13/15R-b A-b R-b R-b R-b
14/15R-b A-b R-b R-b
15/15R-b A-b R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 8 reviewers.

Read the v8 thread

Cover letter [PATCH v8 00/15] RAM_NORESERVE, MAP_NORESERVE and hostmem "reserve" property

Based-on: [email protected]

Some cleanups previously sent in other context (resizeable allocations), followed by RAM_NORESERVE, implementing it under Linux using MAP_NORESERVE, and letting users configure it for memory backens using the "reserve" property (default: true).

MAP_NORESERVE under Linux has in the context of QEMU an effect on
1) Private/shared anonymous memory
-> memory-backend-ram,id=mem0,size=10G
2) Private fd-based mappings
-> memory-backend-file,id=mem0,size=10G,mem-path=/dev/shm/0 -> memory-backend-memfd,id=mem0,size=10G
3) Private/shared hugetlb mappings
-> memory-backend-memfd,id=mem0,size=10G,hugetlb=on,hugetlbsize=2M

With MAP_NORESERVE/"reserve=off", we won't be reserving swap space (1/2) or huge pages (3) for the whole memory region.

The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. MAP_NORESERVE tells the OS "this mapping might be very sparse". This essentially allows avoiding having to set "/proc/sys/vm/overcommit_memory == 1") when using virtio-mem and also supporting hugetlbfs in the future.

Later, upper layers are expected to specify "reserve=off" only for memory backends assigned to virtio-mem devices, not all VM memory. To make mistakes by users less severe, we're, for example, working on preallocation of memory in virtio-mem itself, to be upstreamed later.

v7 -> v8:
- "hostmem: Wire up RAM_NORESERVE via "reserve" property"
-- Make the "reserve" property depend on CONFIG_LINUX
-- Add missing (since 6.1) to qom json
- "qmp: Include "reserve" property of memory backends"
-- Make the "reserve" value optional, depending on availability of the
"reserve" property
- "hmp: Print "reserve" property of memory backends with "info memdev"" -- Print only with "has_reserve"

v6 -> v7:
- Collected ACKs and RBs
- "hostmem: Wire up RAM_NORESERVE via "reserve" property" -- Extended qapi/qom.json documentation
- "qmp: Include "reserve" property of memory backends" -- Extended property description

v5 -> v6:
- "softmmu/memory: Pass ram_flags to memory_region_init ..." -- Split up into two patches
---> "softmmu/memory: Pass ram_flags to memory_region.." ---> "softmmu/memory: Pass ram_flags to qemu_ram_alloc() ..." -- Also set RAM_PREALLOC from qemu_ram_alloc_from_ptr()
- Collected acks/rbs

v4 -> v5:
- Sent out shared anonymous RAM fixes separately
- Rebased
- "hostmem: Wire up RAM_NORESERVE via "reserve" property" -- Adjusted/simplified description of new "reserve" property -- Properly add it to qapi/qom.json
- "qmp: Clarify memory backend properties returned via query-memdev" -- Added
- "qmp: Include "share" property of memory backends"
-- Added
- "hmp: Print "share" property of memory backends with "info memdev""
- Added
- "qmp: Include "reserve" property of memory backends"
-- Adjust description of new "reserve" property

v3 -> v4:
- Minor comment/description updates
- "softmmu/physmem: Fix ram_block_discard_range() to handle shared ..." -- Extended description
- "util/mmap-alloc: Pass flags instead of separate bools to ..." -- Move flags to include/qemu/osdep.h and rename to "QEMU_MAP_*"
- "memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()" -- Adjust to new flags. Handle errors in mmap_activate() for now.
- "util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux" -- Restrict support to Linux only for now
- "qmp: Include "reserve" property of memory backends"
-- Added
- "hmp: Print "reserve" property of memory backends with ..." -- Added

v2 -> v3:
- Renamed "softmmu/physmem: Drop "shared" parameter from ram_block_add()" to "softmmu/physmem: Mark shared anonymous memory RAM_SHARED" and adjusted the description
- Added "softmmu/physmem: Fix ram_block_discard_range() to handle shared anonymous memory"
- Added "softmmu/physmem: Fix qemu_ram_remap() to handle shared anonymous memory"
- Added "util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap()"
- "util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE" -- Further tweak code comments
-- Handle shared anonymous memory

v1 -> v2:
- Rebased to upstream and phs_mem_alloc simplifications
-- Upsteam added the "map_offset" parameter to many RAM allocation
interfaces.
- "softmmu/physmem: Drop "shared" parameter from ram_block_add()" -- Use local variable "shared"
- "memory: introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()" -- Simplify due to phs_mem_alloc changes
- "util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE" -- Add a whole bunch of comments.
-- Exclude shared anonymous memory that QEMU doesn't use -- Special-case readonly mappings

Cc Peter Xu <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Murilo Opsfelder Araujo <[email protected]>
Cc Greg Kurz <[email protected]>
Cc Liam Merwick <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
Cc Michal Privoznik <[email protected]>
Cc Marek Kedzierski <[email protected]>

David Hildenbrand (15):
util/mmap-alloc: Factor out calculation of the pagesize for the guard
page
util/mmap-alloc: Factor out reserving of a memory region to
mmap_reserve()
util/mmap-alloc: Factor out activating of memory to mmap_activate() softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() softmmu/memory: Pass ram_flags to
memory_region_init_ram_shared_nomigrate()
softmmu/memory: Pass ram_flags to qemu_ram_alloc() and
qemu_ram_alloc_internal()
util/mmap-alloc: Pass flags instead of separate bools to

    qemu_ram_mmap()

memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux
hostmem: Wire up RAM_NORESERVE via "reserve" property
qmp: Clarify memory backend properties returned via query-memdev
qmp: Include "share" property of memory backends
hmp: Print "share" property of memory backends with "info memdev"
qmp: Include "reserve" property of memory backends
hmp: Print "reserve" property of memory backends with "info memdev"

 backends/hostmem-file.c                       |  11 +-
 backends/hostmem-memfd.c                      |   8 +-
 backends/hostmem-ram.c                        |   7 +-
 backends/hostmem.c                            |  36 +++
 hw/core/machine-hmp-cmds.c                    |   6 +
 hw/core/machine-qmp-cmds.c                    |   8 +
 hw/m68k/next-cube.c                           |   4 +-
 hw/misc/ivshmem.c                             |   5 +-
 include/exec/cpu-common.h                     |   1 +
 include/exec/memory.h                         |  42 ++--
 include/exec/ram_addr.h                       |   9 +-
 include/qemu/mmap-alloc.h                     |  16 +-
 include/qemu/osdep.h                          |  30 ++-
 include/sysemu/hostmem.h                      |   2 +-
 migration/ram.c                               |   3 +-
 qapi/machine.json                             |  16 +-
 qapi/qom.json                                 |  10 +
 .../memory-region-housekeeping.cocci          |   8 +-
 softmmu/memory.c                              |  27 ++-
 softmmu/physmem.c                             |  51 +++--
 util/mmap-alloc.c                             | 212 +++++++++++++-----
 util/oslib-posix.c                            |   7 +-
 util/oslib-win32.c                            |  13 +-
 23 files changed, 374 insertions(+), 158 deletions(-)
Signature · 1 line
2.30.2