@@ -65,6 +65,21 @@ static Poco::Logger * getLogger()
6565 return logger;
6666}
6767
68+ static String storageMemoryUsageDetail ()
69+ {
70+ return fmt::format (
71+ " non-query: peak={}, amount={}; "
72+ " shared-column-data: peak={}, amount={}." ,
73+ root_of_non_query_mem_trackers ? formatReadableSizeWithBinarySuffix (root_of_non_query_mem_trackers->getPeak ())
74+ : " 0" ,
75+ root_of_non_query_mem_trackers ? formatReadableSizeWithBinarySuffix (root_of_non_query_mem_trackers->get ())
76+ : " 0" ,
77+ shared_column_data_mem_tracker ? formatReadableSizeWithBinarySuffix (shared_column_data_mem_tracker->getPeak ())
78+ : " 0" ,
79+ shared_column_data_mem_tracker ? formatReadableSizeWithBinarySuffix (shared_column_data_mem_tracker->get ())
80+ : " 0" );
81+ }
82+
6883void MemoryTracker::logPeakMemoryUsage () const
6984{
7085 LOG_DEBUG (getLogger (), " Peak memory usage{}: {}." , (description ? " " + std::string (description) : " " ), formatReadableSizeWithBinarySuffix (peak));
@@ -79,7 +94,12 @@ void MemoryTracker::alloc(Int64 size, bool check_memory_limit)
7994 Int64 will_be = size + amount.fetch_add (size, std::memory_order_relaxed);
8095
8196 if (!next.load (std::memory_order_relaxed))
97+ {
8298 CurrentMetrics::add (metric, size);
99+ // Only add shared column data size to root_of_query_mem_trackers.
100+ if (shared_column_data_mem_tracker && root_of_query_mem_trackers.get () == this )
101+ will_be += shared_column_data_mem_tracker->get ();
102+ }
83103
84104 if (check_memory_limit)
85105 {
@@ -101,6 +121,7 @@ void MemoryTracker::alloc(Int64 size, bool check_memory_limit)
101121 (root_of_non_query_mem_trackers ? formatReadableSizeWithBinarySuffix (root_of_non_query_mem_trackers->peak ) : " 0" ),
102122 (root_of_non_query_mem_trackers ? formatReadableSizeWithBinarySuffix (root_of_non_query_mem_trackers->amount ) : " 0" ),
103123 proc_virt_size.load ());
124+ fmt_buf.fmtAppend (" Memory usage of storage: {}" , storageMemoryUsageDetail ());
104125 throw DB::TiFlashException (fmt_buf.toString (), DB::Errors::Coprocessor::MemoryLimitExceeded);
105126 }
106127
@@ -118,7 +139,7 @@ void MemoryTracker::alloc(Int64 size, bool check_memory_limit)
118139 formatReadableSizeWithBinarySuffix (will_be),
119140 size,
120141 formatReadableSizeWithBinarySuffix (current_limit));
121-
142+ fmt_buf. fmtAppend ( " Memory usage of storage: {} " , storageMemoryUsageDetail ());
122143 throw DB::TiFlashException (fmt_buf.toString (), DB::Errors::Coprocessor::MemoryLimitExceeded);
123144 }
124145 Int64 current_bytes_rss_larger_than_limit = bytes_rss_larger_than_limit.load (std::memory_order_relaxed);
@@ -150,7 +171,7 @@ void MemoryTracker::alloc(Int64 size, bool check_memory_limit)
150171 size,
151172 formatReadableSizeWithBinarySuffix (current_limit));
152173 }
153-
174+ fmt_buf. fmtAppend ( " Memory usage of storage: {} " , storageMemoryUsageDetail ());
154175 throw DB::TiFlashException (fmt_buf.toString (), DB::Errors::Coprocessor::MemoryLimitExceeded);
155176 }
156177 }
@@ -224,6 +245,20 @@ thread_local MemoryTracker * current_memory_tracker = nullptr;
224245std::shared_ptr<MemoryTracker> root_of_non_query_mem_trackers = MemoryTracker::createGlobalRoot();
225246std::shared_ptr<MemoryTracker> root_of_query_mem_trackers = MemoryTracker::createGlobalRoot();
226247
248+ std::shared_ptr<MemoryTracker> shared_column_data_mem_tracker;
249+
250+ void initStorageMemoryTracker (Int64 limit, Int64 larger_than_limit)
251+ {
252+ LOG_INFO (
253+ getLogger (),
254+ " Storage task memory limit={}, larger_than_limit={}" ,
255+ formatReadableSizeWithBinarySuffix (limit),
256+ formatReadableSizeWithBinarySuffix (larger_than_limit));
257+ RUNTIME_CHECK (shared_column_data_mem_tracker == nullptr );
258+ shared_column_data_mem_tracker = MemoryTracker::create (limit);
259+ shared_column_data_mem_tracker->setBytesThatRssLargerThanLimit (larger_than_limit);
260+ }
261+
227262namespace CurrentMemoryTracker
228263{
229264static Int64 MEMORY_TRACER_SUBMIT_THRESHOLD = 1024 * 1024 ; // 1 MiB
0 commit comments