fallback.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 TMemoryTag GetCurrentMemoryTag()
  47. {
  48. return NullMemoryTag;
  49. }
  50. Y_WEAK void SetCurrentMemoryTag(TMemoryTag /*tag*/)
  51. { }
  52. Y_WEAK size_t GetMemoryUsageForTag(TMemoryTag /*tag*/)
  53. {
  54. return 0;
  55. }
  56. Y_WEAK void GetMemoryUsageForTags(const TMemoryTag* /*tags*/, size_t /*count*/, size_t* /*results*/)
  57. { }
  58. ////////////////////////////////////////////////////////////////////////////////
  59. Y_WEAK void SetCurrentMemoryZone(EMemoryZone /*zone*/)
  60. { }
  61. Y_WEAK EMemoryZone GetCurrentMemoryZone()
  62. {
  63. return EMemoryZone::Normal;
  64. }
  65. Y_WEAK EMemoryZone GetAllocationMemoryZone(const void* /*ptr*/)
  66. {
  67. return EMemoryZone::Normal;
  68. }
  69. ////////////////////////////////////////////////////////////////////////////////
  70. Y_WEAK void SetCurrentFiberId(TFiberId /*id*/)
  71. { }
  72. Y_WEAK TFiberId GetCurrentFiberId()
  73. {
  74. return 0;
  75. }
  76. ////////////////////////////////////////////////////////////////////////////////
  77. Y_WEAK void EnableLogging(TLogHandler /*logHandler*/)
  78. { }
  79. ////////////////////////////////////////////////////////////////////////////////
  80. Y_WEAK void SetBacktraceProvider(TBacktraceProvider /*provider*/)
  81. { }
  82. Y_WEAK void SetBacktraceFormatter(TBacktraceFormatter /*formatter*/)
  83. { }
  84. ////////////////////////////////////////////////////////////////////////////////
  85. Y_WEAK void EnableStockpile()
  86. { }
  87. Y_WEAK void SetStockpileInterval(TDuration /*value*/)
  88. { }
  89. Y_WEAK void SetStockpileThreadCount(int /*value*/)
  90. { }
  91. Y_WEAK void SetStockpileSize(size_t /*value*/)
  92. { }
  93. Y_WEAK void SetLargeUnreclaimableCoeff(double /*value*/)
  94. { }
  95. Y_WEAK void SetMinLargeUnreclaimableBytes(size_t /*value*/)
  96. { }
  97. Y_WEAK void SetMaxLargeUnreclaimableBytes(size_t /*value*/)
  98. { }
  99. Y_WEAK void SetTimingEventThreshold(TDuration /*value*/)
  100. { }
  101. Y_WEAK void SetAllocationProfilingEnabled(bool /*value*/)
  102. { }
  103. Y_WEAK void SetAllocationProfilingSamplingRate(double /*rate*/)
  104. { }
  105. Y_WEAK void SetSmallArenaAllocationProfilingEnabled(size_t /*rank*/, bool /*value*/)
  106. { }
  107. Y_WEAK void SetLargeArenaAllocationProfilingEnabled(size_t /*rank*/, bool /*value*/)
  108. { }
  109. Y_WEAK void SetProfilingBacktraceDepth(int /*depth*/)
  110. { }
  111. Y_WEAK void SetMinProfilingBytesUsedToReport(size_t /*size*/)
  112. { }
  113. Y_WEAK void SetEnableEagerMemoryRelease(bool /*value*/)
  114. { }
  115. Y_WEAK void SetEnableMadvisePopulate(bool /*value*/)
  116. { }
  117. ////////////////////////////////////////////////////////////////////////////////
  118. Y_WEAK TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters()
  119. {
  120. return {};
  121. }
  122. Y_WEAK TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters()
  123. {
  124. return {};
  125. }
  126. Y_WEAK TEnumIndexedVector<ELargeCounter, ssize_t> GetLargeAllocationCounters()
  127. {
  128. return {};
  129. }
  130. Y_WEAK std::array<TEnumIndexedVector<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
  131. {
  132. return {};
  133. }
  134. Y_WEAK std::array<TEnumIndexedVector<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
  135. {
  136. return {};
  137. }
  138. Y_WEAK TEnumIndexedVector<EHugeCounter, ssize_t> GetHugeAllocationCounters()
  139. {
  140. return {};
  141. }
  142. Y_WEAK TEnumIndexedVector<ESystemCounter, ssize_t> GetSystemAllocationCounters()
  143. {
  144. return {};
  145. }
  146. Y_WEAK TEnumIndexedVector<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters()
  147. {
  148. return {};
  149. }
  150. Y_WEAK TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
  151. {
  152. return {};
  153. }
  154. ////////////////////////////////////////////////////////////////////////////////
  155. Y_WEAK std::vector<TProfiledAllocation> GetProfiledAllocationStatistics()
  156. {
  157. return {};
  158. }
  159. ////////////////////////////////////////////////////////////////////////////////
  160. } // namespace NYT::NYTAlloc