DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Shahaf Shuler <shahafs@mellanox.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: Olga Shern <olgas@mellanox.com>,
	Yongseok Koh <yskoh@mellanox.com>,
	"pawelx.wodkowski@intel.com" <pawelx.wodkowski@intel.com>,
	"gowrishankar.m@linux.vnet.ibm.com"
	<gowrishankar.m@linux.vnet.ibm.com>,
	"ferruh.yigit@intel.com" <ferruh.yigit@intel.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	"arybchenko@solarflare.com" <arybchenko@solarflare.com>,
	"shreyansh.jain@nxp.com" <shreyansh.jain@nxp.com>
Subject: Re: [dpdk-dev] [RFC] ethdev: introduce DMA memory mapping for external memory
Date: Wed, 14 Nov 2018 17:06:14 +0000	[thread overview]
Message-ID: <6c7243cd-5370-846b-2999-5ae34722f640@intel.com> (raw)
In-Reply-To: <DB7PR05MB442617F5BEE7251AAD8836A6C3C30@DB7PR05MB4426.eurprd05.prod.outlook.com>

On 14-Nov-18 2:53 PM, Shahaf Shuler wrote:
> Hi Anatoly,
> 
> Wednesday, November 14, 2018 1:19 PM, Burakov, Anatoly:
>> Subject: Re: [RFC] ethdev: introduce DMA memory mapping for external
>> memory
>>
>> Hi Shahaf,
>>
>> Great to see such effort! Few comments below.
>>
>> Note: halfway through writing my comments i realized that i am starting with
>> an assumption that this API is a replacement for current VFIO DMA mapping
>> API's. So, if my comments seem out of left field, this is probably why :)
>>
>> On 04-Nov-18 12:41 PM, Shahaf Shuler wrote:
>>> Request for comment on the high level changes present on this patch.
>>>
>>> The need to use external memory (memory belong to application and not
>>> part of the DPDK hugepages) is allready present.
>>> Starting from storage apps which prefer to manage their own memory
>>> blocks for efficient use of the storage device. Continue with GPU
>>> based application which strives to achieve zero copy while processing
>>> the packet payload on the GPU core. And finally by vSwitch/vRouter
>>> application who just prefer to have a full control over the memory in use
>> (e.g. VPP).
>>>
>>> Recent work[1] in the DPDK enabled the use of external memory, however
>>> it mostly focus on VFIO as the only way to map memory.
>>> While VFIO is common, there are other vendors which use different ways
>>> to map memory (e.g. Mellanox and NXP[2]).
>>>
>>> The work in this patch moves the DMA mapping to vendor agnostic APIs
>>> located under ethdev. The choice in ethdev was because memory map
>>> should be associated with a specific port(s). Otherwise the memory is
>>> being mapped multiple times to different frameworks and ends up with
>>> memory being wasted on redundant translation table in the host or in the
>> device.
>>
>> So, anything other than ethdev (e.g. cryptodev) will not be able to map
>> memory for DMA?
> 
> That's is a fair point.
> 
>>
>> I have thought about this for some length of time, and i think DMA mapping
>> belongs in EAL (more specifically, somewhere at the bus layer), rather than at
>> device level.
> 
> I am not sure I agree here. For example take Intel and Mellanox devices. Both are PCI devices, so how will you distinguish which mapping API to use?
> Also I still think the mapping should be in device granularity and not bus/system granularity, since it is very typical for a memory to be used for DMA be a specific device.
> 
> Maybe we can say the DMA mapping is a rte_device attribute. It is the parent class for all the DPDK devices.
> We need to see w/ vport representors (which all has the same rte_device). On that case I believe the rte_device.map call can register the memory to all of the representors as well (if needed).
> 
> Placing this functionality at device level comes with more work
>> to support different device types and puts a burden on device driver
>> developers to implement their own mapping functions.
> 
> The mapping function can be shared. For example we can still maintain the vfio mapping scheme as part of eal and have all the related driver to call this function.
> The only overhead will be to maintain the function pointer for the dma call.
> With this work, instead of the eal layer to guess which type of DMA mapping the devices in the  system needs or alternatively force them all to work w/ VFIO, each driver will select its own function.
> The driver is the only one which knows what type of DMA mapping its device needs.
> 
>>
>> However, i have no familiarity with how MLX/NXP devices do their DMA
>> mapping, so maybe the device-centric approach would be better. We could
>> provide "standard" mapping functions at the bus level (such as VFIO mapping
>> functions for PCI bus), so that this could would not have to be
>> reimplemented in the devices.
> 
> Yes, like I said above, I wasn't intending to re-implement all the mapping function again on each driver. Yet, I believe it should be per device.
> 
>>
>> Moreover, i'm not sure how this is going to work for VFIO. If this is to be
>> called for each NIC that needs access to the memory, then we'll end up with
>> double mappings for any NIC that uses VFIO, unless you want each NIC to be
>> in a separate container.
> 
> I am not much familiar w/ VFIO (you are the expert😊).
> What will happen if we map the same memory twice (under same container)? The translation on the IOMMU will be doubled? The map will return with error that this memory mapping already exists?

The latter. You can't map the same memory twice in the same container. 
You can't even keep NICs in separate containers because then secondary 
processes won't work without serious rework.

So, all VFIO-mapped things will need to share the mappings.

It's not an insurmountable problem, but if we're going to share mapping 
status for VFIO (i.e. track which area is already mapped), then what's 
stopping us from doing the same for other DMA mapping mechanisms? I.e. 
instead of duplicating the mappings in each driver, provide some kind of 
mechanism for devices to share the DMA mapping caches. Apologies if i'm 
talking nonsense - i'm completely unfamiliar with how DMA mapping works 
for MLX/NXP devices :)

> 
>>
>>>
>>> For example, consider a host with Mellanox and Intel devices. Mapping a
>>> memory without specifying to which port will end up with IOMMU
>>> registration and Verbs (Mellanox DMA map) registration.
>>> Another example can be two Mellanox devices on the same host. The
>> memory
>>> will be mapped for both, even though application will use mempool per
>>> device.
>>>
>>> To use the suggested APIs the application will allocate a memory block
>>> and will call rte_eth_dma_map. It will map it to every port that needs
>>> DMA access to this memory.
>>
>> This bit is unclear to me. What do you mean "map it to every port that
>> needs DMA access to this memory"? I don't see how this API solves the
>> above problem of mapping the same memory to all devices. How does a
>> device know which memory it will need? Does the user specifically have
>> to call this API for each and every NIC they're using?
> 
> Yes, the user will call this API for every port which needs to have DMA access to this memory.
> Remember we are speaking here on external memory the application allocated and wants to use for send/receive.  The device doesn't guess which memory he will need, the user is telling it to him explicitly.
> 
>>
>> For DPDK-managed memory, everything will still get mapped to every
>> device automatically, correct?
> 
> Yes, even though it is not the case today.

What do you mean it is not the case? It is the case today. When external 
memory chunk is registered at the heap, a mem event callback is 
triggered just like for regular memory, and this chunk does get mapped 
to VFIO as well as any other subscribed entity. As i recall, NXP NICs 
currently are set up to ignore externally allocated memory, but for the 
general VFIO case, everything is mapped automatically.

> 
> If so, then such a manual approach for
>> external memory will be bad for both usability and drop-in replacement
>> of internal-to-external memory, because it introduces inconsistency
>> between using internal and external memory. From my point of view,
>> either we do *everything* manually (i.e. register all memory for DMA
>> explicitly) and thereby avoid this problem but keep the consistency, or
>> we do *everything* automatically and deal with duplication of mappings
>> somehow (say, by MLX/NXP drivers sharing their mappings through bus
>> interface).
> 
> I understand your point, however I am not sure external and internal memory *must* be consist.
> The DPDK-managed memory is part of the DPDK subsystems and the DPDK libs are preparing it for the optimal use of the underlying devices. The external memory is different, it is a proprietary memory the application allocated and the DPDK cannot do anything in advance on it.

My view for designing external memory support was that it should behave 
like regular DPDK memory for all intents and purposes, and be a drop-in 
replacement, should you choose to use it. I.e. the application should 
not care whether it uses internal or external memory - it all sits in 
the same malloc heaps, it all uses the same socket ID mechanisms, etc. - 
for all intents and purposes, they're one and the same.

> Even today there is inconsistency, because if user wants to use external memory it must map it (rte_vfio_dma_map) while he doesn't need to do that for the DPDK-managed memory.

Well, now i see where your confusion stems from :) You didn't know about 
this:

http://git.dpdk.org/dpdk/tree/lib/librte_eal/common/malloc_heap.c#n1169

This will trigger all mem event callbacks, including VFIO DMA mapping 
callback.

> 
> I guess we can we can add a flag on the device mapping which will say MAP_TO_ALL_DEVICES, to ease the application life in the presence of multiple device in the host.
> 


-- 
Thanks,
Anatoly

  reply	other threads:[~2018-11-14 17:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-04 12:41 Shahaf Shuler
2018-11-14 11:19 ` Burakov, Anatoly
2018-11-14 14:53   ` Shahaf Shuler
2018-11-14 17:06     ` Burakov, Anatoly [this message]
2018-11-15  9:46       ` Shahaf Shuler
2018-11-15 10:59         ` Burakov, Anatoly
2018-11-19 11:20           ` Shahaf Shuler
2018-11-19 17:18             ` Burakov, Anatoly
     [not found]               ` <DB7PR05MB442643DFD33B71797CD34B5EC3D90@DB7PR05MB4426.eurprd05.prod.outlook.com>
2018-11-20 10:55                 ` Burakov, Anatoly
2018-11-22 10:06                   ` Shahaf Shuler
2018-11-22 10:41                     ` Burakov, Anatoly
2018-11-22 11:31                       ` Shahaf Shuler
2018-11-22 11:34                         ` Burakov, Anatoly
2019-01-14  6:12                         ` Shahaf Shuler
2019-01-15 12:07                           ` Burakov, Anatoly
2019-01-16 11:04                             ` Shahaf Shuler
2018-11-19 17:04           ` Stephen Hemminger

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=6c7243cd-5370-846b-2999-5ae34722f640@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gowrishankar.m@linux.vnet.ibm.com \
    --cc=olgas@mellanox.com \
    --cc=pawelx.wodkowski@intel.com \
    --cc=shahafs@mellanox.com \
    --cc=shreyansh.jain@nxp.com \
    --cc=thomas@monjalon.net \
    --cc=yskoh@mellanox.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).