Skip to content

Commit 077ea86

Browse files
committed
keep the HardwareManager handle around instead of caching measurements
the number of physical pages won't change at runtime really, nor will the size of pages, but it seems a bit nicer this way..
1 parent 98dfbcd commit 077ea86

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

sled-hardware/src/lib.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ pub enum SledMode {
7777
}
7878

7979
/// Accounting for high watermark memory usage for various system purposes
80-
#[derive(Copy, Clone, Debug)]
80+
#[derive(Clone)]
8181
pub struct MemoryReservations {
82-
/// Installed physical memory in this sled. Probably should hold a
83-
/// [`HardwareManager`] and call `usable_physical_ram_bytes()` instead of
84-
/// this.
85-
hardware_physical_ram_bytes: u64,
82+
hardware_manager: HardwareManager,
8683
/// The amount of memory expected to be used if "control plane" services all
8784
/// running on this sled. "control plane" here refers to services that have
8885
/// roughly fixed memory use given differing sled hardware configurations.
@@ -98,10 +95,6 @@ pub struct MemoryReservations {
9895
// XXX: This is really something we should be told by Neuxs, perhaps after
9996
// starting with this conservative estimate to get the sled started.
10097
control_plane_earmark_bytes: u64,
101-
/// The amount of memory used for `page_t` structures, assuming a distinct
102-
/// `page_t` for each 4k page in the system. If we use larger pages, like
103-
/// 2MiB pages, this will be potentially a gross overestimate.
104-
max_page_t_space: u64,
10598
// XXX: Crucible involves some amount of memory in support of the volumes it
10699
// manages. We should collect zpool size and estimate the memory that would
107100
// be used if all available storage was dedicated to Crucible volumes. For
@@ -113,23 +106,12 @@ impl MemoryReservations {
113106
hardware_manager: HardwareManager,
114107
control_plane_earmark_mib: Option<u32>,
115108
) -> MemoryReservations {
116-
let hardware_physical_ram_bytes =
117-
hardware_manager.usable_physical_ram_bytes();
118-
// Don't like hardcoding a struct size from the host OS here like
119-
// this, maybe we shuffle some bits around before merging.. On the
120-
// other hand, the last time page_t changed was illumos-gate commit
121-
// a5652762e5 from 2006.
122-
const PAGE_T_SIZE: u64 = 120;
123-
let max_page_t_space =
124-
hardware_manager.usable_physical_pages() * PAGE_T_SIZE;
125-
126109
const MIB: u64 = 1024 * 1024;
127110
let control_plane_earmark_bytes =
128111
u64::from(control_plane_earmark_mib.unwrap_or(0)) * MIB;
129112

130113
Self {
131-
hardware_physical_ram_bytes,
132-
max_page_t_space,
114+
hardware_manager,
133115
control_plane_earmark_bytes,
134116
}
135117
}
@@ -141,8 +123,18 @@ impl MemoryReservations {
141123
/// a fixed amount of memory specified by `ReservoirMode::Size` or
142124
/// a percentage of this amount specified by `ReservoirMode::Percentage`.
143125
pub fn vmm_eligible(&self) -> u64 {
144-
self.hardware_physical_ram_bytes
145-
- self.max_page_t_space
126+
let hardware_physical_ram_bytes =
127+
self.hardware_manager.usable_physical_ram_bytes();
128+
// Don't like hardcoding a struct size from the host OS here like
129+
// this, maybe we shuffle some bits around before merging.. On the
130+
// other hand, the last time page_t changed was illumos-gate commit
131+
// a5652762e5 from 2006.
132+
const PAGE_T_SIZE: u64 = 120;
133+
let max_page_t_space =
134+
self.hardware_manager.usable_physical_pages() * PAGE_T_SIZE;
135+
136+
hardware_physical_ram_bytes
137+
- max_page_t_space
146138
- self.control_plane_earmark_bytes
147139
}
148140
}

0 commit comments

Comments
 (0)