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 @@ -106,6 +106,9 @@ pub trait MemoryPool: Send + Sync + std::fmt::Debug {
106106
107107 /// Return the total amount of memory reserved
108108 fn reserved ( & self ) -> usize ;
109+
110+ /// Return the configured pool size (if any)
111+ fn pool_size ( & self ) -> Option < usize > ;
109112}
110113
111114/// A memory consumer is a named allocation traced by a particular
@@ -321,7 +324,9 @@ mod tests {
321324
322325 #[ test]
323326 fn test_memory_pool_underflow ( ) {
324- let pool = Arc :: new ( GreedyMemoryPool :: new ( 50 ) ) as _ ;
327+ let pool: Arc < dyn MemoryPool > = Arc :: new ( GreedyMemoryPool :: new ( 50 ) ) as _ ;
328+ assert_eq ! ( pool. pool_size( ) , Some ( 50 ) ) ;
329+
325330 let mut a1 = MemoryConsumer :: new ( "a1" ) . register ( & pool) ;
326331 assert_eq ! ( pool. reserved( ) , 0 ) ;
327332
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