From: Antonio Di Bacco <a.dibacco.ks@gmail.com>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Cc: users@dpdk.org
Subject: Re: Shared memory between two primary DPDK processes
Date: Mon, 18 Apr 2022 19:53:38 +0200 [thread overview]
Message-ID: <CAO8pfFktove500UAE1RuepxmA78d4hJCdAkHw8Dsxck9_dSpbQ@mail.gmail.com> (raw)
In-Reply-To: <CAO8pfFne4OF1caeFf2GE_XagYQJE8OmsSb8F-fWfVQ-KC_bMMQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3502 bytes --]
Another info to add:
The process that allocates the 1GB page has this map:
antodib@Ubuntu-20.04-5:: /proc> sudo cat /proc/27812/maps | grep huge
140000000-180000000 rw-s 00000000 00:46 97193
/dev/huge1G/rtemap_0
while the process that maps the 1GB page (--file-prefix p2) has this maps,
is stealing a new page?
antodib@Ubuntu-20.04-5:: /proc> sudo cat /proc/27906/maps | grep huge
140000000-180000000 rw-s 00000000 00:46 113170
/dev/huge1G/p2map_0
7f7bc0000000-7f7c00000000 rw-s 00000000 00:46 97193
/dev/huge1G/rtemap_0
Il giorno lun 18 apr 2022 alle ore 19:34 Antonio Di Bacco <
a.dibacco.ks@gmail.com> ha scritto:
> At the end I tried the pidfd_getfd syscall that is working really fine and
> giving me back a "clone" fd of an fd in that was opened from another
> process. I tested it opening a text file in the first process and after
> cloning the fd , I could really read the file also in the second process.
> Now the weird thing:
> 1) In the first process I allocate- a huge page, then get the fd
> 2) In the second process I get my "clone" fd and do an mmap, it works but
> if I write on that memory, the first process cannot see what I wrote
>
> int second_process(int remote_pid, int remote_mem_fd) {
>
> printf("remote_pid %d remote_mem_fd %d\n", remote_pid,
> remote_mem_fd);
> int pidfd = syscall(__NR_pidfd_open, remote_pid, 0);
>
> int my_mem_fd = syscall(438, pidfd, remote_mem_fd, 0);
> printf("my_mem_fd %d\n", my_mem_fd); // This is nice
>
> int flags = MAP_SHARED | MAP_HUGETLB | (30 << MAP_HUGE_SHIFT);
> uint64_t* addr = (uint64_t*) mmap(NULL, 1024 * 1024 * 1024,
> PROT_READ|PROT_WRITE, flags, my_mem_fd, 0);
> if (addr == -1)
> perror("mmap");
> *addr = 0x0101010102020202;
> }
>
>
> Il giorno gio 14 apr 2022 alle ore 21:51 Antonio Di Bacco <
> a.dibacco.ks@gmail.com> ha scritto:
>
>>
>>
>> Il giorno gio 14 apr 2022 alle ore 21:01 Dmitry Kozlyuk <
>> dmitry.kozliuk@gmail.com> ha scritto:
>>
>>> 2022-04-14 10:20 (UTC+0200), Antonio Di Bacco:
>>> [...]
>>> > Ok, after having a look to memif I managed to exchange the fd between
>>> the
>>> > two processes and it works.
>>> > Anyway the procedure seems a little bit clunky and I think I'm going
>>> to use
>>> > the new SYSCALL pidfd_getfd
>>> > to achieve the same result. In your opinion this method (getfd_pidfd)
>>> > could also work if the two DPDK processes
>>> > are inside different docker containers?
>>>
>>> Honestly, I've just learned about pidfd_getfd() from you.
>>> But I know that containers use PID namespaces, so there's a question
>>> how you will obtain the pidfd of a process in another container.
>>>
>>> In general, any method of sharing FD will work.
>>> Remember that you also need offset and size.
>>> Given that some channel is required to share those,
>>> I think Unix domain socket is still the preferred way.
>>>
>>> > Or is there another mechanims like using handles to hugepages present
>>> in
>>> > the filesystem to share between two
>>> > different containers?
>>>
>>> FD is needed for mmap().
>>> You need to either pass the FD or open() the same hugepage file by path.
>>> I advise against using paths because they are not a part of DPDK API
>>> contract.
>>>
>>
>> Thank you very much Dmitry, your answers are always enlightening.
>> I'm going to ask a different question on the dpdk.org about the best
>> practice to share memory between two dpdk processes running in different
>> containers.
>>
>
[-- Attachment #2: Type: text/html, Size: 4887 bytes --]
next prev parent reply other threads:[~2022-04-18 17:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 12:31 Antonio Di Bacco
2022-04-08 13:26 ` Dmitry Kozlyuk
2022-04-08 14:36 ` Ferruh Yigit
2022-04-08 21:14 ` Antonio Di Bacco
2022-04-08 21:08 ` Antonio Di Bacco
2022-04-11 13:03 ` Antonio Di Bacco
2022-04-11 17:30 ` Dmitry Kozlyuk
2022-04-14 8:20 ` Antonio Di Bacco
2022-04-14 19:01 ` Dmitry Kozlyuk
2022-04-14 19:51 ` Antonio Di Bacco
2022-04-18 17:34 ` Antonio Di Bacco
2022-04-18 17:53 ` Antonio Di Bacco [this message]
2022-04-18 19:08 ` Dmitry Kozlyuk
2022-07-06 22:14 ` Antonio Di Bacco
2022-07-07 0:26 ` Dmitry Kozlyuk
2022-07-07 8:48 ` Antonio Di Bacco
2022-07-07 9:26 ` Dmitry Kozlyuk
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=CAO8pfFktove500UAE1RuepxmA78d4hJCdAkHw8Dsxck9_dSpbQ@mail.gmail.com \
--to=a.dibacco.ks@gmail.com \
--cc=dmitry.kozliuk@gmail.com \
--cc=users@dpdk.org \
/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).