Skip to content

Commit

Permalink
mem: limit use of address hint
Browse files Browse the repository at this point in the history
The commit below 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.

In order not to break the existing secondary process design, this patch
only limits the max number of tries that will be done with the
address hint.
When the number of tries exceeds the threshold the code
will use the suggested address from kernel.

Fixes: 1df2170 ("mem: use address hint for mapping hugepages")
Cc: stable@dpdk.org

Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
Tested-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Alejandro Lucero <alejandro.lucero@netronome.com>
  • Loading branch information
shahafsh authored and tmonjalo committed Apr 3, 2019
1 parent c0c055f commit 237060c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/librte_eal/common/eal_common_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ static uint64_t system_page_sz;
static uint64_t baseaddr = 0x100000000;
#endif

#define MAX_MMAP_WITH_DEFINED_ADDR_TRIES 5
void *
eal_get_virtual_area(void *requested_addr, size_t *size,
size_t page_sz, int flags, int mmap_flags)
{
bool addr_is_hint, allow_shrink, unmap, no_align;
uint64_t map_sz;
void *mapped_addr, *aligned_addr;
uint8_t try = 0;

if (system_page_sz == 0)
system_page_sz = sysconf(_SC_PAGESIZE);
Expand Down Expand Up @@ -118,11 +120,14 @@ eal_get_virtual_area(void *requested_addr, size_t *size,

if (mapped_addr != MAP_FAILED && addr_is_hint &&
mapped_addr != requested_addr) {
/* hint was not used. Try with another offset */
munmap(mapped_addr, map_sz);
mapped_addr = MAP_FAILED;
try++;
next_baseaddr = RTE_PTR_ADD(next_baseaddr, page_sz);
requested_addr = next_baseaddr;
if (try <= MAX_MMAP_WITH_DEFINED_ADDR_TRIES) {
/* hint was not used. Try with another offset */
munmap(mapped_addr, map_sz);
mapped_addr = MAP_FAILED;
requested_addr = next_baseaddr;
}
}
} while ((allow_shrink || addr_is_hint) &&
mapped_addr == MAP_FAILED && *size > 0);
Expand Down

0 comments on commit 237060c

Please sign in to comment.