Skip to content

ibv_alloc_pd()

Contents

4.67 avg. rating (93% score) - 3 votes
struct ibv_pd *ibv_alloc_pd(struct ibv_context *context);

Description

ibv_alloc_pd() allocates a Protection Domain (PD) for an RDMA device context.

The created PD will be used for:

  • Create AH, SRQ, QP
  • Register MR
  • Allocate MW

Parameters

Name Direction Description
context in RDMA device context that was returned from ibv_open_device()

Return Values

Value Description
PD pointer to the newly allocated Protection Domain
NULL On failure

Examples

Allocate a PD and then deallocate it:

struct ibv_context *context;
struct ibv_pd *pd;
 
pd = ibv_alloc_pd(context);
if (!pd) {
	fprintf(stderr, "Error, ibv_alloc_pd() failed\n");
	return -1;
}
 
if (ibv_dealloc_pd(pd)) {
	fprintf(stderr, "Error, ibv_dealloc_pd() failed\n");
	return -1;
}

FAQs

Why is a PD good for anyway?

PD is a mean of protection and helps you create a group of object that can work together. If several objects were created using PD1, and others were created using PD2, working with objects from group1 together with objects from group2 will end up with completion with error.

Share Our Posts

Share this post through social bookmarks.

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

Comments

Tell us what do you think.

  1. Tal Epshtein says: April 1, 2013

    There is a typo in the example, which prevents compilation:

    struct ibv_context *context;
    struct ibv_pd *pd;

    pd = ibv_alloc_pd(context);
    if (!pd) { // missing opening for "if" code
    fprintf(stderr, "Error, ibv_alloc_pd() failed\n");
    return -1;
    }

    if (ibv_dealloc_pd(pd)) {
    fprintf(stderr, "Error, ibv_dealloc_pd() failed\n");
    return -1;
    }

    • Dotan Barak says: April 1, 2013

      Fixed, thanks!

      I hope that beside of this, everything is o.k.
      :)

      Thanks
      Dotan

  2. Jack Du says: March 2, 2015

    Hello Dotan,

    Thanks for the wonderful posts! I am new to RDMA. Your blog answered most of the questions I had in my project.

    Now I am wondering how to get the default pd of a local RDMA device. I want to use it to allocate and register a memory pool before accepting any connection requests, so that all the connections share the memory pool. The man page of "rdma_create_qp()" says that there is a default pd per RDMA device. So what is the best way to get it?

    Thanks in advance!

    • Dotan Barak says: March 4, 2015

      Hi.

      The struct rdma_cm_id contains a pre-allocated Protection Domain.
      One can create a QP with a new provided PD, or use the default PD that was allocated by librdmacm.

      Thanks
      Dotan

  3. Adrian says: October 10, 2015

    Hello Dotan,

    If I have two QPs that were created with the same PD and operate on a single MR that was also created with the same PD, is there any ordering guarantee for the operations that are coming over the QPs?

    For example, both QPs are in RTR, and receive WRITE requests, for say some 8 byte block of memory (the same one in both WRITE requests). Will it be the case that the WRITE coming in on one QP will be completely processed before the write on the other QP?

    Thanks in advance

    • Dotan Barak says: October 18, 2015

      Hi Adrian.

      There isn't any guarantee at all on the order of different Work Queues.
      Data access to those QPs can be in any random order.

      Thanks
      Dotan

  4. yang says: March 31, 2017

    Hello Dotan,
    while using ibv_alloc_pd(),segmentation fault (core dumped) occurred.
    do you know the solution to it?

    • Dotan Barak says: April 13, 2017

      Hi.

      This may happen if the pointer of the context that you provided to the ibv_alloc_pd() isn't legal value.

      Thanks
      Dotan

  5. mo says: May 5, 2019

    Hi Dotan,

    Is there the size of PDs should be the same each sides (server/client)?

    Thanks

    • Dotan Barak says: May 6, 2019

      Hi.

      What do you mean "size of PDs" - PD doesn't have a size...

      Thanks
      Dotan

  6. BG says: March 13, 2020

    I'm getting a segmentation fault when trying to allocate a PD. I retrieve the ibv_contexts using the rdma_get_devices() call, and then call ibv_alloc_pd on the returned contexts.

    • Dotan Barak says: July 10, 2020

      Hi.

      It is hard for me to answer without the source code and understand what went wrong.

      sorry
      Dotan

Add a Comment

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

Time limit is exhausted. Please reload CAPTCHA.