void KatranLb::initLrus()

in katran/lib/KatranLb.cpp [452:524]


void KatranLb::initLrus(bool flowDebug, bool globalLru) {
  bool forwarding_cores_specified{false};
  bool numa_mapping_specified{false};
  int lru_map_flags = 0;
  int lru_proto_fd;
  int res;
  if (forwardingCores_.size() != 0) {
    if (numaNodes_.size() != 0) {
      if (numaNodes_.size() != forwardingCores_.size()) {
        throw std::runtime_error(
            "numaNodes size mut be equal to forwardingCores");
      }
      numa_mapping_specified = true;
    }
    int lru_fd, numa_node;
    auto per_core_lru_size = config_.LruSize / forwardingCores_.size();
    VLOG(2) << "per core lru size: " << per_core_lru_size;
    for (int i = 0; i < forwardingCores_.size(); i++) {
      auto core = forwardingCores_[i];
      if ((core > kMaxForwardingCores) || core < 0) {
        LOG(FATAL) << "got core# " << core
                   << " which is not in supported range: [ 0: "
                   << kMaxForwardingCores << " ]";
        throw std::runtime_error("unsuported number of forwarding cores");
      }
      if (numa_mapping_specified) {
        numa_node = numaNodes_[i];
        lru_map_flags |= kMapNumaNode;
      } else {
        numa_node = kNoNuma;
      }
      lru_fd = createLruMap(per_core_lru_size, lru_map_flags, numa_node);
      if (lru_fd < 0) {
        LOG(FATAL) << "can't creat lru for core: " << core;
        throw std::runtime_error(folly::sformat(
            "can't create LRU for forwarding core, error: {}",
            folly::errnoStr(errno)));
      }
      lruMapsFd_[core] = lru_fd;
      if (flowDebug) {
        initFlowDebugMapForCore(
            core, per_core_lru_size, lru_map_flags, numa_node);
      }
      if (globalLru) {
        initGlobalLruMapForCore(
            core, config_.globalLruSize, lru_map_flags, numa_node);
      }
    }
    forwarding_cores_specified = true;
  }

  if (forwarding_cores_specified) {
    // creating prototype for main LRU's map in map
    // as we know that forwardingCores_ at least has one element
    // we are going to use the first one as a key to find fd of
    // already created LRU
    lru_proto_fd = lruMapsFd_[forwardingCores_[kFirstElem]];
  } else {
    // creating prototype for LRU's map-in-map. this code path would be hit
    // only during unit tests, where we dont specify forwarding cores
    lru_proto_fd = createLruMap();

    if (lru_proto_fd < 0) {
      throw std::runtime_error("can't create prototype map for test lru");
    }
  }
  res = bpfAdapter_.setInnerMapPrototype("lru_mapping", lru_proto_fd);
  if (res < 0) {
    throw std::runtime_error(folly::sformat(
        "can't update inner_maps_fds w/ prototype for main lru, error: {}",
        folly::errnoStr(errno)));
  }
}