[pbs-devel] [PATCH v9 proxmox-backup 51/58] client: pxar: set cache limit based on nofile rlimit

Christian Ebner c.ebner at proxmox.com
Wed Jun 5 12:54:09 CEST 2024


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 extended by
an additional field to store the maximum cache size, with fallback to
a default size of 512 entries.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 8:
- no changes

 pbs-client/src/pxar/create.rs                 |  6 ++++--
 proxmox-backup-client/src/main.rs             | 21 ++++++++++++++++---
 .../src/proxmox_restore_daemon/api.rs         |  1 +
 pxar-bin/src/main.rs                          |  1 +
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index 42e4dc502..fcfb9a09c 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -56,6 +56,8 @@ pub struct PxarCreateOptions {
     pub skip_e2big_xattr: bool,
     /// Reference state for partial backups
     pub previous_ref: Option<PxarPrevRef>,
+    /// Maximum number of lookahead cache entries
+    pub max_cache_size: Option<usize>,
 }
 
 pub type MetadataArchiveReader = Arc<dyn ReadAt + Send + Sync + 'static>;
@@ -275,7 +277,7 @@ where
         forced_boundaries,
         suggested_boundaries,
         previous_payload_index,
-        cache: PxarLookaheadCache::new(None),
+        cache: PxarLookaheadCache::new(options.max_cache_size),
         reuse_stats: ReuseStats::default(),
     };
 
@@ -1924,7 +1926,7 @@ mod tests {
                 forced_boundaries: Some(forced_boundaries),
                 previous_payload_index,
                 suggested_boundaries: Some(suggested_boundaries),
-                cache: PxarLookaheadCache::new(),
+                cache: PxarLookaheadCache::new(None),
                 reuse_stats: ReuseStats::default(),
             };
 
diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
index a17588edf..e01da26fc 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_specification, view_task_result, BackupDetectionMode,
@@ -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? {
@@ -1100,7 +1101,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(),
@@ -1109,6 +1123,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 80af5011e..0a535b7a7 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
@@ -361,6 +361,7 @@ fn extract(
                         skip_lost_and_found: false,
                         skip_e2big_xattr: false,
                         previous_ref: None,
+                        max_cache_size: None,
                     };
 
                     let pxar_writer = pxar::PxarVariant::Unified(TokioWriter::new(writer));
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index fa584b4e8..e62348e25 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -376,6 +376,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





More information about the pbs-devel mailing list