5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-03-11 16:58:32 +03:00

client: pxar: set cache limit based on nofile rlimit

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@proxmox.com>
This commit is contained in:
Christian Ebner 2024-05-07 15:16:03 +02:00 committed by Fabian Grünbichler
parent 7b352cc0cf
commit cf75bc0db5
4 changed files with 24 additions and 5 deletions

View File

@ -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(),
};

View File

@ -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 {

View File

@ -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));

View File

@ -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);