Skip to content

Commit ac1f4f7

Browse files
feat: Add session property for debugMemoryPoolWarnThresholdBytes (#25750)
Summary: I added threshold for logging memory pool allocations": facebookincubator/velox#14437 In this adding I'm adding corresponding session property to configure the threshold. Differential Revision: D80066283
1 parent bcfdd43 commit ac1f4f7

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

presto-docs/src/main/sphinx/presto_cpp/properties-session.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ If set to ``true``, disables the optimization in expression evaluation to delay
9797

9898
This should only be used for debugging purposes.
9999

100+
``native_debug_memory_pool_name_regex``
101+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102+
103+
* **Type:** ``varchar``
104+
* **Default value:** ``""``
105+
106+
Native Execution only. Regular expression pattern to match memory pool names for allocation callsite tracking.
107+
Matched pools will also perform leak checks at destruction. Empty string disables tracking.
108+
109+
This should only be used for debugging purposes.
110+
111+
``native_debug_memory_pool_warn_threshold_bytes``
112+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113+
114+
* **Type:** ``bigint``
115+
* **Default value:** ``0``
116+
117+
Native Execution only. Warning threshold for memory pool allocations. Logs callsites when exceeded.
118+
Requires allocation tracking to be enabled with ``native_debug_memory_pool_name_regex``.
119+
Accepts B/KB/MB/GB units. Set to 0B to disable.
120+
121+
This should only be used for debugging purposes.
122+
100123
``native_execution_type_rewrite_enabled``
101124
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102125

presto-main-base/src/main/java/com/facebook/presto/sessionpropertyproviders/NativeWorkerSessionPropertyProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class NativeWorkerSessionPropertyProvider
5353
public static final String NATIVE_DEBUG_DISABLE_EXPRESSION_WITH_MEMOIZATION = "native_debug_disable_expression_with_memoization";
5454
public static final String NATIVE_DEBUG_DISABLE_EXPRESSION_WITH_LAZY_INPUTS = "native_debug_disable_expression_with_lazy_inputs";
5555
public static final String NATIVE_DEBUG_MEMORY_POOL_NAME_REGEX = "native_debug_memory_pool_name_regex";
56+
public static final String NATIVE_DEBUG_MEMORY_POOL_WARN_THRESHOLD_BYTES = "native_debug_memory_pool_warn_threshold_bytes";
5657
public static final String NATIVE_SELECTIVE_NIMBLE_READER_ENABLED = "native_selective_nimble_reader_enabled";
5758
public static final String NATIVE_MAX_PARTIAL_AGGREGATION_MEMORY = "native_max_partial_aggregation_memory";
5859
public static final String NATIVE_MAX_EXTENDED_PARTIAL_AGGREGATION_MEMORY = "native_max_extended_partial_aggregation_memory";
@@ -213,6 +214,15 @@ public NativeWorkerSessionPropertyProvider(FeaturesConfig featuresConfig)
213214
" string means no match for all.",
214215
"",
215216
true),
217+
stringProperty(
218+
NATIVE_DEBUG_MEMORY_POOL_WARN_THRESHOLD_BYTES,
219+
"Warning threshold in bytes for debug memory pools. When set to a " +
220+
"non-zero value, a warning will be logged once per memory pool when " +
221+
"allocations cause the pool to exceed this threshold. This is useful for " +
222+
"identifying memory usage patterns during debugging. A value of " +
223+
"0 means no warning threshold is enforced.",
224+
"0B",
225+
true),
216226
booleanProperty(
217227
NATIVE_SELECTIVE_NIMBLE_READER_ENABLED,
218228
"Temporary flag to control whether selective Nimble reader should be " +

presto-native-execution/presto_cpp/main/QueryContextManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ std::shared_ptr<core::QueryCtx> QueryContextManager::createAndCacheQueryCtx(
6363
QueryContextCache& cache,
6464
const QueryId& queryId,
6565
velox::core::QueryConfig&& queryConfig,
66-
std::unordered_map<std::string, std::shared_ptr<config::ConfigBase>>&& connectorConfigs,
66+
std::unordered_map<std::string, std::shared_ptr<config::ConfigBase>>&&
67+
connectorConfigs,
6768
std::shared_ptr<memory::MemoryPool>&& pool) {
6869
auto queryCtx = core::QueryCtx::create(
6970
driverExecutor_,
@@ -96,10 +97,12 @@ std::shared_ptr<core::QueryCtx> QueryContextManager::findOrCreateQueryCtx(
9697
// is still indexed by the query id.
9798
static std::atomic_uint64_t poolId{0};
9899
std::optional<memory::MemoryPool::DebugOptions> poolDbgOpts;
99-
const auto debugMemoryPoolNameRegex = queryConfig.debugMemoryPoolNameRegex();
100+
auto debugMemoryPoolNameRegex = queryConfig.debugMemoryPoolNameRegex();
100101
if (!debugMemoryPoolNameRegex.empty()) {
101102
poolDbgOpts = memory::MemoryPool::DebugOptions{
102-
.debugPoolNameRegex = debugMemoryPoolNameRegex};
103+
.debugPoolNameRegex = std::move(debugMemoryPoolNameRegex),
104+
.debugPoolWarnThresholdBytes =
105+
queryConfig.debugMemoryPoolWarnThresholdBytes()};
103106
}
104107
auto pool = memory::MemoryManager::getInstance()->addRootPool(
105108
fmt::format("{}_{}", queryId, poolId++),

presto-native-execution/presto_cpp/main/SessionProperties.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ SessionProperties::SessionProperties() {
280280
QueryConfig::kDebugMemoryPoolNameRegex,
281281
c.debugMemoryPoolNameRegex());
282282

283+
addSessionProperty(
284+
kDebugMemoryPoolWarnThresholdBytes,
285+
"Warning threshold in bytes for debug memory pools. When set to a "
286+
"non-zero value, a warning will be logged once per memory pool when "
287+
"allocations cause the pool to exceed this threshold. This is useful for "
288+
"identifying memory usage patterns during debugging. Requires allocation "
289+
"tracking to be enabled with `native_debug_memory_pool_name_regex` "
290+
"for the pool. A value of 0 means no warning threshold is enforced.",
291+
BIGINT(),
292+
false,
293+
QueryConfig::kDebugMemoryPoolWarnThresholdBytes,
294+
std::to_string(c.debugMemoryPoolWarnThresholdBytes()));
295+
283296
addSessionProperty(
284297
kSelectiveNimbleReaderEnabled,
285298
"Temporary flag to control whether selective Nimble reader should be "

presto-native-execution/presto_cpp/main/SessionProperties.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ class SessionProperties {
184184
static constexpr const char* kDebugMemoryPoolNameRegex =
185185
"native_debug_memory_pool_name_regex";
186186

187+
/// Warning threshold in bytes for memory pool allocations. Logs callsites
188+
/// when exceeded. Requires allocation tracking to be enabled with
189+
/// `native_debug_memory_pool_name_regex` property for the pool.
190+
static constexpr const char* kDebugMemoryPoolWarnThresholdBytes =
191+
"native_debug_memory_pool_warn_threshold_bytes";
192+
187193
/// Temporary flag to control whether selective Nimble reader should be used
188194
/// in this query or not. Will be removed after the selective Nimble reader
189195
/// is fully rolled out.

presto-native-execution/presto_cpp/main/tests/SessionPropertiesTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ TEST_F(SessionPropertiesTest, validateMapping) {
6969
core::QueryConfig::kDebugDisableExpressionWithLazyInputs},
7070
{SessionProperties::kDebugMemoryPoolNameRegex,
7171
core::QueryConfig::kDebugMemoryPoolNameRegex},
72+
{SessionProperties::kDebugMemoryPoolWarnThresholdBytes,
73+
core::QueryConfig::kDebugMemoryPoolWarnThresholdBytes},
7274
{SessionProperties::kSelectiveNimbleReaderEnabled,
7375
core::QueryConfig::kSelectiveNimbleReaderEnabled},
7476
{SessionProperties::kQueryTraceEnabled,

0 commit comments

Comments
 (0)