| 186 | next_key_(static_cast<uint32_t>(random::New64())) {} |
| 187 | |
| 188 | Status GdrMemoryManager::Init() { |
| 189 | rdma_addrinfo* addrinfo; |
| 190 | rdma_addrinfo hints = {}; |
| 191 | hints.ai_port_space = RDMA_PS_TCP; |
| 192 | hints.ai_flags = RAI_PASSIVE; |
| 193 | if (rdma_getaddrinfo(const_cast<char*>(host_.c_str()), |
| 194 | const_cast<char*>(port_.c_str()), &hints, &addrinfo)) { |
| 195 | return errors::Unavailable(strerror(errno), ": ", "cannot resolve rdma://", |
| 196 | host_, ":", port_); |
| 197 | } |
| 198 | |
| 199 | ibv_qp_init_attr init_attr = {}; |
| 200 | init_attr.qp_type = IBV_QPT_RC; |
| 201 | init_attr.cap.max_recv_wr = 1024; |
| 202 | init_attr.cap.max_send_wr = 1; |
| 203 | init_attr.cap.max_recv_sge = 1; |
| 204 | init_attr.cap.max_send_sge = 1; |
| 205 | |
| 206 | // Create listening endpoint |
| 207 | rdma_cm_id* id; |
| 208 | if (rdma_create_ep(&id, addrinfo, nullptr, &init_attr)) { |
| 209 | return errors::Unavailable(strerror(errno), ": ", "cannot bind to rdma://", |
| 210 | host_, ":", port_); |
| 211 | } |
| 212 | listening_.reset(id); |
| 213 | rdma_freeaddrinfo(addrinfo); |
| 214 | |
| 215 | // Listen without backlog |
| 216 | if (rdma_listen(listening_.get(), 0)) { |
| 217 | return errors::Unavailable(strerror(errno), ": ", |
| 218 | "cannot listen on rdma://", host_, ":", port_); |
| 219 | } |
| 220 | LOG(INFO) << "RDMA server is listening on " << host_ << ":" << port_; |
| 221 | |
| 222 | if (listening_->verbs == nullptr) { |
| 223 | return errors::Unimplemented( |
| 224 | "Unsupported address ", host_, ":", port_, |
| 225 | " as it does not bind to a particular RDMA device"); |
| 226 | } |
| 227 | |
| 228 | int flags = fcntl(listening_->channel->fd, F_GETFL, 0); |
| 229 | if (fcntl(listening_->channel->fd, F_SETFL, flags | O_NONBLOCK)) { |
| 230 | return errors::Unavailable(strerror(errno), ": ", |
| 231 | "cannot set server to non-blocking mode"); |
| 232 | } |
| 233 | |
| 234 | numa_node_ = TryToReadNumaNode(listening_->verbs->device); |
| 235 | |
| 236 | SubAllocator::Visitor alloc_visitor = [this](void* ptr, int numa_node, |
| 237 | size_t num_bytes) { |
| 238 | VLOG(2) << "Registering RDMA capable memory region on numa_node " |
| 239 | << numa_node; |
| 240 | InsertMemoryRegion(ptr, num_bytes, strings::StrCat("CPU:", numa_node)); |
| 241 | }; |
| 242 | SubAllocator::Visitor free_visitor = [this](void* ptr, int numa_node, |
| 243 | size_t num_bytes) { |
| 244 | VLOG(2) << "De-registering RDMA capable memory region on numa_node " |
| 245 | << numa_node; |
nothing calls this directly
no test coverage detected