17
17
18
18
use crate :: memory_pool:: { MemoryConsumer , MemoryPool , MemoryReservation } ;
19
19
use datafusion_common:: { DataFusionError , Result } ;
20
+ use log:: debug;
20
21
use parking_lot:: Mutex ;
21
22
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
22
23
@@ -45,7 +46,11 @@ impl MemoryPool for UnboundedMemoryPool {
45
46
}
46
47
}
47
48
48
- /// A [`MemoryPool`] that implements a greedy first-come first-serve limit
49
+ /// A [`MemoryPool`] that implements a greedy first-come first-serve limit.
50
+ ///
51
+ /// This pool works well for queries that do not need to spill or have
52
+ /// a single spillable operator. See [`GreedyMemoryPool`] if there are
53
+ /// multiple spillable operators that all will spill.
49
54
#[ derive( Debug ) ]
50
55
pub struct GreedyMemoryPool {
51
56
pool_size : usize ,
@@ -55,6 +60,7 @@ pub struct GreedyMemoryPool {
55
60
impl GreedyMemoryPool {
56
61
/// Allocate up to `limit` bytes
57
62
pub fn new ( pool_size : usize ) -> Self {
63
+ debug ! ( "Created new GreedyMemoryPool(pool_size={pool_size})" ) ;
58
64
Self {
59
65
pool_size,
60
66
used : AtomicUsize :: new ( 0 ) ,
@@ -92,6 +98,13 @@ impl MemoryPool for GreedyMemoryPool {
92
98
/// an even fraction of the available memory sans any unspillable reservations
93
99
/// (i.e. `(pool_size - unspillable_memory) / num_spillable_reservations`)
94
100
///
101
+ /// This pool works best when you know beforehand the query has
102
+ /// multiple spillable operators that will likely all need to
103
+ /// spill. Sometimes it will cause spills even when there was
104
+ /// sufficient memory (reserved for other operators) to avoid doing
105
+ /// so.
106
+ ///
107
+ /// ```text
95
108
/// ┌───────────────────────z──────────────────────z───────────────┐
96
109
/// │ z z │
97
110
/// │ z z │
@@ -100,6 +113,7 @@ impl MemoryPool for GreedyMemoryPool {
100
113
/// │ z z │
101
114
/// │ z z │
102
115
/// └───────────────────────z──────────────────────z───────────────┘
116
+ /// ```
103
117
///
104
118
/// Unspillable memory is allocated in a first-come, first-serve fashion
105
119
#[ derive( Debug ) ]
0 commit comments