<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 8 apr 2022 alle ore 16:36 Ferruh Yigit <<a href="mailto:ferruh.yigit@xilinx.com">ferruh.yigit@xilinx.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 4/8/2022 2:26 PM, Dmitry Kozlyuk wrote:<br>
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.<br>
> <br>
> <br>
> 2022-04-08 14:31 (UTC+0200), Antonio Di Bacco:<br>
>> I know that it is possible to share memory between a primary and secondary<br>
>> process using rte_memzone_reserve_aligned to allocate memory in primary<br>
>> that is "seen" also by the secondary. If we have two primary processes<br>
>> (started with different file-prefix) the same approach is not feasible. I<br>
>> wonder how to share a chunk of memory hosted on a hugepage between two<br>
>> primaries.<br>
>><br>
>> Regards.<br>
> <br>
> Hi Antonio,<br>
> <br>
> Correction: all hugepages allocated by DPDK are shared<br>
> between primary and secondary processes, not only memzones.<br>
> <br>
> I assume we're talking about processes within one host,<br>
> because your previous similar question was about sharing memory between hosts<br>
> (as we have discussed offline), which is out of scope for DPDK.<br>
> <br>
> As for the question directly, you need to map the same part of the same file<br>
> in the second primary as the hugepage is mapped from in the first primary.<br>
> I don't recommend to work with file paths, because their management<br>
> is not straightforward (--single-file-segments, for one) and is undocumented.<br>
> <br>
> There is a way to share DPDK memory segment file descriptors.<br>
> Although public, this DPDK API is dangerous in the sense that you must<br>
> clearly understand what you're doing and how DPDK works.<br>
> Hence the question: what is the task you need this sharing for?<br>
> Maybe there is a simpler way.<br>
> <br>
> 1. In the first primary:<br>
> <br>
>          mz = rte_memzone_reserve()<br>
>          ms = rte_mem_virt2memseg(mz->addr)<br>
>          fd = rte_memseg_get_fd(ms)<br>
>          offset = rte_memseg_get_fd_offset(ms)<br>
> <br>
> 2. Use Unix domain sockets with SCM_RIGHTS<br>
>     to send "fd" and "offset" to the second primary.<br>
> <br>
> 3. In the second primary, after receiving "fd" and "offset":<br>
> <br>
>          flags = MAP_SHARED | MAP_HUGE | (30 << MAP_HUGE_SHIFT)<br>
>          addr = mmap(fd, offset, flags)<br>
> <br>
> Note that "mz" may consist of multiple "ms" depending on the sizes<br>
> of the zone and hugepages, and on the zone alignment.<br>
> Also "addr" may (and probably will) differ from "mz->addr".<br>
> It is possible to pass "mz->addr" and try to force it,<br>
> like DPDK does for primary/secondary.<br>
> <br>
<br>
Also 'net/memif' driver can be used:<br>
<a href="https://doc.dpdk.org/guides/nics/memif.html" rel="noreferrer" target="_blank">https://doc.dpdk.org/guides/nics/memif.html</a></blockquote><div><br></div><div>Yes, I know about memif. Our application is currently using a chunk of shared memory, a primary process writes on it and a secondary reads from it.  Now the secondary will become a primary, sort of a promotion, and MEMIF would be fine but the paradigm should change a little bit compared to a shared memory approach. </div><div>MEMIF is an interface over a shared memory, we would need the opposite, a shared memory over a network interface.</div><div><br></div><div>Thank you.</div></div></div>