mem: don't use address hint for mapping unless requested

Message ID 20190321202156.117496-1-shahafs@mellanox.com (mailing list archive)
State Superseded, archived
Headers
Series mem: don't use address hint for mapping unless requested |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Shahaf Shuler March 21, 2019, 8:21 p.m. UTC
  patch[1] added an address hint as starting address for 64 bit systems in
case an explicit base virtual address was not set by the user.

The justification for such hint was to help devices that work in VA
mode and has a address range limitation to work smoothly with the eal
memory subsystem.

While the base address value selected may work fine for the eal
initialization, it easily breaks when trying to register external memory
using rte_extmem_register API.

Trying to register anonymous memory on RH x86_64 machine took several
minutes, during them the function eal_get_virtual_area repeatedly
scanned for a good VA candidate.

The attempt to guess which VA address will be free for mapping will
always result in not portable, error prone code:
* different application may use different libraries along w/ DPDK. One
  can never guess which library was called first and how much virtual
  memory it consumed.
* external memory can be registered at any time in the application run
  time.

This patch removes the default address hint and use the address returned
by mmap.
devices with address limitations should suggest to their users a proper
base-virtaddr (EAL arg) to use.

Fixes: 1df21702873d ("mem: use address hint for mapping hugepages")
Cc: stable@dpdk.org
Cc: alejandro.lucero@netronome.com

[1] commit 1df21702873d ("mem: use address hint for mapping hugepages")

Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
---
 lib/librte_eal/common/eal_common_memory.c | 22 ----------------------
 1 file changed, 22 deletions(-)
  

Comments

Shahaf Shuler March 27, 2019, 5:36 a.m. UTC | #1
Anatoly, Alejandro,

Any comments on this one?

Thursday, March 21, 2019 10:22 PM, Shahaf Shuler:
> Subject: [dpdk-dev] [PATCH] mem: don't use address hint for mapping
> unless requested
> 
> patch[1] added an address hint as starting address for 64 bit systems in case
> an explicit base virtual address was not set by the user.
> 
> The justification for such hint was to help devices that work in VA mode and
> has a address range limitation to work smoothly with the eal memory
> subsystem.
> 
> While the base address value selected may work fine for the eal initialization,
> it easily breaks when trying to register external memory using
> rte_extmem_register API.
> 
> Trying to register anonymous memory on RH x86_64 machine took several
> minutes, during them the function eal_get_virtual_area repeatedly scanned
> for a good VA candidate.
> 
> The attempt to guess which VA address will be free for mapping will always
> result in not portable, error prone code:
> * different application may use different libraries along w/ DPDK. One
>   can never guess which library was called first and how much virtual
>   memory it consumed.
> * external memory can be registered at any time in the application run
>   time.
> 
> This patch removes the default address hint and use the address returned by
> mmap.
> devices with address limitations should suggest to their users a proper base-
> virtaddr (EAL arg) to use.
> 
> Fixes: 1df21702873d ("mem: use address hint for mapping hugepages")
> Cc: stable@dpdk.org
> Cc: alejandro.lucero@netronome.com
> 
> [1] commit 1df21702873d ("mem: use address hint for mapping hugepages")
> 
> Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
> ---
>  lib/librte_eal/common/eal_common_memory.c | 22 ----------------------
>  1 file changed, 22 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_memory.c
> b/lib/librte_eal/common/eal_common_memory.c
> index c9da69b164..09108f7a32 100644
> --- a/lib/librte_eal/common/eal_common_memory.c
> +++ b/lib/librte_eal/common/eal_common_memory.c
> @@ -39,23 +39,6 @@
>  static void *next_baseaddr;
>  static uint64_t system_page_sz;
> 
> -#ifdef RTE_ARCH_64
> -/*
> - * Linux kernel uses a really high address as starting address for serving
> - * mmaps calls. If there exists addressing limitations and IOVA mode is VA,
> - * this starting address is likely too high for those devices. However, it
> - * is possible to use a lower address in the process virtual address space
> - * as with 64 bits there is a lot of available space.
> - *
> - * Current known limitations are 39 or 40 bits. Setting the starting address
> - * at 4GB implies there are 508GB or 1020GB for mapping the available
> - * hugepages. This is likely enough for most systems, although a device with
> - * addressing limitations should call rte_mem_check_dma_mask for
> ensuring all
> - * memory is within supported range.
> - */
> -static uint64_t baseaddr = 0x100000000; -#endif
> -
>  void *
>  eal_get_virtual_area(void *requested_addr, size_t *size,
>  		size_t page_sz, int flags, int mmap_flags) @@ -79,11 +62,6
> @@ eal_get_virtual_area(void *requested_addr, size_t *size,
>  			rte_eal_process_type() == RTE_PROC_PRIMARY)
>  		next_baseaddr = (void *) internal_config.base_virtaddr;
> 
> -#ifdef RTE_ARCH_64
> -	if (next_baseaddr == NULL && internal_config.base_virtaddr == 0 &&
> -			rte_eal_process_type() == RTE_PROC_PRIMARY)
> -		next_baseaddr = (void *) baseaddr;
> -#endif
>  	if (requested_addr == NULL && next_baseaddr != NULL) {
>  		requested_addr = next_baseaddr;
>  		requested_addr = RTE_PTR_ALIGN(requested_addr,
> page_sz);
> --
> 2.12.0
  
Anatoly Burakov March 27, 2019, 11:49 a.m. UTC | #2
On 21-Mar-19 8:21 PM, Shahaf Shuler wrote:
> patch[1] added an address hint as starting address for 64 bit systems in
> case an explicit base virtual address was not set by the user.
> 
> The justification for such hint was to help devices that work in VA
> mode and has a address range limitation to work smoothly with the eal
> memory subsystem.
> 
> While the base address value selected may work fine for the eal
> initialization, it easily breaks when trying to register external memory
> using rte_extmem_register API.
> 
> Trying to register anonymous memory on RH x86_64 machine took several
> minutes, during them the function eal_get_virtual_area repeatedly
> scanned for a good VA candidate.
> 
> The attempt to guess which VA address will be free for mapping will
> always result in not portable, error prone code:
> * different application may use different libraries along w/ DPDK. One
>    can never guess which library was called first and how much virtual
>    memory it consumed.
> * external memory can be registered at any time in the application run
>    time.
> 
> This patch removes the default address hint and use the address returned
> by mmap.
> devices with address limitations should suggest to their users a proper
> base-virtaddr (EAL arg) to use.
> 
> Fixes: 1df21702873d ("mem: use address hint for mapping hugepages")
> Cc: stable@dpdk.org
> Cc: alejandro.lucero@netronome.com
> 
> [1] commit 1df21702873d ("mem: use address hint for mapping hugepages")
> 
> Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
> ---

I understand the motivation, however this will lower the reliability of 
secondary process initialization. Perhaps, the hinting could be improved 
by not trying to use the hint multiple times, but rather just once? I.e. 
if using hint succeeded - great, if not - try without one. Most of the 
time hint will work correctly, i think.
  
Shahaf Shuler March 28, 2019, 8:45 a.m. UTC | #3
Wednesday, March 27, 2019 1:50 PM, Burakov, Anatoly:
> Subject: Re: [PATCH] mem: don't use address hint for mapping unless
> requested
> 
> On 21-Mar-19 8:21 PM, Shahaf Shuler wrote:
> > patch[1] added an address hint as starting address for 64 bit systems
> > in case an explicit base virtual address was not set by the user.
> >
> > The justification for such hint was to help devices that work in VA
> > mode and has a address range limitation to work smoothly with the eal
> > memory subsystem.
> >
> > While the base address value selected may work fine for the eal
> > initialization, it easily breaks when trying to register external
> > memory using rte_extmem_register API.
> >
> > Trying to register anonymous memory on RH x86_64 machine took several
> > minutes, during them the function eal_get_virtual_area repeatedly
> > scanned for a good VA candidate.
> >
> > The attempt to guess which VA address will be free for mapping will
> > always result in not portable, error prone code:
> > * different application may use different libraries along w/ DPDK. One
> >    can never guess which library was called first and how much virtual
> >    memory it consumed.
> > * external memory can be registered at any time in the application run
> >    time.
> >
> > This patch removes the default address hint and use the address
> > returned by mmap.
> > devices with address limitations should suggest to their users a
> > proper base-virtaddr (EAL arg) to use.
> >
> > Fixes: 1df21702873d ("mem: use address hint for mapping hugepages")
> > Cc: stable@dpdk.org
> > Cc: alejandro.lucero@netronome.com
> >
> > [1] commit 1df21702873d ("mem: use address hint for mapping
> > hugepages")
> >
> > Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
> > ---
> 
> I understand the motivation, however this will lower the reliability of
> secondary process initialization. 

Can you explain why?
It is very bad if we base the DPDK secondary process design on some predefined VA address base to be available. 

Perhaps, the hinting could be improved by
> not trying to use the hint multiple times, but rather just once? I.e.
> if using hint succeeded - great, if not - try without one. Most of the time hint
> will work correctly, i think.
> 
> --
> Thanks,
> Anatoly
  
Anatoly Burakov March 28, 2019, 10:26 a.m. UTC | #4
On 28-Mar-19 8:45 AM, Shahaf Shuler wrote:
> Wednesday, March 27, 2019 1:50 PM, Burakov, Anatoly:
>> Subject: Re: [PATCH] mem: don't use address hint for mapping unless
>> requested
>>
>> On 21-Mar-19 8:21 PM, Shahaf Shuler wrote:
>>> patch[1] added an address hint as starting address for 64 bit systems
>>> in case an explicit base virtual address was not set by the user.
>>>
>>> The justification for such hint was to help devices that work in VA
>>> mode and has a address range limitation to work smoothly with the eal
>>> memory subsystem.
>>>
>>> While the base address value selected may work fine for the eal
>>> initialization, it easily breaks when trying to register external
>>> memory using rte_extmem_register API.
>>>
>>> Trying to register anonymous memory on RH x86_64 machine took several
>>> minutes, during them the function eal_get_virtual_area repeatedly
>>> scanned for a good VA candidate.
>>>
>>> The attempt to guess which VA address will be free for mapping will
>>> always result in not portable, error prone code:
>>> * different application may use different libraries along w/ DPDK. One
>>>     can never guess which library was called first and how much virtual
>>>     memory it consumed.
>>> * external memory can be registered at any time in the application run
>>>     time.
>>>
>>> This patch removes the default address hint and use the address
>>> returned by mmap.
>>> devices with address limitations should suggest to their users a
>>> proper base-virtaddr (EAL arg) to use.
>>>
>>> Fixes: 1df21702873d ("mem: use address hint for mapping hugepages")
>>> Cc: stable@dpdk.org
>>> Cc: alejandro.lucero@netronome.com
>>>
>>> [1] commit 1df21702873d ("mem: use address hint for mapping
>>> hugepages")
>>>
>>> Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
>>> ---
>>
>> I understand the motivation, however this will lower the reliability of
>> secondary process initialization.
> 
> Can you explain why?
> It is very bad if we base the DPDK secondary process design on some predefined VA address base to be available.

Our whole secondary process is "very bad design" in the first place, 
because it relies on address space duplication. This change was 
unrelated to it, but it has been shown that setting address hint to this 
value (or setting --base-virtaddr to the same address) improves success 
rate for secondary process initialization to the point where it doesn't 
even register in our internal bug tracker (whereas previously i did 
routinely get pings about secondary process init failing).

This is just something we have to live with, and this change has been a 
net positive as far as reliability of secondary process initialization goes.

> 
> Perhaps, the hinting could be improved by
>> not trying to use the hint multiple times, but rather just once? I.e.
>> if using hint succeeded - great, if not - try without one. Most of the time hint
>> will work correctly, i think.
>>
>> --
>> Thanks,
>> Anatoly
  

Patch

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index c9da69b164..09108f7a32 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -39,23 +39,6 @@ 
 static void *next_baseaddr;
 static uint64_t system_page_sz;
 
-#ifdef RTE_ARCH_64
-/*
- * Linux kernel uses a really high address as starting address for serving
- * mmaps calls. If there exists addressing limitations and IOVA mode is VA,
- * this starting address is likely too high for those devices. However, it
- * is possible to use a lower address in the process virtual address space
- * as with 64 bits there is a lot of available space.
- *
- * Current known limitations are 39 or 40 bits. Setting the starting address
- * at 4GB implies there are 508GB or 1020GB for mapping the available
- * hugepages. This is likely enough for most systems, although a device with
- * addressing limitations should call rte_mem_check_dma_mask for ensuring all
- * memory is within supported range.
- */
-static uint64_t baseaddr = 0x100000000;
-#endif
-
 void *
 eal_get_virtual_area(void *requested_addr, size_t *size,
 		size_t page_sz, int flags, int mmap_flags)
@@ -79,11 +62,6 @@  eal_get_virtual_area(void *requested_addr, size_t *size,
 			rte_eal_process_type() == RTE_PROC_PRIMARY)
 		next_baseaddr = (void *) internal_config.base_virtaddr;
 
-#ifdef RTE_ARCH_64
-	if (next_baseaddr == NULL && internal_config.base_virtaddr == 0 &&
-			rte_eal_process_type() == RTE_PROC_PRIMARY)
-		next_baseaddr = (void *) baseaddr;
-#endif
 	if (requested_addr == NULL && next_baseaddr != NULL) {
 		requested_addr = next_baseaddr;
 		requested_addr = RTE_PTR_ALIGN(requested_addr, page_sz);