yjshen commented on a change in pull request #1526: URL: https://github.com/apache/arrow-datafusion/pull/1526#discussion_r780634037
########## File path: datafusion/src/execution/memory_manager.rs ########## @@ -0,0 +1,320 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Manages all available memory during query execution + +use crate::error::Result; +use async_trait::async_trait; +use hashbrown::HashMap; +use log::info; +use std::fmt; +use std::fmt::{Debug, Display, Formatter}; +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::{Arc, Mutex}; +use std::time::Duration; +use tokio::task; +use tokio::task::JoinHandle; + +static mut CONSUMER_ID: AtomicUsize = AtomicUsize::new(0); + +fn next_id() -> usize { + unsafe { CONSUMER_ID.fetch_add(1, Ordering::SeqCst) } +} + +/// Type of the memory consumer +pub enum ConsumerType { + /// consumers that can grow or shrink its memory usage during execution Review comment: I use controlling consumers to describe consumers like external-sorter, hash-aggregator/joiner, or such pipeline breaker operations' consumers that would use a huge amount of memory, and we could control their memory usage pattern by forcing them to spill sometime when no more memory is available. Tracking consumers now describe a category of entities that may use some memory during execution, but we do not control them, just check their usage updates periodically. They are free to grow or shrink memory usage, the only demand for the implementors is to be accurate as possible for the `mem_used()` report. Tracking consumers would occupy tiny memory space, such as a constant internal buffer for each batch calculation, or much larger memory if they are coming from the previous `controlling consumers`. For example, the last part of in-memory batches for the `external sort` or the already built, partial memory-residential hashtables for hash join probing are tracking consumers we would like to only remember its memory usage, but not trigger its spill to reduce system complexity. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org