File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
datafusion/execution/src/memory_pool Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ pub trait MemoryPool: Send + Sync + std::fmt::Debug {
108108
109109 /// Return the total amount of memory reserved
110110 fn reserved ( & self ) -> usize ;
111+
112+ /// Return the configured pool size (if any)
113+ fn pool_size ( & self ) -> Option < usize > ;
111114}
112115
113116/// A memory consumer is a named allocation traced by a particular
@@ -323,7 +326,9 @@ mod tests {
323326
324327 #[ test]
325328 fn test_memory_pool_underflow ( ) {
326- let pool = Arc :: new ( GreedyMemoryPool :: new ( 50 ) ) as _ ;
329+ let pool: Arc < dyn MemoryPool > = Arc :: new ( GreedyMemoryPool :: new ( 50 ) ) as _ ;
330+ assert_eq ! ( pool. pool_size( ) , Some ( 50 ) ) ;
331+
327332 let mut a1 = MemoryConsumer :: new ( "a1" ) . register ( & pool) ;
328333 assert_eq ! ( pool. reserved( ) , 0 ) ;
329334
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ impl MemoryPool for UnboundedMemoryPool {
4444 fn reserved ( & self ) -> usize {
4545 self . used . load ( Ordering :: Relaxed )
4646 }
47+
48+ fn pool_size ( & self ) -> Option < usize > {
49+ None
50+ }
4751}
4852
4953/// A [`MemoryPool`] that implements a greedy first-come first-serve limit.
@@ -96,6 +100,10 @@ impl MemoryPool for GreedyMemoryPool {
96100 fn reserved ( & self ) -> usize {
97101 self . used . load ( Ordering :: Relaxed )
98102 }
103+
104+ fn pool_size ( & self ) -> Option < usize > {
105+ Some ( self . pool_size )
106+ }
99107}
100108
101109/// A [`MemoryPool`] that prevents spillable reservations from using more than
@@ -229,6 +237,10 @@ impl MemoryPool for FairSpillPool {
229237 let state = self . state . lock ( ) ;
230238 state. spillable + state. unspillable
231239 }
240+
241+ fn pool_size ( & self ) -> Option < usize > {
242+ Some ( self . pool_size )
243+ }
232244}
233245
234246fn insufficient_capacity_err (
@@ -246,7 +258,8 @@ mod tests {
246258
247259 #[ test]
248260 fn test_fair ( ) {
249- let pool = Arc :: new ( FairSpillPool :: new ( 100 ) ) as _ ;
261+ let pool: Arc < dyn MemoryPool > = Arc :: new ( FairSpillPool :: new ( 100 ) ) as _ ;
262+ assert_eq ! ( pool. pool_size( ) , Some ( 100 ) ) ;
250263
251264 let mut r1 = MemoryConsumer :: new ( "unspillable" ) . register ( & pool) ;
252265 // Can grow beyond capacity of pool
You can’t perform that action at this time.
0 commit comments