aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/ytalloc/api/ytalloc-inl.h
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.ru>2022-02-10 16:49:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:19 +0300
commitcec37806d8847aa3db53bafc9e251d4aaf325c12 (patch)
tree4a61c191e93e31d9ab423e258c71ab43550ee3d2 /library/cpp/ytalloc/api/ytalloc-inl.h
parent58cd0b86ed99a72df22479e26a20bc1c1e57e65e (diff)
downloadydb-cec37806d8847aa3db53bafc9e251d4aaf325c12.tar.gz
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/ytalloc/api/ytalloc-inl.h')
-rw-r--r--library/cpp/ytalloc/api/ytalloc-inl.h210
1 files changed, 105 insertions, 105 deletions
diff --git a/library/cpp/ytalloc/api/ytalloc-inl.h b/library/cpp/ytalloc/api/ytalloc-inl.h
index 263108423d..8b698a3125 100644
--- a/library/cpp/ytalloc/api/ytalloc-inl.h
+++ b/library/cpp/ytalloc/api/ytalloc-inl.h
@@ -1,105 +1,105 @@
-#pragma once
-#ifndef YT_ALLOC_INL_H_
-#error "Direct inclusion of this file is not allowed, include ytalloc.h"
-// For the sake of sane code completion.
-#include "ytalloc.h"
-#endif
-
-#include <util/system/types.h>
-
-namespace NYT::NYTAlloc {
-
-////////////////////////////////////////////////////////////////////////////////
-
-// Maps small chunk ranks to size in bytes.
-constexpr ui16 SmallRankToSize[SmallRankCount] = {
- 0,
- 16, 32, 48, 64, 96, 128,
- 192, 256, 384, 512, 768, 1024, 1536, 2048,
- 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768
-};
-
-// Helper array for mapping size to small chunk rank.
-constexpr ui8 SizeToSmallRank1[65] = {
- 1, 1, 1, 2, 2, // 16, 32
- 3, 3, 4, 4, // 48, 64
- 5, 5, 5, 5, 6, 6, 6, 6, // 96, 128
- 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, // 192, 256
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 384
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 // 512
-};
-
-// Helper array for mapping size to small chunk rank.
-constexpr unsigned char SizeToSmallRank2[128] = {
- 10, 10, 11, 12, // 512, 512, 768, 1022
- 13, 13, 14, 14, // 1536, 2048
- 15, 15, 15, 15, 16, 16, 16, 16, // 3072, 4096
- 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, // 6144, 8192
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // 12288
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 16384
- 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
- 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, // 22576
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22 // 32768
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-constexpr size_t SizeToSmallRank(size_t size)
-{
- if (size <= 512) {
- return SizeToSmallRank1[(size + 7) >> 3];
- } else {
- if (size <= LargeAllocationSizeThreshold) {
- return SizeToSmallRank2[(size - 1) >> 8];
- } else {
- return 0;
- }
- }
-}
-
-void* AllocateSmall(size_t rank);
-
-template <size_t Size>
-void* AllocateConstSize()
-{
- constexpr auto rank = SizeToSmallRank(Size);
- if constexpr(rank != 0) {
- return AllocateSmall(rank);
- } else {
- return Allocate(Size);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-inline TMemoryTagGuard::TMemoryTagGuard()
- : Active_(false)
- , PreviousTag_(NullMemoryTag)
-{ }
-
-inline TMemoryTagGuard::TMemoryTagGuard(TMemoryTag tag)
- : Active_(true)
- , PreviousTag_(GetCurrentMemoryTag())
-{
- SetCurrentMemoryTag(tag);
-}
-
-inline TMemoryTagGuard::TMemoryTagGuard(TMemoryTagGuard&& other)
- : Active_(other.Active_)
- , PreviousTag_(other.PreviousTag_)
-{
- other.Active_ = false;
- other.PreviousTag_ = NullMemoryTag;
-}
-
-inline TMemoryTagGuard::~TMemoryTagGuard()
-{
- if (Active_) {
- SetCurrentMemoryTag(PreviousTag_);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NYTAlloc
+#pragma once
+#ifndef YT_ALLOC_INL_H_
+#error "Direct inclusion of this file is not allowed, include ytalloc.h"
+// For the sake of sane code completion.
+#include "ytalloc.h"
+#endif
+
+#include <util/system/types.h>
+
+namespace NYT::NYTAlloc {
+
+////////////////////////////////////////////////////////////////////////////////
+
+// Maps small chunk ranks to size in bytes.
+constexpr ui16 SmallRankToSize[SmallRankCount] = {
+ 0,
+ 16, 32, 48, 64, 96, 128,
+ 192, 256, 384, 512, 768, 1024, 1536, 2048,
+ 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768
+};
+
+// Helper array for mapping size to small chunk rank.
+constexpr ui8 SizeToSmallRank1[65] = {
+ 1, 1, 1, 2, 2, // 16, 32
+ 3, 3, 4, 4, // 48, 64
+ 5, 5, 5, 5, 6, 6, 6, 6, // 96, 128
+ 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, // 192, 256
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 384
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 // 512
+};
+
+// Helper array for mapping size to small chunk rank.
+constexpr unsigned char SizeToSmallRank2[128] = {
+ 10, 10, 11, 12, // 512, 512, 768, 1022
+ 13, 13, 14, 14, // 1536, 2048
+ 15, 15, 15, 15, 16, 16, 16, 16, // 3072, 4096
+ 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, // 6144, 8192
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // 12288
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 16384
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, // 22576
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22 // 32768
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+constexpr size_t SizeToSmallRank(size_t size)
+{
+ if (size <= 512) {
+ return SizeToSmallRank1[(size + 7) >> 3];
+ } else {
+ if (size <= LargeAllocationSizeThreshold) {
+ return SizeToSmallRank2[(size - 1) >> 8];
+ } else {
+ return 0;
+ }
+ }
+}
+
+void* AllocateSmall(size_t rank);
+
+template <size_t Size>
+void* AllocateConstSize()
+{
+ constexpr auto rank = SizeToSmallRank(Size);
+ if constexpr(rank != 0) {
+ return AllocateSmall(rank);
+ } else {
+ return Allocate(Size);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+inline TMemoryTagGuard::TMemoryTagGuard()
+ : Active_(false)
+ , PreviousTag_(NullMemoryTag)
+{ }
+
+inline TMemoryTagGuard::TMemoryTagGuard(TMemoryTag tag)
+ : Active_(true)
+ , PreviousTag_(GetCurrentMemoryTag())
+{
+ SetCurrentMemoryTag(tag);
+}
+
+inline TMemoryTagGuard::TMemoryTagGuard(TMemoryTagGuard&& other)
+ : Active_(other.Active_)
+ , PreviousTag_(other.PreviousTag_)
+{
+ other.Active_ = false;
+ other.PreviousTag_ = NullMemoryTag;
+}
+
+inline TMemoryTagGuard::~TMemoryTagGuard()
+{
+ if (Active_) {
+ SetCurrentMemoryTag(PreviousTag_);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NYTAlloc