fallback.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // This file contains the fallback implementations of YTAlloc-specific stuff.
  2. // These implementations are annotated with Y_WEAK to ensure that if the actual YTAlloc
  3. // is available at the link time, the latter is preferred over the fallback.
  4. #include "ytalloc.h"
  5. #include <util/system/compiler.h>
  6. #include <util/system/yassert.h>
  7. #include <cstdlib>
  8. namespace NYT::NYTAlloc {
  9. ////////////////////////////////////////////////////////////////////////////////
  10. Y_WEAK void* Allocate(size_t size)
  11. {
  12. return ::malloc(size);
  13. }
  14. Y_WEAK void* AllocatePageAligned(size_t size)
  15. {
  16. #if defined(_win_)
  17. return ::_aligned_malloc(size, PageSize);
  18. #elif defined(_darwin_) || !defined(_musl_)
  19. return ::valloc(size);
  20. #else
  21. return ::memalign(PageSize, size);
  22. #endif
  23. }
  24. Y_WEAK void* AllocateSmall(size_t rank)
  25. {
  26. return ::malloc(SmallRankToSize[rank]);
  27. }
  28. Y_WEAK void Free(void* ptr)
  29. {
  30. ::free(ptr);
  31. }
  32. Y_WEAK void FreeNonNull(void* ptr)
  33. {
  34. Y_ASSERT(ptr);
  35. ::free(ptr);
  36. }
  37. Y_WEAK size_t GetAllocationSize(const void* /*ptr*/)
  38. {
  39. return 0;
  40. }
  41. Y_WEAK size_t GetAllocationSize(size_t size)
  42. {
  43. return size;
  44. }
  45. ////////////////////////////////////////////////////////////////////////////////
  46. Y_WEAK void SetCurrentMemoryZone(EMemoryZone /*zone*/)
  47. { }
  48. Y_WEAK EMemoryZone GetCurrentMemoryZone()
  49. {
  50. return EMemoryZone::Normal;
  51. }
  52. Y_WEAK EMemoryZone GetAllocationMemoryZone(const void* /*ptr*/)
  53. {
  54. return EMemoryZone::Normal;
  55. }
  56. ////////////////////////////////////////////////////////////////////////////////
  57. Y_WEAK void SetCurrentFiberId(TFiberId /*id*/)
  58. { }
  59. Y_WEAK TFiberId GetCurrentFiberId()
  60. {
  61. return 0;
  62. }
  63. ////////////////////////////////////////////////////////////////////////////////
  64. Y_WEAK void EnableLogging(TLogHandler /*logHandler*/)
  65. { }
  66. ////////////////////////////////////////////////////////////////////////////////
  67. Y_WEAK void SetBacktraceProvider(TBacktraceProvider /*provider*/)
  68. { }
  69. Y_WEAK void SetBacktraceFormatter(TBacktraceFormatter /*formatter*/)
  70. { }
  71. ////////////////////////////////////////////////////////////////////////////////
  72. Y_WEAK void EnableStockpile()
  73. { }
  74. Y_WEAK void SetStockpileInterval(TDuration /*value*/)
  75. { }
  76. Y_WEAK void SetStockpileThreadCount(int /*value*/)
  77. { }
  78. Y_WEAK void SetStockpileSize(size_t /*value*/)
  79. { }
  80. Y_WEAK void SetLargeUnreclaimableCoeff(double /*value*/)
  81. { }
  82. Y_WEAK void SetMinLargeUnreclaimableBytes(size_t /*value*/)
  83. { }
  84. Y_WEAK void SetMaxLargeUnreclaimableBytes(size_t /*value*/)
  85. { }
  86. Y_WEAK void SetTimingEventThreshold(TDuration /*value*/)
  87. { }
  88. Y_WEAK void SetAllocationProfilingEnabled(bool /*value*/)
  89. { }
  90. Y_WEAK void SetAllocationProfilingSamplingRate(double /*rate*/)
  91. { }
  92. Y_WEAK void SetSmallArenaAllocationProfilingEnabled(size_t /*rank*/, bool /*value*/)
  93. { }
  94. Y_WEAK void SetLargeArenaAllocationProfilingEnabled(size_t /*rank*/, bool /*value*/)
  95. { }
  96. Y_WEAK void SetProfilingBacktraceDepth(int /*depth*/)
  97. { }
  98. Y_WEAK void SetMinProfilingBytesUsedToReport(size_t /*size*/)
  99. { }
  100. Y_WEAK void SetEnableEagerMemoryRelease(bool /*value*/)
  101. { }
  102. Y_WEAK void SetEnableMadvisePopulate(bool /*value*/)
  103. { }
  104. ////////////////////////////////////////////////////////////////////////////////
  105. Y_WEAK TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters()
  106. {
  107. return {};
  108. }
  109. Y_WEAK TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters()
  110. {
  111. return {};
  112. }
  113. Y_WEAK TEnumIndexedVector<ELargeCounter, ssize_t> GetLargeAllocationCounters()
  114. {
  115. return {};
  116. }
  117. Y_WEAK std::array<TEnumIndexedVector<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
  118. {
  119. return {};
  120. }
  121. Y_WEAK std::array<TEnumIndexedVector<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
  122. {
  123. return {};
  124. }
  125. Y_WEAK TEnumIndexedVector<EHugeCounter, ssize_t> GetHugeAllocationCounters()
  126. {
  127. return {};
  128. }
  129. Y_WEAK TEnumIndexedVector<ESystemCounter, ssize_t> GetSystemAllocationCounters()
  130. {
  131. return {};
  132. }
  133. Y_WEAK TEnumIndexedVector<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters()
  134. {
  135. return {};
  136. }
  137. Y_WEAK TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
  138. {
  139. return {};
  140. }
  141. ////////////////////////////////////////////////////////////////////////////////
  142. Y_WEAK std::vector<TProfiledAllocation> GetProfiledAllocationStatistics()
  143. {
  144. return {};
  145. }
  146. ////////////////////////////////////////////////////////////////////////////////
  147. } // namespace NYT::NYTAlloc