Skip to content

Commit

Permalink
pyverbs: Add support for implicit ODP MR
Browse files Browse the repository at this point in the history
The implicit ODP MR covers the entire memory space of a process.
Applications using implicit ODP can use the entire address range
when writing to the MR, instead of being limited to the address
space registered to the MR.
This also saves actual pages registration so that application
control path is faster.

Signed-off-by: Itay Aveksis <itayav@mellanox.com>
Signed-off-by: Edward Srouji <edwards@mellanox.com>
  • Loading branch information
itayave authored and EdwardSro committed Jul 19, 2020
1 parent bed45e6 commit 61ad291
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pyverbs/mr.pyx
Expand Up @@ -7,11 +7,11 @@ import logging
from posix.mman cimport mmap, munmap, MAP_PRIVATE, PROT_READ, PROT_WRITE, \
MAP_ANONYMOUS, MAP_HUGETLB
from pyverbs.pyverbs_error import PyverbsError, PyverbsRDMAError
from libc.stdint cimport uintptr_t, SIZE_MAX
from pyverbs.base import PyverbsRDMAErrno
from posix.stdlib cimport posix_memalign
from libc.string cimport memcpy, memset
cimport pyverbs.libibverbs_enums as e
from libc.stdint cimport uintptr_t
from pyverbs.device cimport DM
from libc.stdlib cimport free
from .pd cimport PD
Expand All @@ -27,16 +27,18 @@ cdef class MR(PyverbsCM):
MR class represents ibv_mr. Buffer allocation in done in the c'tor. Freeing
it is done in close().
"""
def __init__(self, PD pd not None, length=0, access=0, address=None, **kwargs):
def __init__(self, PD pd not None, length=0, access=0, address=None,
implicit=False, **kwargs):
"""
Allocate a user-level buffer of length <length> and register a Memory
Region of the given length and access flags.
:param pd: A PD object
:param length: Length in bytes
:param length: Length (in bytes) of MR's buffer.
:param access: Access flags, see ibv_access_flags enum
:param address: Memory address to register (Optional). If it's not
provided, a memory will be allocated in the class
initialization.
:param implicit: Implicit the MR address.
:param kwargs: Arguments:
* *handle*
A valid kernel handle for a MR object in the given PD.
Expand All @@ -48,10 +50,6 @@ cdef class MR(PyverbsCM):
if self.mr != NULL:
return
self.is_huge = True if access & e.IBV_ACCESS_HUGETLB else False
# We want to enable registering an MR of size 0 but this fails with a
# buffer of size 0, so in this case lets increase the buffer
if length == 0:
length = 10
if address:
self.is_user_addr = True
# uintptr_t is guaranteed to be large enough to hold any pointer.
Expand All @@ -70,7 +68,7 @@ cdef class MR(PyverbsCM):
return

# Allocate a buffer
if not address:
if not address and length > 0:
if self.is_huge:
# Rounding up to multiple of HUGE_PAGE_SIZE
self.mmap_length = length + (HUGE_PAGE_SIZE - length % HUGE_PAGE_SIZE) \
Expand All @@ -86,7 +84,10 @@ cdef class MR(PyverbsCM):
raise PyverbsError('Failed to allocate MR buffer of size {l}'.
format(l=length))
memset(self.buf, 0, length)
self.mr = v.ibv_reg_mr(<v.ibv_pd*>pd.pd, self.buf, length, access)
if implicit:
self.mr = v.ibv_reg_mr(<v.ibv_pd*>pd.pd, NULL, SIZE_MAX, access)
else:
self.mr = v.ibv_reg_mr(<v.ibv_pd*>pd.pd, self.buf, length, access)
if self.mr == NULL:
raise PyverbsRDMAErrno('Failed to register a MR. length: {l}, access flags: {a}'.
format(l=length, a=access))
Expand Down

0 comments on commit 61ad291

Please sign in to comment.