Skip to content
  • David Hildenbrand's avatar
    09b3b7e0
    virtio-mem: Support "prealloc=on" option · 09b3b7e0
    David Hildenbrand authored
    
    
    For scarce memory resources, such as hugetlb, we want to be able to
    prealloc such memory resources in order to not crash later on access. On
    simple user errors we could otherwise easily run out of memory resources
    an crash the VM -- pretty much undesired.
    
    For ordinary memory devices, such as DIMMs, we preallocate memory via the
    memory backend for such use cases; however, with virtio-mem we're dealing
    with sparse memory backends; preallocating the whole memory backend
    destroys the whole purpose of virtio-mem.
    
    Instead, we want to preallocate memory when actually exposing memory to the
    VM dynamically, and fail plugging memory gracefully + warn the user in case
    preallocation fails.
    
    A common use case for hugetlb will be using "reserve=off,prealloc=off" for
    the memory backend and "prealloc=on" for the virtio-mem device. This
    way, no huge pages will be reserved for the process, but we can recover
    if there are no actual huge pages when plugging memory. Libvirt is
    already prepared for this.
    
    Note that preallocation cannot protect from the OOM killer -- which
    holds true for any kind of preallocation in QEMU. It's primarily useful
    only for scarce memory resources such as hugetlb, or shared file-backed
    memory. It's of little use for ordinary anonymous memory that can be
    swapped, KSM merged, ... but we won't forbid it.
    
    Reviewed-by: default avatarMichal Privoznik <mprivozn@redhat.com>
    Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    Message-Id: <20211217134611.31172-9-david@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    09b3b7e0
    virtio-mem: Support "prealloc=on" option
    David Hildenbrand authored
    
    
    For scarce memory resources, such as hugetlb, we want to be able to
    prealloc such memory resources in order to not crash later on access. On
    simple user errors we could otherwise easily run out of memory resources
    an crash the VM -- pretty much undesired.
    
    For ordinary memory devices, such as DIMMs, we preallocate memory via the
    memory backend for such use cases; however, with virtio-mem we're dealing
    with sparse memory backends; preallocating the whole memory backend
    destroys the whole purpose of virtio-mem.
    
    Instead, we want to preallocate memory when actually exposing memory to the
    VM dynamically, and fail plugging memory gracefully + warn the user in case
    preallocation fails.
    
    A common use case for hugetlb will be using "reserve=off,prealloc=off" for
    the memory backend and "prealloc=on" for the virtio-mem device. This
    way, no huge pages will be reserved for the process, but we can recover
    if there are no actual huge pages when plugging memory. Libvirt is
    already prepared for this.
    
    Note that preallocation cannot protect from the OOM killer -- which
    holds true for any kind of preallocation in QEMU. It's primarily useful
    only for scarce memory resources such as hugetlb, or shared file-backed
    memory. It's of little use for ordinary anonymous memory that can be
    swapped, KSM merged, ... but we won't forbid it.
    
    Reviewed-by: default avatarMichal Privoznik <mprivozn@redhat.com>
    Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    Message-Id: <20211217134611.31172-9-david@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Loading