@@ -7,21 +7,21 @@ use std::io::{self, ErrorKind as IOErrorKind, Read};
77use std:: mem;
88use std:: ops:: Deref ;
99use std:: path:: { Path , PathBuf } ;
10- use std:: sync:: OnceLock ;
1110
1211use anyhow:: { Context , Result , anyhow, bail} ;
1312use tar:: EntryType ;
14- use tracing:: { error , trace , warn} ;
13+ use tracing:: warn;
1514
16- use crate :: diskio:: { CompletedIo , Executor , FileBuffer , IO_CHUNK_SIZE , Item , Kind , get_executor} ;
15+ use crate :: diskio:: {
16+ CompletedIo , Executor , FileBuffer , IO_CHUNK_SIZE , Item , Kind , get_executor, unpack_ram,
17+ } ;
1718use crate :: dist:: component:: components:: { ComponentPart , ComponentPartKind , Components } ;
1819use crate :: dist:: component:: transaction:: Transaction ;
1920use crate :: dist:: download:: DownloadCfg ;
2021use crate :: dist:: manifest:: CompressionKind ;
2122use crate :: dist:: temp;
2223use crate :: errors:: RustupError ;
2324use crate :: utils;
24- use crate :: utils:: units:: Size ;
2525
2626/// The current metadata revision used by rust-installer
2727pub ( crate ) const INSTALLER_VERSION : & str = "3" ;
@@ -152,59 +152,6 @@ impl<P: Deref<Target = Path>> DirectoryPackage<P> {
152152 }
153153}
154154
155- // Probably this should live in diskio but ¯\_(ツ)_/¯
156- fn unpack_ram ( io_chunk_size : usize , budget : Option < usize > ) -> usize {
157- const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS : usize = 200 * 1024 * 1024 ;
158- let minimum_ram = io_chunk_size * 2 ;
159-
160- let default_max_unpack_ram = match effective_limits:: memory_limit ( ) {
161- Ok ( effective)
162- if effective as usize > minimum_ram + RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS =>
163- {
164- effective as usize - RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS
165- }
166- Ok ( _) => minimum_ram,
167- Err ( error) => {
168- error ! ( "can't determine memory limit: {error}" ) ;
169- minimum_ram
170- }
171- } ;
172-
173- let unpack_ram = match budget {
174- Some ( budget) => {
175- if budget < minimum_ram {
176- warn ! (
177- "Ignoring RUSTUP_UNPACK_RAM ({}) less than minimum of {}." ,
178- budget, minimum_ram
179- ) ;
180- minimum_ram
181- } else if budget > default_max_unpack_ram {
182- warn ! (
183- "Ignoring RUSTUP_UNPACK_RAM ({}) greater than detected available RAM of {}." ,
184- budget, default_max_unpack_ram
185- ) ;
186- default_max_unpack_ram
187- } else {
188- budget
189- }
190- }
191- None => {
192- if RAM_NOTICE_SHOWN . set ( ( ) ) . is_ok ( ) {
193- trace ! ( size = %Size :: new( default_max_unpack_ram) , "unpacking components in memory" ) ;
194- }
195- default_max_unpack_ram
196- }
197- } ;
198-
199- if minimum_ram > unpack_ram {
200- panic ! ( "RUSTUP_UNPACK_RAM must be larger than {minimum_ram}" ) ;
201- } else {
202- unpack_ram
203- }
204- }
205-
206- static RAM_NOTICE_SHOWN : OnceLock < ( ) > = OnceLock :: new ( ) ;
207-
208155/// Handle the async result of io operations
209156/// Replaces op.result with Ok(())
210157fn filter_result ( op : & mut CompletedIo ) -> io:: Result < ( ) > {
0 commit comments