@@ -167,13 +167,19 @@ struct MemoryBudget {
167
167
impl MemoryBudget {
168
168
fn new (
169
169
max_file_size : usize ,
170
- effective_max_ram : usize ,
170
+ effective_max_ram : Option < usize > ,
171
171
notify_handler : Option < & dyn Fn ( Notification < ' _ > ) > ,
172
172
) -> Self {
173
173
const DEFAULT_UNPACK_RAM_MAX : usize = 500 * 1024 * 1024 ;
174
174
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS : usize = 100 * 1024 * 1024 ;
175
- let ram_for_unpacking = effective_max_ram - RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS ;
176
- let default_max_unpack_ram = std:: cmp:: min ( DEFAULT_UNPACK_RAM_MAX , ram_for_unpacking) ;
175
+ let default_max_unpack_ram = if let Some ( effective_max_ram) = effective_max_ram {
176
+ let ram_for_unpacking = effective_max_ram - RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS ;
177
+ std:: cmp:: min ( DEFAULT_UNPACK_RAM_MAX , ram_for_unpacking)
178
+ } else {
179
+ // Rustup does not know how much RAM the machine has: use the
180
+ // minimum known to work reliably.
181
+ DEFAULT_UNPACK_RAM_MAX
182
+ } ;
177
183
let unpack_ram = match env:: var ( "RUSTUP_UNPACK_RAM" )
178
184
. ok ( )
179
185
. and_then ( |budget_str| budget_str. parse :: < usize > ( ) . ok ( ) )
@@ -291,12 +297,16 @@ fn unpack_without_first_dir<'a, R: Read>(
291
297
. entries ( )
292
298
. chain_err ( || ErrorKind :: ExtractingPackage ) ?;
293
299
const MAX_FILE_SIZE : u64 = 200_000_000 ;
294
- let effective_max_ram = effective_limits:: memory_limit ( ) ?;
295
- let mut budget = MemoryBudget :: new (
296
- MAX_FILE_SIZE as usize ,
297
- effective_max_ram as usize ,
298
- notify_handler,
299
- ) ;
300
+ let effective_max_ram = match effective_limits:: memory_limit ( ) {
301
+ Ok ( ram) => Some ( ram as usize ) ,
302
+ Err ( e) => {
303
+ if let Some ( h) = notify_handler {
304
+ h ( Notification :: Error ( e. to_string ( ) ) )
305
+ }
306
+ None
307
+ }
308
+ } ;
309
+ let mut budget = MemoryBudget :: new ( MAX_FILE_SIZE as usize , effective_max_ram, notify_handler) ;
300
310
301
311
let mut directories: HashMap < PathBuf , DirStatus > = HashMap :: new ( ) ;
302
312
// Path is presumed to exist. Call it a precondition.
0 commit comments