| 980 | } |
| 981 | |
| 982 | async fn setup_swapfile(&self, swap_size: u64) -> Result<()> { |
| 983 | let swapfile = self.args.mount_point.join("swapfile"); |
| 984 | if swapfile.exists() { |
| 985 | fs::remove_file(&swapfile).context("Failed to remove swapfile")?; |
| 986 | info!("Removed existing swapfile"); |
| 987 | } |
| 988 | if swap_size == 0 { |
| 989 | return Ok(()); |
| 990 | } |
| 991 | let swapfile = swapfile.display().to_string(); |
| 992 | info!("Creating swapfile at {swapfile} (size {swap_size} bytes)"); |
| 993 | let size_str = swap_size.to_string(); |
| 994 | cmd! { |
| 995 | fallocate -l $size_str $swapfile; |
| 996 | chmod 600 $swapfile; |
| 997 | mkswap $swapfile; |
| 998 | swapon $swapfile; |
| 999 | swapon --show; |
| 1000 | } |
| 1001 | .context("Failed to enable swap on swapfile")?; |
| 1002 | Ok(()) |
| 1003 | } |
| 1004 | |
| 1005 | async fn setup_swap_zvol(&self, swap_size: u64) -> Result<()> { |
| 1006 | let swapvol_path = "dstack/swap"; |