diff options
| author | babenko <[email protected]> | 2024-09-21 18:32:01 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2024-09-21 18:42:43 +0300 |
| commit | 22ec41df66d0db33b7c3870298dc2973c51c6241 (patch) | |
| tree | 8e167134b8ccbcc2336f14cac6a30a4d8264132c | |
| parent | 7deed162d9d0d42ef21eea39547befcd9e48a784 (diff) | |
Increase RC size to 64 bits
commit_hash:31d021c482ac2a3f99e86bf1a2aca7231c86c11d
| -rw-r--r-- | library/cpp/yt/memory/atomic_intrusive_ptr.h | 13 | ||||
| -rw-r--r-- | library/cpp/yt/memory/ref_counted-inl.h | 8 | ||||
| -rw-r--r-- | library/cpp/yt/memory/ref_counted.h | 6 | ||||
| -rw-r--r-- | yt/yt/library/profiling/solomon/sensor.h | 8 |
4 files changed, 17 insertions, 18 deletions
diff --git a/library/cpp/yt/memory/atomic_intrusive_ptr.h b/library/cpp/yt/memory/atomic_intrusive_ptr.h index ae0a307182d..72405053c09 100644 --- a/library/cpp/yt/memory/atomic_intrusive_ptr.h +++ b/library/cpp/yt/memory/atomic_intrusive_ptr.h @@ -6,13 +6,10 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -// Atomic ptr based on https://github.com/facebook/folly/blob/main/folly/concurrency/AtomicSharedPtr.h - -// Operators * and -> for TAtomicIntrusivePtr are useless because it is not safe to work with atomic ptr such way -// Safe usage is to convert to TIntrusivePtr. - -// Max TAtomicIntrusivePtr count per object is (2**16 = 2**32 / 2**16). - +//! Atomic pointer with split reference counting. +/* + * \see https://github.com/facebook/folly/blob/main/folly/concurrency/AtomicSharedPtr.h +*/ template <class T> class TAtomicIntrusivePtr { @@ -39,7 +36,7 @@ public: bool CompareAndSwap(TRawPtr& comparePtr, T* target); bool CompareAndSwap(TRawPtr& comparePtr, TIntrusivePtr<T> target); - // Result is suitable only for comparison. Not dereference. + //! Result is only suitable for comparison, not dereference. TRawPtr Get() const; explicit operator bool() const; diff --git a/library/cpp/yt/memory/ref_counted-inl.h b/library/cpp/yt/memory/ref_counted-inl.h index 9ffdf328ebf..6c20db8c41b 100644 --- a/library/cpp/yt/memory/ref_counted-inl.h +++ b/library/cpp/yt/memory/ref_counted-inl.h @@ -90,7 +90,7 @@ Y_FORCE_INLINE void DestroyRefCountedImpl(T* obj) return; } - YT_ASSERT(offset < std::numeric_limits<ui16>::max()); + YT_ASSERT(offset < (1ULL << PackedPtrTagBits)); auto* vTablePtr = reinterpret_cast<TPackedPtr*>(basePtr); *vTablePtr = TTaggedPtr<void(void*, ui16)>(&NYT::NDetail::TMemoryReleaser<T>::Do, offset).Pack(); @@ -187,7 +187,7 @@ Y_FORCE_INLINE void TRefCounter::Ref(int n) const noexcept // It is safe to use relaxed here, since new reference is always created from another live reference. auto value = StrongCount_.fetch_add(n, std::memory_order::relaxed); YT_ASSERT(value > 0); - YT_ASSERT(value <= std::numeric_limits<int>::max() - n); + YT_ASSERT(value <= std::numeric_limits<TRefCount>::max() - n); YT_ASSERT(WeakCount_.load(std::memory_order::relaxed) > 0); } @@ -199,7 +199,7 @@ Y_FORCE_INLINE void TRefCounter::DangerousRef(int n) const noexcept // Relaxed is fine as per lukyan@, the caller guarantees object liveness. auto value = StrongCount_.fetch_add(n, std::memory_order::relaxed); YT_ASSERT(value >= 0); - YT_ASSERT(value <= std::numeric_limits<int>::max() - n); + YT_ASSERT(value <= std::numeric_limits<TRefCount>::max() - n); YT_ASSERT(WeakCount_.load(std::memory_order::relaxed) > 0); } @@ -207,7 +207,7 @@ Y_FORCE_INLINE void TRefCounter::DangerousRef(int n) const noexcept Y_FORCE_INLINE bool TRefCounter::TryRef() const noexcept { auto value = StrongCount_.load(std::memory_order::relaxed); - YT_ASSERT(value >= 0 && value < std::numeric_limits<int>::max()); + YT_ASSERT(value >= 0 && value < std::numeric_limits<TRefCount>::max()); YT_ASSERT(WeakCount_.load(std::memory_order::relaxed) > 0); while (value != 0 && !StrongCount_.compare_exchange_weak(value, value + 1)); diff --git a/library/cpp/yt/memory/ref_counted.h b/library/cpp/yt/memory/ref_counted.h index ed55aee6ee0..6abef3bf053 100644 --- a/library/cpp/yt/memory/ref_counted.h +++ b/library/cpp/yt/memory/ref_counted.h @@ -63,8 +63,10 @@ public: bool WeakUnref() const; private: - mutable std::atomic<int> StrongCount_ = 1; - mutable std::atomic<int> WeakCount_ = 1; + // NB: Must we 64 bit as TAtomicIntrusivePtr grabs refs in 64K batches. + using TRefCount = i64; + mutable std::atomic<TRefCount> StrongCount_ = 1; + mutable std::atomic<TRefCount> WeakCount_ = 1; }; //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/library/profiling/solomon/sensor.h b/yt/yt/library/profiling/solomon/sensor.h index 3ac491ef599..c81055ea149 100644 --- a/yt/yt/library/profiling/solomon/sensor.h +++ b/yt/yt/library/profiling/solomon/sensor.h @@ -62,7 +62,7 @@ private: std::atomic<i64> Value_ = 0; }; -static_assert(sizeof(TSimpleCounter) == 24); +static_assert(sizeof(TSimpleCounter) == 32); //////////////////////////////////////////////////////////////////////////////// @@ -75,10 +75,10 @@ public: TDuration GetValue() override; private: - std::atomic<TDuration::TValue> Value_{0}; + std::atomic<TDuration::TValue> Value_ = 0; }; -static_assert(sizeof(TSimpleTimeCounter) == 24); +static_assert(sizeof(TSimpleTimeCounter) == 32); //////////////////////////////////////////////////////////////////////////////// @@ -108,7 +108,7 @@ class THistogram , public IHistogramImpl { public: - THistogram(const TSensorOptions& options); + explicit THistogram(const TSensorOptions& options); void Record(TDuration value) override; |
