From 49938362ad0be22f2d22c3ddcdd0eb47c062e091 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 23 May 2021 10:33:53 +0100 Subject: [PATCH] unpack_ram: More graceful handling of low unpack ram Some people try setting RUSTUP_UNPACK_RAM below the minimum RAM needed for a threaded operation. Since, in principle, we need at least IO_CHUNK_SIZE and thus in theory 2x IO_CHUNK_SIZE, this change softens the failure mode from a panic to a warning and then tries anyway. This is *likely* to succeed and as such we'll let it happen. The warning should make it clear if there's a problem, and should not appear for no-sysinfo platforms since they default to minimum_ram anyway. Signed-off-by: Daniel Silverstone --- src/dist/component/package.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs index 9d141f4d94a..a54ec075b91 100644 --- a/src/dist/component/package.rs +++ b/src/dist/component/package.rs @@ -182,9 +182,23 @@ fn unpack_ram( .ok() .and_then(|budget_str| budget_str.parse::().ok()) { - // Note: In future we may want to add a warning or even an override if a user - // supplied budget is larger than effective_max_ram. - Some(budget) => budget, + Some(budget) => { + if budget < minimum_ram { + warn!( + "Specified unpack RAM limit ({}) less than minimum of {}. Unpacking may fail.", + budget, minimum_ram + ); + } + if budget > default_max_unpack_ram { + warn!( + "Specified unpack RAM limit ({}) greater than detected available RAM of {}. Clamping to detected limit.", + budget, default_max_unpack_ram + ); + default_max_unpack_ram + } else { + budget + } + } None => { if let Some(h) = notify_handler { h(Notification::SetDefaultBufferSize(default_max_unpack_ram)) @@ -193,10 +207,11 @@ fn unpack_ram( } }; - if io_chunk_size > unpack_ram { - panic!("RUSTUP_UNPACK_RAM must be larger than {}", io_chunk_size); + if minimum_ram > unpack_ram { + minimum_ram + } else { + unpack_ram } - unpack_ram } /// Handle the async result of io operations