common/mlx5: adjust fork call with the new kernel API
PATCH 1/1 common/mlx5: adjust fork call with the new kernel API
From: Erez Ferber <[email protected]>
While doing process fork() the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.
The ibv_fork_init() prepares the library to track all the related memory and prevent it from forking using madvise() system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.
The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine ibv_is_fork_initialized() should be involved to decide if library initialization for forking is required.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 4 ++++ 2 files changed, 6 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -219,6 +219,8 @@ has_sym_args = [ 'ibv_import_device' ], [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h', 'mlx5dv_dr_action_create_dest_root_table' ], + [ 'HAVE_IBV_FORK_UNNEEDED', 'infiniband/verbs.h', + 'ibv_is_fork_initialized'], ] if libmtcr_ul_found has_sym_args += [
drivers/common/mlx5/linux/mlx5_glue.c +4 -0
@@ -19,6 +19,10 @@static int mlx5_glue_fork_init (void ) { +#ifdef HAVE_IBV_FORK_UNNEEDED +if (ibv_is_fork_initialized () ==IBV_FORK_UNNEEDED ) +return 0 ;/* ibv_fork_init() not needed */ +#endif return ibv_fork_init (); }
Signature · 1 line
2.14.1
Quoted 16 lines · On Wed, 24 May 2023 15:01:40 +0300 <[email protected]> wrote:
From: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.
Quoted 8 lines
The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking is required.Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separate file")Signed-off-by Erez Ferber <[email protected]>
I don't think DPDK applications should fork(), and lots other parts of the shared huge pages will break if an application does this.
Quoted 10 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, May 24, 2023 5:50 PM
To: Erez Ferber <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [PATCH] common/mlx5: adjust fork call with the new kernel API
Quoted 28 lines
Quoted 24 lines · On Wed, 24 May 2023 15:01:40 +0300 <[email protected]> wrote:
From: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking is required.Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separate file")Signed-off-by Erez Ferber <[email protected]>
Hi,
Quoted 2 lines
I don't think DPDK applications should
fork(), and lots other parts of the shared huge pages will break if an application does this.
I agree - application should not, we have the secondary/primary processes approach. Nonetheless, we have the real use case - DPDK application does fork() and works well. Without mlx5 PMD 😊. With mlx5 it ran into some troubles. Now we have the solution.
With best regards,
Slava
Quoted 37 lines · On Thu, 25 May 2023 08:10:03 +0000 Slava Ovsiienko <[email protected]>…
Quoted 9 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, May 24, 2023 5:50 PM
To: Erez Ferber <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [PATCH] common/mlx5: adjust fork call with the new kernel APIQuoted 28 lines
Quoted 24 lines · On Wed, 24 May 2023 15:01:40 +0300 <[email protected]> wrote:
From: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking is required.Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separate file")Signed-off-by Erez Ferber <[email protected]>
Quoted 8 lines
Hi,
Quoted 2 lines
I don't think DPDK applications should
fork(), and lots other parts of the shared huge pages will break if an application does this.I agree - application should not, we have the secondary/primary processes approach. Nonetheless, we have the real use case - DPDK application does
fork()and works well. Without mlx5 PMD 😊. With mlx5 it ran into some troubles. Now we have the solution.
The problem is you are allowing fork(). And many other libraries may break. Imagine a DPDK library which has some local mutex and hugepages. If two forked processes use it then the locks won't work and hugepage data will be corrupted.
Quoted 60 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, May 25, 2023 6:28 PM
To: Slava Ovsiienko <[email protected]>
Cc: Erez Ferber <[email protected]>; [email protected]; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [PATCH] common/mlx5: adjust fork call with the new kernel APIQuoted 29 lines · On Thu, 25 May 2023 08:10:03 +0000 Slava Ovsiienko <[email protected]>…
Quoted 29 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, May 24, 2023 5:50 PM
To: Erez Ferber <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [PATCH] common/mlx5: adjust fork call with the new kernel APIQuoted 16 lines · On Wed, 24 May 2023 15:01:40 +0300 <[email protected]> wrote:
From: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking isrequired.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separatefile")
Signed-off-by Erez Ferber <[email protected]>Quoted 6 lines
Hi,
Quoted 2 lines
I don't think DPDK applications should
fork(), and lots other parts of the shared huge pages will break if an application does this.I agree - application should not, we have the secondary/primary processes
approach.
Quoted 1 line
Nonetheless, we have the real use case - DPDK application does
fork()and
Quoted 8 lines
works well.
Quoted 1 line
Without mlx5 PMD 😊. With mlx5 it ran into some troubles. Now we have
the solution.
The problem is you are allowing
fork(). And many other libraries may break. Imagine a DPDK library which has some local mutex and hugepages. If two forked processes use it then the locks won't work and hugepage data will be corrupted.
IMO, this problem is not fork() specific - applications/libraries supporting secondary/primary process approach should be developed with the similar precautions.
And, IIRC, fork() is neither disallowed nor discouraged in DPDK documentation. Moreover, some library unit tests ensure fork() works. No wonder users may develop applications using fork(). They do, and app works well, beside mlx5 PMD. Also, the recommendations to re-design with pri/sec approach was given.
With best regards,
Slava
Quoted 24 lines
-----Original Message-----
From: Erez Ferber <[email protected]>
Sent: Wednesday, May 24, 2023 3:02 PM
To: [email protected]
Cc: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Erez Ferber <[email protected]>; [email protected]
Subject: [PATCH] common/mlx5: adjust fork call with the new kernel APIFrom: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.
Quoted 8 lines
The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking is required.Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separate file")Signed-off-by Erez Ferber <[email protected]>
Hi,
Quoted 25 lines
-----Original Message-----
From: Erez Ferber <[email protected]>
Sent: Wednesday, May 24, 2023 3:02 PM
To: [email protected]
Cc: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Erez Ferber <[email protected]>; [email protected]
Subject: [PATCH] common/mlx5: adjust fork call with the new kernel APIFrom: Erez Ferber <[email protected]>
While doing process
fork()the operating system remaps all the parent process's memory to the address space of the child process and activates the Copy-on-Write mechanics - it duplicates physical pages once memory writing happens in the child process. Sometimes memory duplication is not allowed - for example, if the page contains hardware queue descriptors. To handle similar issues the rdma-core library should be prepared for forking.The
ibv_fork_init()prepares the library to track all the related memory and prevent it from forking usingmadvise()system API. This approach allows fork, but not all the memory is forked to the child process and, application should care not to touch pages where the parent application allocated the rdma-core objects.
Quoted 8 lines
The newer kernels propose an option of copy-on-fork for DMA pages and tracking all the memory and disabling it for the forking is no longer needed. The new API routine
ibv_is_fork_initialized()should be involved to decide if library initialization for forking is required.Fixes 0e83b8e536 ("net/mlx5: move rdma-core calls to separate file")Signed-off-by Erez Ferber <[email protected]>
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh