Skip to content

ibv_dereg_mr()

Contents

5.00 avg. rating (97% score) - 1 vote
int ibv_dereg_mr(struct ibv_mr *mr);

Description

ibv_dereg_mr() deregisters a Memory Region and release the resources of that MR in the RDMA device it is associated with.

Only after a Memory Region is deregistered, the memory buffer that was associated with it should be released by the user.

The deregistration of an MR will fail if any Memory Window is still bound to it.

It is up to the user to stop using the keys (lkey and rkey) that are associated with this MR. If those keys will be used in local Work Requests or by remote operation requests, it will lead to Work Completion errors.

Parameters

Name Direction Description
mr in MR that was returned from ibv_reg_mr()

Return Values

Value Description
0 On success
errno On failure
EINVAL MR context is invalid
EBUSY MWs are still associated with this MR

Examples

Register an MR to allow only local read and write access and deregister it:

struct ibv_pd *pd;
struct ibv_mr *mr;
 
mr = ibv_reg_mr(pd, buf, size, IBV_ACCESS_LOCAL_WRITE);
if (!mr) {
	fprintf(stderr, "Error, ibv_reg_mr() failed\n");
	return -1;
}
 
if (ibv_dereg_mr(mr)) {
	fprintf(stderr, "Error, ibv_dereg_mr() failed\n");
	return -1;
}

FAQs

What will happen if I will release the memory buffer that is associated with an MR before deregistering it?

Doing this may lead to a segmentation fault.

What will happen if I will use the keys (lkey or rkey) that were associated with the MR after I deregistered it?

Doing this will lead to Work Completion with error since those keys are invalid. One should make sure that there aren't any local Work Request or remote operation requests that use those keys, before deregister this MR.

ibv_dereg_mr() failed, can I know which MWs are allocated and causes this failure?

No, currently the RDMA stack doesn't have this capability.

Share Our Posts

Share this post through social bookmarks.

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati

Comments

Tell us what do you think.

  1. David R. says: April 28, 2017

    Hi Dotan,

    This blog and the man page for ibv_dereg_mr() both state that its return value on failure is the value of errno. However, I recently noticed that the RDMA Aware Networks Programming User Manual (Rev. 1.7) from Mellanox states that the return value is -1 on error and errno will be set to indicate the reason for the failure. Do you know if this is something that has changed recently or is this an error in the Mellanox User Manual?

    Thank you,
    David

    • Dotan Barak says: July 3, 2017

      Hi.

      The return value is for hint only,
      I suggest that you'll check if the verb passed or not
      (in most cases: return value 0 means that it passed).

      There isn't any really consistency in the errno/return value between different drivers/versions.

      Thanks
      Dotan

Add a Comment

This comment will be moderated; answer may be provided within 14 days.

Time limit is exhausted. Please reload CAPTCHA.