ibv_alloc_pd()
Contents
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.
Comments
Tell us what do you think.
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;
}
Fixed, thanks!
I hope that beside of this, everything is o.k.
:)
Thanks
Dotan
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!
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
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
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
Hello Dotan,
while using ibv_alloc_pd(),segmentation fault (core dumped) occurred.
do you know the solution to it?
Hi.
This may happen if the pointer of the context that you provided to the ibv_alloc_pd() isn't legal value.
Thanks
Dotan
Hi Dotan,
Is there the size of PDs should be the same each sides (server/client)?
Thanks
Hi.
What do you mean "size of PDs" - PD doesn't have a size...
Thanks
Dotan
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.
Hi.
It is hard for me to answer without the source code and understand what went wrong.
sorry
Dotan