This is an automated email from the ASF dual-hosted git repository.
liaoxin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 7ad64890477 [fix](memtable) using memtable memory instead of load
memory to calculate adaptive write buffer size (#62104)
7ad64890477 is described below
commit 7ad648904771393b801bcc218db9c12bc212aca2
Author: hui lai <[email protected]>
AuthorDate: Wed Apr 8 14:22:37 2026 +0800
[fix](memtable) using memtable memory instead of load memory to calculate
adaptive write buffer size (#62104)
## Problem
`_adaptive_write_buffer_size()` used
`MemoryProfile::load_current_usage()` to evaluate memory pressure, but
this metric **does not include memtable memory**. As a result, even when
memtable memory is high, the pressure check always reads near zero,
causing the write buffer to always use the maximum 4× factor and never
scale down — defeating the purpose of adaptive sizing.
## Solution
Replace `MemoryProfile::load_current_usage()` with
`memtable_memory_limiter()->mem_tracker()->consumption()`, which
directly reflects actual memtable memory consumption. The scaling logic
remains the same:
| Memtable memory usage | Buffer size factor |
|---|---|
| > 80% of limit | 1× (minimum) |
| > 50% of limit | 2× |
| ≤ 50% of limit | 4× (maximum) |
A null check is added for safety in case the limiter or tracker is not
initialized.
---
be/src/load/memtable/memtable.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/be/src/load/memtable/memtable.cpp
b/be/src/load/memtable/memtable.cpp
index d84d5bbe9a6..5b23c358029 100644
--- a/be/src/load/memtable/memtable.cpp
+++ b/be/src/load/memtable/memtable.cpp
@@ -718,15 +718,19 @@ int64_t MemTable::_adaptive_write_buffer_size() const {
if (!config::enable_adaptive_write_buffer_size) [[unlikely]] {
return config::write_buffer_size;
}
- const int64_t current_load_mem_value = MemoryProfile::load_current_usage();
+ auto* memtable_limiter = ExecEnv::GetInstance()->memtable_memory_limiter();
+ int64_t memtable_mem =
+ (memtable_limiter != nullptr && memtable_limiter->mem_tracker() !=
nullptr)
+ ? memtable_limiter->mem_tracker()->consumption()
+ : 0;
int64_t factor = 4;
// Memory usage intervals:
// (80 %, 100 %] → 1× buffer
// (50 %, 80 %] → 2× buffer
// [0 %, 50 %] → 4× buffer
- if (current_load_mem_value > (_load_mem_limit * 4) / 5) { // > 80 %
+ if (memtable_mem > (_load_mem_limit * 4) / 5) { // > 80 %
factor = 1;
- } else if (current_load_mem_value > _load_mem_limit / 2) { // > 50 %
+ } else if (memtable_mem > _load_mem_limit / 2) { // > 50 %
factor = 2;
}
return config::write_buffer_size * factor;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]