From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id CCCEE1FF389 for ; Tue, 7 May 2024 17:53:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3E05E12379; Tue, 7 May 2024 17:53:54 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Tue, 7 May 2024 17:52:44 +0200 Message-Id: <20240507155244.793819-63-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240507155244.793819-1-c.ebner@proxmox.com> References: <20240507155244.793819-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH v5 proxmox-backup 62/62] client: pxar: set cache limit based on nofile rlimit X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" The lookahead cache size requires the resource limit for open file handles to be high in order to allow for efficient reuse of unchanged file payloads. Increase the nofile soft limit to the hard limit and dynamically adapt the cache size to the new soft limit minus the half of the previous soft limit. The `PxarCreateOptions` and the `Archiver` are therefore extedned by an additional field to store the maximum cache size, with fallback to a default size of 512 entries. Signed-off-by: Christian Ebner --- changes since version 4: - not present in previous version pbs-client/src/pxar/create.rs | 7 ++++++- proxmox-backup-client/src/main.rs | 21 ++++++++++++++++--- .../src/proxmox_restore_daemon/api.rs | 1 + pxar-bin/src/main.rs | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 9349dd8bb..d326d5ac0 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -57,6 +57,8 @@ pub struct PxarCreateOptions { pub skip_e2big_xattr: bool, /// Reference state for partial backups pub previous_ref: Option, + /// Maximum number of lookahead cache entries + pub max_cache_size: Option, } pub type MetadataArchiveReader = Arc; @@ -172,6 +174,7 @@ struct Archiver { suggested_boundaries: Option>, previous_payload_index: Option, cached_entries: Vec, + max_cache_size: usize, cached_hardlinks: HashSet, cached_range: Range, cached_last_chunk: Option, @@ -292,6 +295,7 @@ where previous_payload_index, suggested_boundaries, cached_entries: Vec::new(), + max_cache_size: options.max_cache_size.unwrap_or(MAX_CACHE_SIZE), cached_range: Range::default(), cached_last_chunk: None, cached_hardlinks: HashSet::new(), @@ -743,7 +747,7 @@ impl Archiver { } // Avoid having to many open file handles in cached entries - if self.cached_entries.len() > MAX_CACHE_SIZE { + if self.cached_entries.len() > self.max_cache_size { log::debug!("Max cache size reached, reuse cached entries"); self.flush_cached_reusing_if_below_threshold(encoder, true) .await?; @@ -2018,6 +2022,7 @@ mod tests { previous_payload_index, suggested_boundaries: Some(suggested_boundaries), cached_entries: Vec::new(), + max_cache_size: 512, cached_range: Range::default(), cached_last_chunk: None, cached_hardlinks: HashSet::new(), diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 1423e6f0f..359b2afcf 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -41,7 +41,7 @@ use pbs_client::tools::{ crypto_parameters, format_key_source, get_encryption_key_password, KEYFD_SCHEMA, KEYFILE_SCHEMA, MASTER_PUBKEY_FD_SCHEMA, MASTER_PUBKEY_FILE_SCHEMA, }, - CHUNK_SIZE_SCHEMA, REPO_URL_SCHEMA, + raise_nofile_limit, CHUNK_SIZE_SCHEMA, REPO_URL_SCHEMA, }; use pbs_client::{ delete_ticket_info, parse_backup_detection_mode_specification, parse_backup_specification, @@ -1074,7 +1074,8 @@ async fn create_backup( .start_directory(std::ffi::CString::new(target.as_str())?.as_c_str())?; let mut previous_ref = None; - if detection_mode.is_metadata() { + let max_cache_size = if detection_mode.is_metadata() { + let old_rlimit = raise_nofile_limit()?; if let Some(ref manifest) = previous_manifest { // BackupWriter::start created a new snapshot, get the one before if let Some(backup_time) = client.previous_backup_time().await? { @@ -1099,7 +1100,20 @@ async fn create_backup( .await? } } - } + + if old_rlimit.rlim_max <= 4096 { + log::info!( + "resource limit for open file handles low: {}", + old_rlimit.rlim_max, + ); + } + + Some(usize::try_from( + old_rlimit.rlim_max - old_rlimit.rlim_cur / 2, + )?) + } else { + None + }; let pxar_options = pbs_client::pxar::PxarCreateOptions { device_set: devices.clone(), @@ -1108,6 +1122,7 @@ async fn create_backup( skip_lost_and_found, skip_e2big_xattr, previous_ref, + max_cache_size, }; let upload_options = UploadOptions { diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs index 956c3246a..49aa96b58 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -356,6 +356,7 @@ fn extract( skip_lost_and_found: false, skip_e2big_xattr: false, previous_ref: None, + max_cache_size: None, }; let pxar_writer = TokioWriter::new(writer); diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 2a5403467..c08aee4f6 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -365,6 +365,7 @@ async fn create_archive( skip_lost_and_found: false, skip_e2big_xattr: false, previous_ref: None, + max_cache_size: None, }; let source = PathBuf::from(source); -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel