543 字
3 分钟
Linux RDMA
RXE 传输测试
Host A
# 加载 RXE 模块sudo modprobe rdma_rxe
# 创建 RXE 设备sudo rdma link add rxe_ens33 type rxe netdev ens33
# 启动带宽测试服务端(监听所有接口)ib_send_bw -d rxe_ens33Host B
# 加载 RXE 模块sudo modprobe rdma_rxe
# 创建 RXE 设备sudo rdma link add rxe_ens33 type rxe netdev ens33
# 连接 Server 并开始测试ib_send_bw -d rxe_ens33 10.225.231.254虚拟 RDMA 设备驱动实现
环境配置
系统信息
系统:Ubuntu 24.04.3 LTS in VMware
内核版本:6.14.0-35-generic
安装软件包
sudo apt updatesudo apt install -y qemu-system qemu-utils cloud-image-utils cpu-checker验证 KVM 可用性
kvm-ok# KVM acceleration can be used将用户添加到 kvm 组
这样可以无需 sudo 运行某些 QEMU 操作。
sudo usermod -aG kvm $(whoami)WARNING可能需要注销并重新登录或者重新连接ssh,用户组的更改才能生效。
创建虚拟机
# 创建工作目录mkdir -p ~/rdma/vmcd ~/rdma/vm# 下载 cloud image (qcow2 格式)wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img创建差分镜像 (Backing File)
qemu-img create -f qcow2 -F qcow2 -b noble-server-cloudimg-amd64.img my-ubuntu.qcow2 40G准备 cloud-init
cat > meta-data <<EOFinstance-id: ubuntu-$(date +%s)local-hostname: ubuntu-vmEOFif [ ! -f ~/.ssh/id_rsa.pub ]; then ssh-keygen; fi
cat > user-data <<EOF#cloud-configpassword: ubuntu # 设置用户密码 (可选)chpasswd: { expire: False }ssh_pwauth: true # 允许密码认证 (可选)ssh_authorized_keys: - $(cat ~/.ssh/id_rsa.pub)EOF创建 cloud-init 数据源镜像
cloud-localds seed.img user-data meta-data配置共享文件夹
# 在宿主机上创建一个用于共享的目录mkdir -p ~/rdma/shared启动 QEMU 并连接
qemu-system-x86_64 \ -enable-kvm \ -cpu host \ -smp $(nproc) \ -m 2G \ -drive file=my-ubuntu.qcow2,format=qcow2,if=virtio \ -drive file=seed.img,format=raw,if=virtio \ -netdev user,id=net0,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=net0 \ -virtfs local,path=$HOME/rdma/shared,mount_tag=host_share,security_model=none,id=fsdev0 \ -device virtio-9p-pci,fsdev=fsdev0,mount_tag=host_share \ -nographic -serial mon:stdiossh ubuntu@localhost -p 2222配置虚拟机开发环境
安装软件包
sudo apt updatesudo apt install build-essential gcc make git linux-headers-$(uname -r) linux-modules-extra-$(uname -r) rdma-core ibverbs-utils验证 RDMA 环境
# 获取网卡名称NETDEV=$(ip -o -4 route show to default | awk '{print $5}')
# 加载 RXE 模块并创建一个 rxe 设备sudo modprobe rdma_rxesudo rdma link add rxe0 type rxe netdev $NETDEV
# 查看设备信息ibv_devinfohca_id: rxe0 transport: InfiniBand (0) fw_ver: 0.0.0 node_guid: 5054:00ff:fe12:3456 sys_image_guid: 5054:00ff:fe12:3456 vendor_id: 0xffffff vendor_part_id: 0 hw_ver: 0x0 phys_port_cnt: 1 port: 1 state: PORT_ACTIVE (4) max_mtu: 4096 (5) active_mtu: 1024 (3) sm_lid: 0 port_lid: 0 port_lmc: 0x00 link_layer: Ethernet
挂载共享目录
sudo mkdir -p /mnt/host_sharesudo mount -t 9p -o trans=virtio,version=9p2000.L,rw host_share /mnt/host_share# 开机自动挂载echo 'host_share /mnt/host_share 9p trans=virtio,version=9p2000.L,rw,_netdev,nofail 0 0' | sudo tee -a /etc/fstab参考
部分信息可能已经过时