---
name: "ibv_alloc_mw"
section: "3"
platform: "linux"
package: "rdma-core"
version: "65.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/ibv_alloc_mw"
---

# ibv\_alloc\_mw(3)

allocate or deallocate a memory window (MW)

## NAME

ibv\_alloc\_mw, ibv\_dealloc\_mw - allocate or deallocate a memory window (MW)

## SYNOPSIS

```
#include <infiniband/verbs.h>

struct ibv_mw *ibv_alloc_mw(struct ibv_pd *pd,
                            enum ibv_mw_type type);

int ibv_dealloc_mw(struct ibv_mw *mw);
```

## DESCRIPTION

**ibv\_alloc\_mw()** allocates a memory window (MW) associated with the protection domain *pd.* The MW's type (1 or 2A/2B) is *type.*

The MW is created not bound. For it to be useful, the MW must be bound, through either ibv\_bind\_mw (type 1) or a special WR (type 2). Once bound, the memory window allows RDMA (remote) access to a subset of the MR to which it was bound, until invalidated by: ibv\_bind\_mw verb with zero length for type 1, IBV\_WR\_LOCAL\_INV/IBV\_WR\_SEND\_WITH\_INV WR opcode for type 2, deallocation.

**ibv\_dealloc\_mw()** Unbinds in case was previously bound and deallocates the MW *mw.*

## RETURN VALUE

**ibv\_alloc\_mw()** returns a pointer to the allocated MW, or NULL if the request fails. The remote key (**R\_Key**) field **rkey** is used by remote processes to perform Atomic and RDMA operations. This key will be changed during bind operations. The remote process places this **rkey** as the rkey field of struct ibv\_send\_wr passed to the ibv\_post\_send function.

**ibv\_dealloc\_mw()** returns 0 on success, or the value of errno on failure (which indicates the failure reason).

## NOTES

**ibv\_dereg\_mr()** fails if any memory window is still bound to this MR.

## SEE ALSO

[**ibv\_alloc\_pd**(3)](/ibv_alloc_pd/3.md), [**ibv\_post\_send**(3)](/ibv_post_send/3.md), [**ibv\_bind\_mw**(3)](/ibv_bind_mw/3.md), [**ibv\_reg\_mr**(3)](/ibv_reg_mr/3.md),

## AUTHORS

- Majd Dibbiny \<majd@mellanox.com\>

  - Yishai Hadas \<yishaih@mellanox.com\>
