函数
ibv_fork_init
模板: int ibv_fork_init(void)
输入参数: 无
输出参数: 无
返回值: 0
on success, -1
on error. If the call fails, errno will be set to indicate the reason for the failure.
描述: ibv_fork_init
初始化 libverbs 的数据结构来安全地处理 fork()
并避免数据损坏,不论 fork()
是被显式调用还是隐式调用(比如在 system()
中被调用)。
如果所有的父进程总是阻塞直至所有的子进程结束或使用 exec()
改变地址空间,那么 ibv_fork_init
可以不被调用。
该函数在支持 madvise
的 MADV_DONTFORK
标记的 Linux 内核(2.6.17或更高)上可以工作。
设置环境变量 RDMAV_FORK_SAFE
或 IBV_FORK_SAFE
环境变量为任意值,有着与 ibv_fork_init
相同的效果。
设置 RDMAV_HUGEPAGES_SAFE
为任意值,以告诉库需要检查内核为内存域(memory regions)使用的底层内存页的大小。如果应用程序直接或通过库(如 libhugtlbfs )间接使用大内存页(博主注:即大于4KB)时,该环境变量是必须的。(博主注:ibv_fork_init
将检查 RDMAV_HUGEPAGES_SAFE
)
调用 ibv_fork_init
将降低性能,因为每个内存注册都将有一个额外的系统调用和分配附加的内存以追踪内存域(memory regions)。
确切的性能损失取决于工作负载,通常不会很大。
设置 RDMAV_HUGEPAGES_SAFE
会为所有的内存注册增加更多的开销。
文档
Documentation: RDMA Aware Networks Programming User Manual v1.6
Sun Network QDR InfiniBand Gateway Switch Topic Set
用户态的Verbs API手册跟代码在一个仓库维护,手册地址:https://github.com/linux-rdma/rdma-core/tree/master/libibverbs/man
有很多在线的man page网站可以查阅这些接口的说明,比如官方的连接:https://man7.org/linux/man-pages/man3/ibv_post_send.3.html
也有一些其他非官方网页,支持在线搜索:https://linux.die.net/man/3/ibv
查阅系统man page
如果你使用的商用OS安装了rdma-core或者libibverbs库,那么可以直接用man命令查询接口:
1 | man ibv_post_send |
查询Mellanox的编程手册
《RDMA Aware Networks Programming User Manual Rev 1.7》,最新版是2015年更新的。该手册写的比较详尽,并且附有示例程序,但是可能与最新的接口有一些差异。Mellanox VPI®(Virtual Procotol Interconnect)架构为同时支持InfiniBand和以太网语义的网络适配器和交换机提供高性能、低延迟和可靠的方法。
Book: Linux Kernel Networking - Implementation and Theory
Dotan’s blog: Dotan Barak, an InfiniBand Expert. Dotan is a Senior Software Manager at Mellanox Technologies working on RDMA Technologies.
性能分析工具(profiling)
Blog: Tips and tricks to optimize your RDMA code
IB简介
RDMA - Remote Direct Memory Access 远程直接内存存取。
InfiniBand是一种高性能计算机网络通信标准,它具有极高的吞吐量和极低的延迟。如果您需要使用InfiniBand进行编程,您需要使用支持InfiniBand的编程语言(如C++)来编写代码。
机构和组织:
OFA: Open Fabrics Alliance.
IBTA: InfiniBand Trade Association.
概念
CQ
- Complete Queue 完成队列WQ
- Work Queue 工作队列WR
- Work Request 工作请求QP
- Queue Pairs 队列对(Send-Receive)SQ
- Send Queue 发送队列RQ
- Receive Queue 接收队列PD
- Protection Domain 保护域,将QP和MR结合在一起MR
- Memory Region 内存区域。一块经注册过的且本地网卡可以读写的内存区域。包含R_Key和L_Key。SGE
- Scatter/Gather Elements 分散/聚集元素。R_Key
- Remote KeyL_Key
- Local KeyCA
- (Host) Channel Adapter, an inifiniband network interface card.NIC
- Network Interface Card 网卡。LID
- Local Identifier.CM
- Connection Manager.
其他常见缩写:
RC
- reliable connected.SCSI
- Small Computer System Interface 小型计算机系统接口。SRP
- SCSI RDMA Protocol. / Secure Remote Password.
博客:https://blog.51cto.com/liangchaoxi/4044818
安装
sudo apt-get install infiniband-diags
sudo apt install ibverbs-utils
API
以下是一些支持InfiniBand的C++库:
Infinity:这是一个轻量级的C++ RDMA库,用于InfiniBand网络。它提供了对两侧(发送/接收)和单侧(读/写/原子)操作的支持,并且是一个简单而强大的面向对象的ibVerbs抽象。该库使用户能够构建使用RDMA的复杂应用程序,而不会影响性能1。
OFED:这是一个开放式Fabrics Enterprise Distribution,它提供了对InfiniBand和RoCE(RDMA over Converged Ethernet)技术的支持。OFED提供了一组用户空间库和驱动程序,可用于构建支持RDMA的应用程序2。
以下是使用Infinity库编写支持InfiniBand的C++代码示例:
1 | // 创建新上下文 |
以下是使用OFED库编写支持InfiniBand的C++代码示例:
1 | // 创建新上下文 |
- 入门级文档:https://zhuanlan.zhihu.com/p/337461037
- 文档:https://docs.kernel.org/infiniband/index.html
- 文档:http://blog.foool.net/wp-content/uploads/linuxdocs/infiniband.pdf
- 文档:https://support.bull.com/documentation/byproduct/infra/sw-extremcomp/sw-extremcomp-com/g
- 文档:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_infiniband_and_rdma_networks/index
- 博客:https://zhuanlan.zhihu.com/p/337461037
- 文档:https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/networking_guide/ch-configure_infiniband_and_rdma_networks
- 知乎专栏:https://www.zhihu.com/column/c_1231181516811390976
- 知乎专栏:https://www.zhihu.com/column/rdmatechnology
Command-Line
文档:https://docs.nvidia.com/networking/pages/viewpage.action?pageId=43719572
ibstat
ibhosts
- 查看所有的IB hosts。ibnetdiscover
- discover InfiniBand topology.ibv_devices
- list RDMA devices.ibv_devinof
- Print information about RDMA devices available for use from userspace.ibv_rc_pingpong
- Run a simple ping-pong test over InfiniBand via the reliable connected (RC) transport.targetcli
- administration shell for storage targetstargetcli
is a shell for viewing, editing, and saving the configuration of the kernel’s target subsystem,
also known as LIO. It enables the administrator to assign local storage resources backed by either files,
volumes, local SCSI devices, or ramdisk, and export them to remote systems via network fabrics, such as iSCSI or FCoE.srp_daemon
- Discovers and connects to InfiniBand SCSI RDMA Protocol (SRP) targets in an IB fabric.ibsrpdm
- List InfiniBand SCSI RDMA Protocol (SRP) targets on an IB fabric.
liraries
devid: device ID library. Refer to here.
ibverbs: 使得用户空间进程能够使用RDMA verbs(即进行RDMA操作)。Refer to here.
dl: Dynamic Loader.