From: David Hildenbrand <david@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>,
Wei Yang <richard.weiyang@linux.alibaba.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Auger Eric <eric.auger@redhat.com>,
teawater <teawaterz@linux.alibaba.com>,
Igor Mammedov <imammedo@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
Marek Kedzierski <mkedzier@redhat.com>
Subject: Re: [PATCH v1 4/9] vfio: Support for RamDiscardMgr in the !vIOMMU case
Date: Thu, 3 Dec 2020 11:07:42 +0100 [thread overview]
Message-ID: <dc19808f-61f6-4ccc-1d23-12e4af1c8fec@redhat.com> (raw)
In-Reply-To: <20201202162633.27cb15b6@w520.home>
On 03.12.20 00:26, Alex Williamson wrote:
> On Thu, 19 Nov 2020 16:39:13 +0100
> David Hildenbrand <david@redhat.com> wrote:
>
>> Implement support for RamDiscardMgr, to prepare for virtio-mem
>> support. Instead of mapping the whole memory section, we only map
>> "populated" parts and update the mapping when notified about
>> discarding/population of memory via the RamDiscardListener. Similarly, when
>> syncing the dirty bitmaps, sync only the actually mapped (populated) parts
>> by replaying via the notifier.
>>
>> Small mapping granularity is problematic for vfio, because we might run out
>> of mappings. Warn to at least make users aware that there is such a
>> limitation and that we are dealing with a setup issue e.g., of
>> virtio-mem devices.
>>
>> Using virtio-mem with vfio is still blocked via
>> ram_block_discard_disable()/ram_block_discard_require() after this patch.
>>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
>> Cc: Peter Xu <peterx@redhat.com>
>> Cc: Auger Eric <eric.auger@redhat.com>
>> Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
>> Cc: teawater <teawaterz@linux.alibaba.com>
>> Cc: Marek Kedzierski <mkedzier@redhat.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> hw/vfio/common.c | 233 ++++++++++++++++++++++++++++++++++
>> include/hw/vfio/vfio-common.h | 12 ++
>> 2 files changed, 245 insertions(+)
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index c1fdbf17f2..d52e7356cb 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
> ...
>> +static void vfio_register_ram_discard_notifier(VFIOContainer *container,
>> + MemoryRegionSection *section)
>> +{
>> + RamDiscardMgr *rdm = memory_region_get_ram_discard_mgr(section->mr);
>> + RamDiscardMgrClass *rdmc = RAM_DISCARD_MGR_GET_CLASS(rdm);
>> + MachineState *ms = MACHINE(qdev_get_machine());
>> + uint64_t suggested_granularity;
>> + VFIORamDiscardListener *vrdl;
>> + int ret;
>> +
>> + vrdl = g_new0(VFIORamDiscardListener, 1);
>> + vrdl->container = container;
>> + vrdl->mr = section->mr;
>> + vrdl->offset_within_region = section->offset_within_region;
>> + vrdl->offset_within_address_space = section->offset_within_address_space;
>> + vrdl->size = int128_get64(section->size);
>> + vrdl->granularity = rdmc->get_min_granularity(rdm, section->mr);
>> +
>> + /* Ignore some corner cases not relevant in practice. */
>> + g_assert(QEMU_IS_ALIGNED(vrdl->offset_within_region, TARGET_PAGE_SIZE));
>> + g_assert(QEMU_IS_ALIGNED(vrdl->offset_within_address_space,
>> + TARGET_PAGE_SIZE));
>> + g_assert(QEMU_IS_ALIGNED(vrdl->size, TARGET_PAGE_SIZE));
>> +
>> + /*
>> + * We assume initial RAM never has a RamDiscardMgr and that all memory
>> + * to eventually get hotplugged later could be coordinated via a
>> + * RamDiscardMgr ("worst case").
>> + *
>> + * We assume the Linux kernel is configured ("dma_entry_limit") for the
>> + * maximum of 65535 mappings and that we can consume roughly half of that
>
>
> s/maximum/default/
>
> Deciding we should only use half of it seems arbitrary.
Yeah, it's sub-optimal - bad heuristic :) . What would be your
suggestion for a better heuristic? My gut feeling would be that we
rarely use more than 512 mappings in the system address space (e.g.,
maximum number of DIMMs is 256).
>
>
>> + * for this purpose.
>> + *
>> + * In reality, we might also have RAM without a RamDiscardMgr in our device
>> + * memory region and might be able to consume more mappings.
>> + */
>> + suggested_granularity = pow2ceil((ms->maxram_size - ms->ram_size) / 32768);
>> + suggested_granularity = MAX(suggested_granularity, 1 * MiB);
>> + if (vrdl->granularity < suggested_granularity) {
>> + warn_report("%s: eventually problematic mapping granularity (%" PRId64
>> + " MiB) with coordinated discards (e.g., 'block-size' in"
>> + " virtio-mem). Suggested minimum granularity: %" PRId64
>> + " MiB", __func__, vrdl->granularity / MiB,
>> + suggested_granularity / MiB);
>> + }
>
>
> Starting w/ kernel 5.10 we have a way to get the instantaneous count of
> available DMA mappings, so we could avoid assuming 64k when that's
> available (see ex. s390_pci_update_dma_avail()).
Interesting, I missed that interface. Will have a look. TThanks!
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2020-12-03 10:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 15:39 [PATCH v1 0/9] virtio-mem: vfio support David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 1/9] memory: Introduce RamDiscardMgr for RAM memory regions David Hildenbrand
2020-12-02 23:26 ` Alex Williamson
2020-12-03 10:04 ` David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 2/9] virtio-mem: Factor out traversing unplugged ranges David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 3/9] virtio-mem: Implement RamDiscardMgr interface David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 4/9] vfio: Support for RamDiscardMgr in the !vIOMMU case David Hildenbrand
2020-12-02 23:26 ` Alex Williamson
2020-12-03 10:07 ` David Hildenbrand [this message]
2020-11-19 15:39 ` [PATCH v1 5/9] vfio: Support for RamDiscardMgr in the vIOMMU case David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 6/9] softmmu/physmem: Don't use atomic operations in ram_block_discard_(disable|require) David Hildenbrand
2020-11-19 20:34 ` Peter Xu
2020-11-19 15:39 ` [PATCH v1 7/9] softmmu/physmem: Extend ram_block_discard_(require|disable) by two discard types David Hildenbrand
2020-11-19 15:39 ` [PATCH v1 8/9] virtio-mem: Require only coordinated discards David Hildenbrand
2020-11-30 17:20 ` Dr. David Alan Gilbert
2020-11-19 15:39 ` [PATCH v1 9/9] vfio: Disable only uncoordinated discards David Hildenbrand
2020-11-23 11:31 ` [PATCH v1 0/9] virtio-mem: vfio support David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc19808f-61f6-4ccc-1d23-12e4af1c8fec@redhat.com \
--to=david@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eric.auger@redhat.com \
--cc=imammedo@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mkedzier@redhat.com \
--cc=mst@redhat.com \
--cc=pankaj.gupta.linux@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.weiyang@linux.alibaba.com \
--cc=teawaterz@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).