Skip to content

Commit d2625c3

Browse files
authored
Minor: Improve memory helper trait documentaiton (#9025)
1 parent d594e62 commit d2625c3

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

datafusion/execution/src/memory_pool/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Manages all available memory during query execution
18+
//! [`MemoryPool`] for memory management during query execution, [`proxy]` for
19+
//! help with allocation accounting.
1920
2021
use datafusion_common::Result;
2122
use std::{cmp::Ordering, sync::Arc};
@@ -56,7 +57,7 @@ pub use pool::*;
5657
/// kills the process, DataFusion `ExecutionPlan`s (operators) that consume
5758
/// large amounts of memory must first request their desired allocation from a
5859
/// [`MemoryPool`] before allocating more. The request is typically managed via
59-
/// a [`MemoryReservation`].
60+
/// a [`MemoryReservation`] and [`MemoryConsumer`].
6061
///
6162
/// If the allocation is successful, the operator should proceed and allocate
6263
/// the desired memory. If the allocation fails, the operator must either first
@@ -107,9 +108,13 @@ pub trait MemoryPool: Send + Sync + std::fmt::Debug {
107108
fn reserved(&self) -> usize;
108109
}
109110

110-
/// A memory consumer that can be tracked by [`MemoryReservation`] in
111-
/// a [`MemoryPool`]. All allocations are registered to a particular
112-
/// `MemoryConsumer`;
111+
/// A memory consumer is a named allocation traced by a particular
112+
/// [`MemoryReservation`] in a [`MemoryPool`]. All allocations are registered to
113+
/// a particular `MemoryConsumer`;
114+
///
115+
/// For help with allocation accounting, see the [proxy] module.
116+
///
117+
/// [proxy]: crate::memory_pool::proxy
113118
#[derive(Debug)]
114119
pub struct MemoryConsumer {
115120
name: String,

datafusion/execution/src/memory_pool/proxy.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Utilities that help with tracking of memory allocations.
18+
//! [`VecAllocExt`] and [`RawTableAllocExt`] to help tracking of memory allocations
1919
2020
use hashbrown::raw::{Bucket, RawTable};
2121

@@ -24,12 +24,18 @@ pub trait VecAllocExt {
2424
/// Item type.
2525
type T;
2626

27-
/// [Push](Vec::push) new element to vector and store additional allocated bytes in `accounting` (additive).
27+
/// [Push](Vec::push) new element to vector and increase
28+
/// `accounting` by any newly allocated bytes.
29+
///
30+
/// Note that allocation counts capacity, not size
2831
fn push_accounted(&mut self, x: Self::T, accounting: &mut usize);
2932

30-
/// Return the amount of memory allocated by this Vec (not
31-
/// recursively counting any heap allocations contained within the
32-
/// structure). Does not include the size of `self`
33+
/// Return the amount of memory allocated by this Vec to store elements
34+
/// (`size_of<T> * capacity`).
35+
///
36+
/// Note this calculation is not recursive, and does not include any heap
37+
/// allocations contained within the Vec's elements. Does not include the
38+
/// size of `self`
3339
fn allocated_size(&self) -> usize;
3440
}
3541

@@ -54,12 +60,15 @@ impl<T> VecAllocExt for Vec<T> {
5460
}
5561
}
5662

57-
/// Extension trait for [`RawTable`] to account for allocations.
63+
/// Extension trait for hash browns [`RawTable`] to account for allocations.
5864
pub trait RawTableAllocExt {
5965
/// Item type.
6066
type T;
6167

62-
/// [Insert](RawTable::insert) new element into table and store additional allocated bytes in `accounting` (additive).
68+
/// [Insert](RawTable::insert) new element into table and increase
69+
/// `accounting` by any newly allocated bytes.
70+
///
71+
/// Returns the bucket where the element was inserted.
6372
fn insert_accounted(
6473
&mut self,
6574
x: Self::T,

0 commit comments

Comments
 (0)