<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 8 apr 2022 alle ore 15:26 Dmitry Kozlyuk <<a href="mailto:dmitry.kozliuk@gmail.com">dmitry.kozliuk@gmail.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">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></blockquote><div><br></div><div><br></div><div>Thank you Dmitry, it is really incredible how deep your knowledge is. I will give it a try. </div></div></div>