diff options
author | Alexander Smirnov <alex@ydb.tech> | 2025-02-06 00:51:36 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2025-02-06 00:51:36 +0000 |
commit | 56094433309e9ee14b6be144db40dd8c200df4c6 (patch) | |
tree | e331c04c654370c8d6d5578b8c81a7828c254eaf /library/cpp | |
parent | 95fac681074068aad4d6bc5a02b1d7a153de5a09 (diff) | |
parent | 37bab6825374df518e0b1cb748ce7bd2cef55688 (diff) | |
download | ydb-56094433309e9ee14b6be144db40dd8c200df4c6.tar.gz |
Merge branch 'rightlib' into merge-libs-250206-0050
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.cpp | 51 | ||||
-rw-r--r-- | library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.h | 13 | ||||
-rw-r--r-- | library/cpp/yt/backtrace/absl_unwinder/ya.make | 14 | ||||
-rw-r--r-- | library/cpp/yt/memory/blob.cpp | 12 | ||||
-rw-r--r-- | library/cpp/yt/mlock/README.md | 11 | ||||
-rw-r--r-- | library/cpp/yt/mlock/mlock.h | 11 | ||||
-rw-r--r-- | library/cpp/yt/mlock/mlock_linux.cpp | 89 | ||||
-rw-r--r-- | library/cpp/yt/mlock/mlock_other.cpp | 14 | ||||
-rw-r--r-- | library/cpp/yt/mlock/unittests/mlock_ut.cpp | 19 | ||||
-rw-r--r-- | library/cpp/yt/mlock/unittests/ya.make | 13 | ||||
-rw-r--r-- | library/cpp/yt/mlock/ya.make | 16 | ||||
-rw-r--r-- | library/cpp/yt/threading/traceless_guard-inl.h | 115 | ||||
-rw-r--r-- | library/cpp/yt/threading/traceless_guard.h | 29 |
13 files changed, 11 insertions, 396 deletions
diff --git a/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.cpp b/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.cpp deleted file mode 100644 index 429598e3b16..00000000000 --- a/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "absl_unwinder.h" - -#include <library/cpp/yt/backtrace/cursors/libunwind/libunwind_cursor.h> - -#include <absl/debugging/stacktrace.h> - -namespace NYT::NBacktrace { - -//////////////////////////////////////////////////////////////////////////////// - -namespace { - -int AbslStackUnwinder( - void** frames, - int* /*framesSizes*/, - int maxFrames, - int skipFrames, - const void* /*uc*/, - int* /*minDroppedFrames*/) -{ - NBacktrace::TLibunwindCursor cursor; - - for (int i = 0; i < skipFrames + 1; ++i) { - cursor.MoveNext(); - } - - int count = 0; - for (int i = 0; i < maxFrames; ++i) { - if (cursor.IsFinished()) { - return count; - } - - // IP point's to return address. Subtract 1 to get accurate line information for profiler. - frames[i] = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(cursor.GetCurrentIP()) - 1); - count++; - - cursor.MoveNext(); - } - return count; -} - -} // namespace - -void SetAbslStackUnwinder() -{ - absl::SetStackUnwinder(AbslStackUnwinder); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NBacktrace diff --git a/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.h b/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.h deleted file mode 100644 index 9a23c582c53..00000000000 --- a/library/cpp/yt/backtrace/absl_unwinder/absl_unwinder.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace NYT::NBacktrace { - -//////////////////////////////////////////////////////////////////////////////// - -//! Configures Abseil to use a libunwind-based stack unwinder. -//! This is useful, e.g., for collecting TCMalloc heap dumps. -void SetAbslStackUnwinder(); - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NBacktrace diff --git a/library/cpp/yt/backtrace/absl_unwinder/ya.make b/library/cpp/yt/backtrace/absl_unwinder/ya.make deleted file mode 100644 index f6bb0fbb5a6..00000000000 --- a/library/cpp/yt/backtrace/absl_unwinder/ya.make +++ /dev/null @@ -1,14 +0,0 @@ -LIBRARY() - -INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc) - -SRCS( - absl_unwinder.cpp -) - -PEERDIR( - library/cpp/yt/backtrace/cursors/libunwind - contrib/libs/tcmalloc/malloc_extension -) - -END() diff --git a/library/cpp/yt/memory/blob.cpp b/library/cpp/yt/memory/blob.cpp index b4de038948c..2517446ec7e 100644 --- a/library/cpp/yt/memory/blob.cpp +++ b/library/cpp/yt/memory/blob.cpp @@ -4,6 +4,8 @@ #include <library/cpp/yt/malloc/malloc.h> +#include <library/cpp/yt/system/exit.h> + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -147,9 +149,17 @@ void TBlob::Reset() char* TBlob::DoAllocate(size_t size) { - return static_cast<char*>(PageAligned_ + auto* allocated = static_cast<char*>(PageAligned_ ? ::aligned_malloc(size, GetPageSize()) : ::malloc(size)); + + if (Y_UNLIKELY(!allocated)) { + AbortProcessDramatically( + EProcessExitCode::OutOfMemory, + "Out-of-memory during TBlob allocation"); + } + + return allocated; } void TBlob::Allocate(size_t newCapacity) diff --git a/library/cpp/yt/mlock/README.md b/library/cpp/yt/mlock/README.md deleted file mode 100644 index b61b6072c4d..00000000000 --- a/library/cpp/yt/mlock/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# mlock - -MlockFileMappings подгружает и лочит в память все страницы исполняемого файла. - -В отличии от вызова mlockall, функция не лочит другие страницы процесса. -mlockall явно выделяет физическую память под все vma. Типичный процесс сначала -стартует и инициализирует аллокатор, а потом уже вызывает функцию для mlock страниц. -Аллокатор при старте выделяет большие диапазоны через mmap, но реально их не использует. -Поэтому mlockall приводит в повышенному потреблению памяти. - -Также, в отличии от mlockall, функция может подгрузить страницы в память сразу. diff --git a/library/cpp/yt/mlock/mlock.h b/library/cpp/yt/mlock/mlock.h deleted file mode 100644 index 035fc47e373..00000000000 --- a/library/cpp/yt/mlock/mlock.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -bool MlockFileMappings(bool populate = true); - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/library/cpp/yt/mlock/mlock_linux.cpp b/library/cpp/yt/mlock/mlock_linux.cpp deleted file mode 100644 index 8791869f951..00000000000 --- a/library/cpp/yt/mlock/mlock_linux.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "mlock.h" - -#include <stdio.h> -#include <sys/mman.h> -#include <stdint.h> -#include <inttypes.h> - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -void PopulateFile(void* ptr, size_t size) -{ - constexpr size_t PageSize = 4096; - - auto* begin = static_cast<volatile char*>(ptr); - for (auto* current = begin; current < begin + size; current += PageSize) { - *current; - } -} - -bool MlockFileMappings(bool populate) -{ - auto* file = ::fopen("/proc/self/maps", "r"); - if (!file) { - return false; - } - - // Each line of /proc/<pid>/smaps has the following format: - // address perms offset dev inode path - // E.g. - // 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm - - bool failed = false; - while (true) { - char line[1024]; - if (!fgets(line, sizeof(line), file)) { - break; - } - - char addressStr[64]; - char permsStr[64]; - char offsetStr[64]; - char devStr[64]; - int inode; - if (sscanf(line, "%s %s %s %s %d", - addressStr, - permsStr, - offsetStr, - devStr, - &inode) != 5) - { - continue; - } - - if (inode == 0) { - continue; - } - - if (permsStr[0] != 'r') { - continue; - } - - uintptr_t startAddress; - uintptr_t endAddress; - if (sscanf(addressStr, "%" PRIx64 "-%" PRIx64, - &startAddress, - &endAddress) != 2) - { - continue; - } - - if (::mlock(reinterpret_cast<const void*>(startAddress), endAddress - startAddress) != 0) { - failed = true; - continue; - } - - if (populate) { - PopulateFile(reinterpret_cast<void*>(startAddress), endAddress - startAddress); - } - } - - ::fclose(file); - return !failed; -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/library/cpp/yt/mlock/mlock_other.cpp b/library/cpp/yt/mlock/mlock_other.cpp deleted file mode 100644 index 269c5c3cb98..00000000000 --- a/library/cpp/yt/mlock/mlock_other.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "mlock.h" - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -bool MlockFileMappings(bool /* populate */) -{ - return false; -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT diff --git a/library/cpp/yt/mlock/unittests/mlock_ut.cpp b/library/cpp/yt/mlock/unittests/mlock_ut.cpp deleted file mode 100644 index 98386622e8d..00000000000 --- a/library/cpp/yt/mlock/unittests/mlock_ut.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include <gtest/gtest.h> - -#include <library/cpp/yt/mlock/mlock.h> - -namespace NYT { -namespace { - -//////////////////////////////////////////////////////////////////////////////// - -TEST(TMlockTest, Call) -{ - ASSERT_TRUE(MlockFileMappings(false)); - ASSERT_TRUE(MlockFileMappings(true)); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace -} // namespace NYT
\ No newline at end of file diff --git a/library/cpp/yt/mlock/unittests/ya.make b/library/cpp/yt/mlock/unittests/ya.make deleted file mode 100644 index f1f956d4681..00000000000 --- a/library/cpp/yt/mlock/unittests/ya.make +++ /dev/null @@ -1,13 +0,0 @@ -GTEST() - -INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc) - -SRCS( - mlock_ut.cpp -) - -PEERDIR( - library/cpp/yt/mlock -) - -END() diff --git a/library/cpp/yt/mlock/ya.make b/library/cpp/yt/mlock/ya.make deleted file mode 100644 index 2603d128ed8..00000000000 --- a/library/cpp/yt/mlock/ya.make +++ /dev/null @@ -1,16 +0,0 @@ -LIBRARY() - -INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc) - -IF (OS_LINUX AND NOT SANITIZER_TYPE) - SRCS(mlock_linux.cpp) -ELSE() - SRCS(mlock_other.cpp) -ENDIF() - -END() - -IF (OS_LINUX AND NOT SANITIZER_TYPE) - RECURSE(unittests) -ENDIF() - diff --git a/library/cpp/yt/threading/traceless_guard-inl.h b/library/cpp/yt/threading/traceless_guard-inl.h deleted file mode 100644 index e03d5196c43..00000000000 --- a/library/cpp/yt/threading/traceless_guard-inl.h +++ /dev/null @@ -1,115 +0,0 @@ -#pragma once - -#ifndef TRACELESS_GUARD_INL_H_ -#error "Direct inclusion of this file is not allowed, include traceless_guard.h" -#endif -#undef TRACELESS_GUARD_INL_H_ - -#include "rw_spin_lock.h" -#include "spin_lock_count.h" - -#include <util/system/guard.h> - -#include <concepts> - -namespace NYT::NThreading::NPrivate { - -//////////////////////////////////////////////////////////////////////////////// - -#ifdef NDEBUG - -template <class T, class TOps = TCommonLockOps<T>> -using TTracelessGuard = TGuard<T, TOps>; - -template <class T, class TOps = TCommonLockOps<T>> -using TTracelessInverseGuard = TInverseGuard<T, TOps>; - -template <class T, class TOps = TTryLockOps<T>> -using TTracelessTryGuard = TTryGuard<T, TOps>; - -template <class T> -using TTracelessReaderGuard = TReaderGuard<T>; - -template <class T> -using TTracelessWriterGuard = TWriterGuard<T>; - -#else - -template <class TOps> -struct TTracelessOps - : public TOps -{ - template <class T> - static void Acquire(T* t) noexcept - { - TOps::Acquire(t); - NDetail::RecordSpinLockReleased(); - } - - template <class T> - static void Release(T* t) noexcept - { - NDetail::RecordSpinLockAcquired(); - TOps::Release(t); - } - - template <class T> - requires requires (T* t) { { TOps::TryAcquire(t) } -> std::same_as<bool>; } - static bool TryAcquire(T* t) noexcept - { - bool isAcquired = TOps::TryAcquire(t); - - if (isAcquired) { - NDetail::RecordSpinLockReleased(); - } - - return isAcquired; - } -}; - -template <CTrackedSpinLock T, class TOps = TCommonLockOps<T>> -using TTracelessGuard = TGuard<T, TTracelessOps<TOps>>; - -template <CTrackedSpinLock T, class TOps = TCommonLockOps<T>> -using TTracelessInverseGuard = TInverseGuard<T, TTracelessOps<TOps>>; - -template <CTrackedSpinLock T, class TOps = TTryLockOps<T>> -using TTracelessTryGuard = TTryGuard<T, TTracelessOps<TOps>>; - -template <CTrackedSpinLock T> -using TTracelessReaderGuard = TGuard<T, TTracelessOps<TReaderSpinlockTraits<T>>>; - -template <CTrackedSpinLock T> -using TTracelessWriterGuard = TGuard<T, TTracelessOps<TWriterSpinlockTraits<T>>>; - -#endif - -//////////////////////////////////////////////////////////////////////////////// - -template <CTrackedSpinLock T> -TTracelessGuard<T> TracelessGuard(const T& mutex) -{ - return {&mutex}; -} - -template <CTrackedSpinLock T> -TTracelessTryGuard<T> TracelessTryGuard(const T& mutex) -{ - return {&mutex}; -} - -template <CTrackedSpinLock T> -TTracelessReaderGuard<T> TracelessReaderGuard(const T& mutex) -{ - return {&mutex}; -} - -template <CTrackedSpinLock T> -TTracelessWriterGuard<T> TracelessWriterGuard(const T& mutex) -{ - return {&mutex}; -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NThreading::NPrivate diff --git a/library/cpp/yt/threading/traceless_guard.h b/library/cpp/yt/threading/traceless_guard.h deleted file mode 100644 index 10ad0ded986..00000000000 --- a/library/cpp/yt/threading/traceless_guard.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#define TRACELESS_GUARD_INL_H_ -#include "traceless_guard-inl.h" -#undef TRACELESS_GUARD_INL_H_ - -namespace NYT::NThreading { - -// This guards are zero-cost replacements for normal ones -// which allow user to avoid spinlocks being tracked. - -//////////////////////////////////////////////////////////////////////////////// - -using NPrivate::TTracelessGuard; -using NPrivate::TTracelessInverseGuard; -using NPrivate::TTracelessTryGuard; -using NPrivate::TTracelessReaderGuard; -using NPrivate::TTracelessWriterGuard; - -//////////////////////////////////////////////////////////////////////////////// - -using NPrivate::TracelessGuard; -using NPrivate::TracelessTryGuard; -using NPrivate::TracelessReaderGuard; -using NPrivate::TracelessWriterGuard; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NThreading |