Skip to content

Commit

Permalink
Add cpu num to katran_lru maps name
Browse files Browse the repository at this point in the history
Summary:
Per-CPU LRU maps are all currently named `katran_lru`, which makes it harder to identify when inspecting with bpftool. Adding cpu number to the name `katran_lru0, katran_lru1, ...`

Plus minor changes, replaced kMapNumaNode with corresponding kernel constant BPF_F_NUMA_NODE.

Reviewed By: frankfeir

Differential Revision: D69079665

fbshipit-source-id: 67893b8cc864bc5fe9750c22fdfc8b430b0277cb
  • Loading branch information
avasylev authored and facebook-github-bot committed Feb 5, 2025
1 parent a1c099f commit ca11962
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions katran/lib/KatranLb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ void KatranLb::initialSanityChecking(bool flowDebug, bool globalLru) {
}
}

int KatranLb::createLruMap(int size, int flags, int numaNode) {
int KatranLb::createLruMap(int size, int flags, int numaNode, int cpu) {
return bpfAdapter_->createNamedBpfMap(
"katran_lru",
"katran_lru" + std::to_string(cpu),
kBpfMapTypeLruHash,
sizeof(struct flow_key),
sizeof(struct real_pos_lru),
Expand Down Expand Up @@ -450,9 +450,7 @@ void KatranLb::attachGlobalLru(int core) {
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()) {
Expand All @@ -461,7 +459,6 @@ void KatranLb::initLrus(bool flowDebug, bool globalLru) {
}
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++) {
Expand All @@ -472,13 +469,14 @@ void KatranLb::initLrus(bool flowDebug, bool globalLru) {
<< kMaxForwardingCores << " ]";
throw std::runtime_error("unsuported number of forwarding cores");
}
int numa_node = kNoNuma;
int lru_map_flags = 0;
if (numa_mapping_specified) {
numa_node = numaNodes_[i];
lru_map_flags |= kMapNumaNode;
} else {
numa_node = kNoNuma;
lru_map_flags |= BPF_F_NUMA_NODE;
}
lru_fd = createLruMap(per_core_lru_size, lru_map_flags, numa_node);
int lru_fd =
createLruMap(per_core_lru_size, lru_map_flags, numa_node, core);
if (lru_fd < 0) {
LOG(FATAL) << "can't creat lru for core: " << core;
throw std::runtime_error(fmt::format(
Expand All @@ -498,6 +496,7 @@ void KatranLb::initLrus(bool flowDebug, bool globalLru) {
forwarding_cores_specified = true;
}

int lru_proto_fd;
if (forwarding_cores_specified) {
// creating prototype for main LRU's map in map
// as we know that forwardingCores_ at least has one element
Expand All @@ -513,7 +512,7 @@ void KatranLb::initLrus(bool flowDebug, bool globalLru) {
throw std::runtime_error("can't create prototype map for test lru");
}
}
res = bpfAdapter_->setInnerMapPrototype("lru_mapping", lru_proto_fd);
int res = bpfAdapter_->setInnerMapPrototype("lru_mapping", lru_proto_fd);
if (res < 0) {
throw std::runtime_error(fmt::format(
"can't update inner_maps_fds w/ prototype for main lru, error: {}",
Expand Down
4 changes: 2 additions & 2 deletions katran/lib/KatranLb.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ constexpr uint32_t kIcmpPtbV4Offset = 13;
*/
constexpr int kFallbackLruSize = 1024;
constexpr int kMapNoFlags = 0;
constexpr int kMapNumaNode = 4;
constexpr int kNoNuma = -1;

constexpr uint8_t V6DADDR = 1;
Expand Down Expand Up @@ -967,7 +966,8 @@ class KatranLb {
int createLruMap(
int size = kFallbackLruSize,
int flags = kMapNoFlags,
int numaNode = kNoNuma);
int numaNode = kNoNuma,
int cpu = 0);

/**
* helper function to creat LRU map w/ specified size.
Expand Down

0 comments on commit ca11962

Please sign in to comment.