Skip to content

Commit c8be2a3

Browse files
authored
Merge pull request #2780 from kinnison/graceful-lowmem
unpack_ram: More graceful handling of low unpack ram
2 parents 7c9e51a + b1e515c commit c8be2a3

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/dist/component/package.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,23 @@ fn unpack_ram(
182182
.ok()
183183
.and_then(|budget_str| budget_str.parse::<usize>().ok())
184184
{
185-
// Note: In future we may want to add a warning or even an override if a user
186-
// supplied budget is larger than effective_max_ram.
187-
Some(budget) => budget,
185+
Some(budget) => {
186+
if budget < minimum_ram {
187+
warn!(
188+
"Ignoring RUSTUP_UNPACK_RAM ({}) less than minimum of {}.",
189+
budget, minimum_ram
190+
);
191+
minimum_ram
192+
} else if budget > default_max_unpack_ram {
193+
warn!(
194+
"Ignoring RUSTUP_UNPACK_RAM ({}) greater than detected available RAM of {}.",
195+
budget, default_max_unpack_ram
196+
);
197+
default_max_unpack_ram
198+
} else {
199+
budget
200+
}
201+
}
188202
None => {
189203
if let Some(h) = notify_handler {
190204
h(Notification::SetDefaultBufferSize(default_max_unpack_ram))
@@ -193,10 +207,11 @@ fn unpack_ram(
193207
}
194208
};
195209

196-
if io_chunk_size > unpack_ram {
197-
panic!("RUSTUP_UNPACK_RAM must be larger than {}", io_chunk_size);
210+
if minimum_ram > unpack_ram {
211+
panic!("RUSTUP_UNPACK_RAM must be larger than {}", minimum_ram);
212+
} else {
213+
unpack_ram
198214
}
199-
unpack_ram
200215
}
201216

202217
/// Handle the async result of io operations

0 commit comments

Comments
 (0)