mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
a4d18475f9
Summary: This fixes a deadlock where the kernel held the memory manager lock while satisfying a page fault resulting in a call into Eden, which tried to read /proc/pid/cmdline, acquiring the memory manager lock again. The fix is to never read /proc/pid/cmdline while handling a request. That work is now done on a background thread. Reviewed By: strager Differential Revision: D13685318 fbshipit-source-id: c4e17de3358b668638db0c2dcfba8536d05e5b7c
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#include "eden/fs/utils/ProcessNameCache.h"
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace std::literals;
|
|
using namespace facebook::eden;
|
|
|
|
TEST(ProcessNameCache, getProcPidCmdLine) {
|
|
using namespace facebook::eden::detail;
|
|
EXPECT_EQ("/proc/0/cmdline"s, getProcPidCmdLine(0).data());
|
|
EXPECT_EQ("/proc/1234/cmdline"s, getProcPidCmdLine(1234).data());
|
|
EXPECT_EQ("/proc/1234/cmdline"s, getProcPidCmdLine(1234).data());
|
|
|
|
auto longestPath = getProcPidCmdLine(std::numeric_limits<pid_t>::max());
|
|
EXPECT_EQ(longestPath.size(), strlen(longestPath.data()) + 1);
|
|
}
|
|
|
|
TEST(ProcessNameCache, readMyPidsName) {
|
|
ProcessNameCache processNameCache;
|
|
processNameCache.add(getpid());
|
|
auto results = processNameCache.getAllProcessNames();
|
|
EXPECT_NE("", results[getpid()]);
|
|
}
|
|
|
|
TEST(ProcessNameCache, expireMyPidsName) {
|
|
ProcessNameCache processNameCache{0ms};
|
|
processNameCache.add(getpid());
|
|
auto results = processNameCache.getAllProcessNames();
|
|
EXPECT_EQ(0, results.size());
|
|
}
|
|
|
|
TEST(ProcessNameCache, addFromMultipleThreads) {
|
|
ProcessNameCache processNameCache;
|
|
|
|
size_t kThreadCount = 32;
|
|
std::vector<std::thread> threads;
|
|
threads.reserve(kThreadCount);
|
|
for (size_t i = 0; i < kThreadCount; ++i) {
|
|
threads.emplace_back([&] { processNameCache.add(getpid()); });
|
|
}
|
|
|
|
auto results = processNameCache.getAllProcessNames();
|
|
|
|
for (auto& thread : threads) {
|
|
thread.join();
|
|
}
|
|
EXPECT_EQ(1, results.size());
|
|
}
|