[compiler-rt] c8bf93d - [scudo] Remove RSS checking code.
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 12:35:30 PDT 2023
Author: Christopher Ferris
Date: 2023-08-30T12:35:14-07:00
New Revision: c8bf93dba0a28ee5e5f2c4c1e31786905fedb5be
URL: https://github.com/llvm/llvm-project/commit/c8bf93dba0a28ee5e5f2c4c1e31786905fedb5be
DIFF: https://github.com/llvm/llvm-project/commit/c8bf93dba0a28ee5e5f2c4c1e31786905fedb5be.diff
LOG: [scudo] Remove RSS checking code.
The RSS code is not very useful and can be replicated by using
ulimit. Remove it and remove the options associated with it.
Reviewed By: Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D159155
Added:
Modified:
compiler-rt/lib/scudo/standalone/CMakeLists.txt
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/common.cpp
compiler-rt/lib/scudo/standalone/common.h
compiler-rt/lib/scudo/standalone/flags.inc
compiler-rt/lib/scudo/standalone/linux.cpp
compiler-rt/lib/scudo/standalone/report.cpp
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
compiler-rt/lib/scudo/standalone/tests/common_test.cpp
Removed:
compiler-rt/lib/scudo/standalone/rss_limit_checker.cpp
compiler-rt/lib/scudo/standalone/rss_limit_checker.h
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 52c3a2e5a52956..2b7a613066b83b 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -83,7 +83,6 @@ set(SCUDO_HEADERS
quarantine.h
release.h
report.h
- rss_limit_checker.h
secondary.h
size_class_map.h
stack_depot.h
@@ -113,7 +112,6 @@ set(SCUDO_SOURCES
mem_map_linux.cpp
release.cpp
report.cpp
- rss_limit_checker.cpp
string_utils.cpp
timing.cpp
)
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 8cc84adcd4843b..12f229610921e9 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -18,7 +18,6 @@
#include "options.h"
#include "quarantine.h"
#include "report.h"
-#include "rss_limit_checker.h"
#include "secondary.h"
#include "stack_depot.h"
#include "string_utils.h"
@@ -149,9 +148,6 @@ class Allocator {
initFlags();
reportUnrecognizedFlags();
- RssChecker.init(scudo::getFlags()->soft_rss_limit_mb,
- scudo::getFlags()->hard_rss_limit_mb);
-
// Store some flags locally.
if (getFlags()->may_return_null)
Primary.Options.set(OptionBit::MayReturnNull);
@@ -361,19 +357,6 @@ class Allocator {
}
DCHECK_LE(Size, NeededSize);
- switch (RssChecker.getRssLimitExceeded()) {
- case RssLimitChecker::Neither:
- break;
- case RssLimitChecker::Soft:
- if (Options.get(OptionBit::MayReturnNull))
- return nullptr;
- reportSoftRSSLimit(RssChecker.getSoftRssLimit());
- break;
- case RssLimitChecker::Hard:
- reportHardRSSLimit(RssChecker.getHardRssLimit());
- break;
- }
-
void *Block = nullptr;
uptr ClassId = 0;
uptr SecondaryBlockEnd = 0;
@@ -884,13 +867,6 @@ class Allocator {
Header.State == Chunk::State::Allocated;
}
- void setRssLimitsTestOnly(int SoftRssLimitMb, int HardRssLimitMb,
- bool MayReturnNull) {
- RssChecker.init(SoftRssLimitMb, HardRssLimitMb);
- if (MayReturnNull)
- Primary.Options.set(OptionBit::MayReturnNull);
- }
-
bool useMemoryTaggingTestOnly() const {
return useMemoryTagging<Config>(Primary.Options.load());
}
@@ -1050,7 +1026,6 @@ class Allocator {
QuarantineT Quarantine;
TSDRegistryT TSDRegistry;
pthread_once_t PostInitNonce = PTHREAD_ONCE_INIT;
- RssLimitChecker RssChecker;
#ifdef GWP_ASAN_HOOKS
gwp_asan::GuardedPoolAllocator GuardedAlloc;
diff --git a/compiler-rt/lib/scudo/standalone/common.cpp b/compiler-rt/lib/scudo/standalone/common.cpp
index 9f14faeef283ce..666f95400c7e7a 100644
--- a/compiler-rt/lib/scudo/standalone/common.cpp
+++ b/compiler-rt/lib/scudo/standalone/common.cpp
@@ -35,8 +35,4 @@ void NORETURN dieOnMapUnmapError(uptr SizeIfOOM) {
die();
}
-#if !SCUDO_LINUX
-uptr GetRSS() { return 0; }
-#endif
-
} // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/common.h b/compiler-rt/lib/scudo/standalone/common.h
index c39b8b20d5414d..db5f20f7acdc49 100644
--- a/compiler-rt/lib/scudo/standalone/common.h
+++ b/compiler-rt/lib/scudo/standalone/common.h
@@ -146,8 +146,6 @@ u32 getNumberOfCPUs();
const char *getEnv(const char *Name);
-uptr GetRSS();
-
u64 getMonotonicTime();
// Gets the time faster but with less accuracy. Can call getMonotonicTime
// if no fast version is available.
diff --git a/compiler-rt/lib/scudo/standalone/flags.inc b/compiler-rt/lib/scudo/standalone/flags.inc
index c1f153bafdd96e..60aeb1f1df570a 100644
--- a/compiler-rt/lib/scudo/standalone/flags.inc
+++ b/compiler-rt/lib/scudo/standalone/flags.inc
@@ -46,14 +46,5 @@ SCUDO_FLAG(int, release_to_os_interval_ms, SCUDO_ANDROID ? INT32_MIN : 5000,
"Interval (in milliseconds) at which to attempt release of unused "
"memory to the OS. Negative values disable the feature.")
-SCUDO_FLAG(int, hard_rss_limit_mb, 0,
- "Hard RSS Limit in Mb. If non-zero, once the limit is achieved, "
- "abort the process")
-
-SCUDO_FLAG(int, soft_rss_limit_mb, 0,
- "Soft RSS Limit in Mb. If non-zero, once the limit is reached, all "
- "subsequent calls will fail or return NULL until the RSS goes below "
- "the soft limit")
-
SCUDO_FLAG(int, allocation_ring_buffer_size, 32768,
"Entries to keep in the allocation ring buffer for scudo.")
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index 54d0461bb4fa0b..c31c3d2483a97a 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -203,39 +203,6 @@ bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) {
extern "C" WEAK int async_safe_write_log(int pri, const char *tag,
const char *msg);
-static uptr GetRSSFromBuffer(const char *Buf) {
- // The format of the file is:
- // 1084 89 69 11 0 79 0
- // We need the second number which is RSS in pages.
- const char *Pos = Buf;
- // Skip the first number.
- while (*Pos >= '0' && *Pos <= '9')
- Pos++;
- // Skip whitespaces.
- while (!(*Pos >= '0' && *Pos <= '9') && *Pos != 0)
- Pos++;
- // Read the number.
- u64 Rss = 0;
- for (; *Pos >= '0' && *Pos <= '9'; Pos++)
- Rss = Rss * 10 + static_cast<u64>(*Pos) - '0';
- return static_cast<uptr>(Rss * getPageSizeCached());
-}
-
-uptr GetRSS() {
- // TODO: We currently use sanitizer_common's GetRSS which reads the
- // RSS from /proc/self/statm by default. We might want to
- // call getrusage directly, even if it's less accurate.
- auto Fd = open("/proc/self/statm", O_RDONLY);
- char Buf[64];
- s64 Len = read(Fd, Buf, sizeof(Buf) - 1);
- close(Fd);
- if (Len <= 0)
- return 0;
- Buf[Len] = 0;
-
- return GetRSSFromBuffer(Buf);
-}
-
void outputRaw(const char *Buffer) {
if (&async_safe_write_log) {
constexpr s32 AndroidLogInfo = 4;
diff --git a/compiler-rt/lib/scudo/standalone/report.cpp b/compiler-rt/lib/scudo/standalone/report.cpp
index 81b3dce4e02c1f..f126bc6eb5412b 100644
--- a/compiler-rt/lib/scudo/standalone/report.cpp
+++ b/compiler-rt/lib/scudo/standalone/report.cpp
@@ -36,18 +36,6 @@ class ScopedErrorReport {
inline void NORETURN trap() { __builtin_trap(); }
-void NORETURN reportSoftRSSLimit(uptr RssLimitMb) {
- ScopedErrorReport Report;
- Report.append("Soft RSS limit of %zu MB exhausted, current RSS is %zu MB\n",
- RssLimitMb, GetRSS() >> 20);
-}
-
-void NORETURN reportHardRSSLimit(uptr RssLimitMb) {
- ScopedErrorReport Report;
- Report.append("Hard RSS limit of %zu MB exhausted, current RSS is %zu MB\n",
- RssLimitMb, GetRSS() >> 20);
-}
-
// This could potentially be called recursively if a CHECK fails in the reports.
void NORETURN reportCheckFailed(const char *File, int Line,
const char *Condition, u64 Value1, u64 Value2) {
diff --git a/compiler-rt/lib/scudo/standalone/rss_limit_checker.cpp b/compiler-rt/lib/scudo/standalone/rss_limit_checker.cpp
deleted file mode 100644
index f428386b755c8f..00000000000000
--- a/compiler-rt/lib/scudo/standalone/rss_limit_checker.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//===-- common.cpp ----------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "rss_limit_checker.h"
-#include "atomic_helpers.h"
-#include "string_utils.h"
-
-namespace scudo {
-
-void RssLimitChecker::check(u64 NextCheck) {
- // The interval for the checks is 250ms.
- static constexpr u64 CheckInterval = 250 * 1000000;
-
- // Early return in case another thread already did the calculation.
- if (!atomic_compare_exchange_strong(&RssNextCheckAtNS, &NextCheck,
- getMonotonicTime() + CheckInterval,
- memory_order_relaxed)) {
- return;
- }
-
- const uptr CurrentRssMb = GetRSS() >> 20;
-
- RssLimitExceeded Result = RssLimitExceeded::Neither;
- if (UNLIKELY(HardRssLimitMb && HardRssLimitMb < CurrentRssMb))
- Result = RssLimitExceeded::Hard;
- else if (UNLIKELY(SoftRssLimitMb && SoftRssLimitMb < CurrentRssMb))
- Result = RssLimitExceeded::Soft;
-
- atomic_store_relaxed(&RssLimitStatus, static_cast<u8>(Result));
-}
-
-} // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/rss_limit_checker.h b/compiler-rt/lib/scudo/standalone/rss_limit_checker.h
deleted file mode 100644
index 29dc063f3fc4ec..00000000000000
--- a/compiler-rt/lib/scudo/standalone/rss_limit_checker.h
+++ /dev/null
@@ -1,63 +0,0 @@
-//===-- common.h ------------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef SCUDO_RSS_LIMIT_CHECKER_H_
-#define SCUDO_RSS_LIMIT_CHECKER_H_
-
-#include "atomic_helpers.h"
-#include "common.h"
-#include "internal_defs.h"
-
-namespace scudo {
-
-class RssLimitChecker {
-public:
- enum RssLimitExceeded {
- Neither,
- Soft,
- Hard,
- };
-
- void init(int SoftRssLimitMb, int HardRssLimitMb) {
- CHECK_GE(SoftRssLimitMb, 0);
- CHECK_GE(HardRssLimitMb, 0);
- this->SoftRssLimitMb = static_cast<uptr>(SoftRssLimitMb);
- this->HardRssLimitMb = static_cast<uptr>(HardRssLimitMb);
- }
-
- // Opportunistic RSS limit check. This will update the RSS limit status, if
- // it can, every 250ms, otherwise it will just return the current one.
- RssLimitExceeded getRssLimitExceeded() {
- if (!HardRssLimitMb && !SoftRssLimitMb)
- return RssLimitExceeded::Neither;
-
- u64 NextCheck = atomic_load_relaxed(&RssNextCheckAtNS);
- u64 Now = getMonotonicTime();
-
- if (UNLIKELY(Now >= NextCheck))
- check(NextCheck);
-
- return static_cast<RssLimitExceeded>(atomic_load_relaxed(&RssLimitStatus));
- }
-
- uptr getSoftRssLimit() const { return SoftRssLimitMb; }
- uptr getHardRssLimit() const { return HardRssLimitMb; }
-
-private:
- void check(u64 NextCheck);
-
- uptr SoftRssLimitMb = 0;
- uptr HardRssLimitMb = 0;
-
- atomic_u64 RssNextCheckAtNS = {};
- atomic_u8 RssLimitStatus = {};
-};
-
-} // namespace scudo
-
-#endif // SCUDO_RSS_LIMIT_CHECKER_H_
diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 83135f9bd337db..6d381eab645115 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -794,41 +794,3 @@ TEST(ScudoCombinedTest, BasicTrustyConfig) {
#endif
#endif
-
-#if SCUDO_LINUX
-
-SCUDO_TYPED_TEST(ScudoCombinedTest, SoftRssLimit) {
- auto *Allocator = this->Allocator.get();
- Allocator->setRssLimitsTestOnly(1, 0, true);
-
- size_t Megabyte = 1024 * 1024;
- size_t ChunkSize = 16;
- size_t Error = 256;
-
- std::vector<void *> Ptrs;
- for (size_t index = 0; index < Megabyte + Error; index += ChunkSize) {
- void *Ptr = Allocator->allocate(ChunkSize, Origin);
- Ptrs.push_back(Ptr);
- }
-
- EXPECT_EQ(nullptr, Allocator->allocate(ChunkSize, Origin));
-
- for (void *Ptr : Ptrs)
- Allocator->deallocate(Ptr, Origin);
-}
-
-SCUDO_TYPED_TEST(ScudoCombinedTest, HardRssLimit) {
- auto *Allocator = this->Allocator.get();
- Allocator->setRssLimitsTestOnly(0, 1, false);
-
- size_t Megabyte = 1024 * 1024;
-
- EXPECT_DEATH(
- {
- disableDebuggerdMaybe();
- Allocator->allocate(Megabyte, Origin);
- },
- "");
-}
-
-#endif
diff --git a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
index b1e55e80d09bf0..fff7c662a41bcd 100644
--- a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
@@ -72,27 +72,4 @@ TEST(ScudoCommonTest, Zeros) {
MemMap.unmap(MemMap.getBase(), Size);
}
-#if 0
-// This test is temorarily disabled because it may not work as expected. E.g.,
-// it doesn't dirty the pages so the pages may not be commited and it may only
-// work on the single thread environment. As a result, this test is flaky and is
-// impacting many test scenarios.
-TEST(ScudoCommonTest, GetRssFromBuffer) {
- constexpr int64_t AllocSize = 10000000;
- constexpr int64_t Error = 3000000;
- constexpr size_t Runs = 10;
-
- int64_t Rss = scudo::GetRSS();
- EXPECT_GT(Rss, 0);
-
- std::vector<std::unique_ptr<char[]>> Allocs(Runs);
- for (auto &Alloc : Allocs) {
- Alloc.reset(new char[AllocSize]());
- int64_t Prev = Rss;
- Rss = scudo::GetRSS();
- EXPECT_LE(std::abs(Rss - AllocSize - Prev), Error);
- }
-}
-#endif
-
} // namespace scudo
More information about the llvm-commits
mailing list