All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] RAM_NORESERVE, MAP_NORESERVE and hostmem "reserve" property
@ 2021-03-05 10:16 David Hildenbrand
  2021-03-05 10:16 ` [PATCH v2 1/9] softmmu/physmem: Drop "shared" parameter from ram_block_add() David Hildenbrand
                   ` (8 more replies)
  0 siblings, 9 replies; 22+ messages in thread
From: David Hildenbrand @ 2021-03-05 10:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Juan Quintela, Murilo Opsfelder Araujo, Cornelia Huck,
	Eduardo Habkost, Michael S. Tsirkin, Stefan Weil,
	David Hildenbrand, Richard Henderson, Dr. David Alan Gilbert,
	Peter Xu, Greg Kurz, Halil Pasic, Christian Borntraeger,
	Stefan Hajnoczi, Igor Mammedov, Thomas Huth, Paolo Bonzini,
	Philippe Mathieu-Daudé,
	Igor Kotrasinski

Some cleanups previously sent in other context (resizeable allocations),
followed by RAM_NORESERVE, implementing it under POSIX 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 anonymous memory
-> memory-backend-ram,id=mem0,size=10G
2) Private file-based mappings
-> memory-backend-file,id=mem0,size=10G,mem-path=/dev/shm/0
3) Private/shared hugetlbfs memory
-> 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 to set "/proc/sys/vm/overcommit_memory == 1") when using
virtio-mem and also supporting hugetlbfs in the future.

virtio-mem currently only supports anonymous memory, in the future we want
to also support private memfd, shared file-based and shared hugetlbfs
mappings.

virtio-mem features I am currently working on include:
1. Introducing a prealloc option for virtio-mem (e.g., using fallocate()
   when plugging blocks) to fail nicely when running out of
   backing storage like huge pages.
2. Supporting resizable RAM block/memmory regions, such that we won't
   always expose a large, sparse memory region to the VM.
3. Handling virtio-mem requests via an iothread to not hold the BQL while
   populating/preallocating memory
4. Protecting unplugged memory e.g., using userfaultfd.
5. (resizeable allocations / optimized mmap handling when resizing RAM
    blocks)

Based-on: 20210303130916.22553-1-david@redhat.com

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 <peterx@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Cc: Greg Kurz <groug@kaod.org>
Cc: Liam Merwick <liam.merwick@oracle.com>


David Hildenbrand (9):
  softmmu/physmem: Drop "shared" parameter from ram_block_add()
  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 into qemu_ram_alloc_from_fd()
  softmmu/memory: Pass ram_flags into
    memory_region_init_ram_shared_nomigrate()
  memory: introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()
  util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE
  hostmem: Wire up RAM_NORESERVE via "reserve" property

 backends/hostmem-file.c                       |  11 +-
 backends/hostmem-memfd.c                      |   8 +-
 backends/hostmem-ram.c                        |   7 +-
 backends/hostmem.c                            |  33 +++
 hw/m68k/next-cube.c                           |   4 +-
 hw/misc/ivshmem.c                             |   5 +-
 include/exec/cpu-common.h                     |   1 +
 include/exec/memory.h                         |  43 ++--
 include/exec/ram_addr.h                       |   9 +-
 include/qemu/mmap-alloc.h                     |   2 +
 include/qemu/osdep.h                          |   3 +-
 include/sysemu/hostmem.h                      |   2 +-
 migration/ram.c                               |   3 +-
 .../memory-region-housekeeping.cocci          |   8 +-
 softmmu/memory.c                              |  27 ++-
 softmmu/physmem.c                             |  41 ++--
 util/mmap-alloc.c                             | 220 ++++++++++++------
 util/oslib-posix.c                            |   6 +-
 util/oslib-win32.c                            |  13 +-
 19 files changed, 299 insertions(+), 147 deletions(-)

-- 
2.29.2



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2021-03-08  8:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 10:16 [PATCH v2 0/9] RAM_NORESERVE, MAP_NORESERVE and hostmem "reserve" property David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 1/9] softmmu/physmem: Drop "shared" parameter from ram_block_add() David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 2/9] util/mmap-alloc: Factor out calculation of the pagesize for the guard page David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 3/9] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 4/9] util/mmap-alloc: Factor out activating of memory to mmap_activate() David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 5/9] softmmu/memory: Pass ram_flags into qemu_ram_alloc_from_fd() David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 6/9] softmmu/memory: Pass ram_flags into memory_region_init_ram_shared_nomigrate() David Hildenbrand
2021-03-05 10:16 ` [PATCH v2 7/9] memory: introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() David Hildenbrand
2021-03-05 10:16   ` David Hildenbrand
2021-03-05 15:37   ` Peter Xu
2021-03-05 15:37     ` Peter Xu
2021-03-05 10:16 ` [PATCH v2 8/9] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE David Hildenbrand
2021-03-05 15:42   ` Peter Xu
2021-03-05 15:44     ` David Hildenbrand
2021-03-05 15:51       ` Peter Xu
2021-03-05 16:24         ` David Hildenbrand
2021-03-07 13:18         ` David Hildenbrand
2021-03-07 14:11           ` Marcel Apfelbaum
2021-03-08  8:45             ` David Hildenbrand
2021-03-08  8:54               ` Marcel Apfelbaum
2021-03-05 10:16 ` [PATCH v2 9/9] hostmem: Wire up RAM_NORESERVE via "reserve" property David Hildenbrand
2021-03-05 22:14   ` Eduardo Habkost

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.