Skip to content

Commit

Permalink
shm region cache: fix multiple sessions issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed May 7, 2021
1 parent 87e0ca5 commit 2ca62d0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions fairmq/shmem/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <thread>
#include <unordered_map>
#include <utility> // pair
#include <tuple>
#include <vector>

#include <unistd.h> // getuid
Expand All @@ -58,7 +59,8 @@ class Manager
{
public:
Manager(const std::string& sessionName, std::string deviceId, size_t size, const ProgOptions* config)
: fShmId(makeShmIdStr(sessionName))
: fShmId64(makeShmIdUint64(sessionName))
, fShmId(makeShmIdStr(sessionName))
, fSegmentId(config ? config->GetProperty<uint16_t>("shm-segment-id", 0) : 0)
, fDeviceId(std::move(deviceId))
, fSegments()
Expand Down Expand Up @@ -337,8 +339,8 @@ class Manager

// fast path
for (const auto &lRegion : lTlCacheVec) {
if ((lRegion.second == id) && (lTlCacheGen == fRegionsGen)) {
return lRegion.first;
if ((std::get<1>(lRegion) == id) && (lTlCacheGen == fRegionsGen) && (std::get<2>(lRegion) == fShmId64)) {
return std::get<0>(lRegion);
}
}

Expand All @@ -349,7 +351,7 @@ class Manager
}

auto *lRegion = GetRegionUnsafe(id);
fTlRegionCache.fRegionsTLCache.emplace_back(std::make_pair(lRegion, id));
fTlRegionCache.fRegionsTLCache.emplace_back(std::make_tuple(lRegion, id, fShmId64));
fTlRegionCache.fRegionsTLCacheGen = fRegionsGen;
return lRegion;
}
Expand Down Expand Up @@ -670,6 +672,7 @@ class Manager
}

private:
uint64_t fShmId64;
std::string fShmId;
uint16_t fSegmentId;
std::string fDeviceId;
Expand All @@ -694,7 +697,7 @@ class Manager
alignas(128) inline static std::atomic<unsigned long> fRegionsGen = 0ul;
inline static thread_local struct ManagerTLCache {
unsigned long fRegionsTLCacheGen;
std::vector<std::pair<Region*, uint16_t>> fRegionsTLCache;
std::vector<std::tuple<Region*, uint16_t, uint64_t>> fRegionsTLCache;
} fTlRegionCache;

std::atomic<bool> fInterrupted;
Expand Down

0 comments on commit 2ca62d0

Please sign in to comment.