From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8997863500 for ; Tue, 25 Jan 2022 11:15:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 63ADE2BFC8 for ; Tue, 25 Jan 2022 11:14:39 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 607BB2BFBF for ; Tue, 25 Jan 2022 11:14:38 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2E104460A4; Tue, 25 Jan 2022 11:14:38 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Tue, 25 Jan 2022 11:14:35 +0100 Message-Id: <20220125101435.2169848-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.466 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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] Set MMAP_THRESHOLD to a fixed value (128K) 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: , X-List-Received-Date: Tue, 25 Jan 2022 10:15:09 -0000 This reduces RSS size by factor 10-20 when running backups. Signed-off-by: Dietmar Maurer --- pbs-tools/src/lib.rs | 17 +++++++++++++++++ proxmox-backup-client/src/main.rs | 2 ++ src/bin/proxmox-backup-api.rs | 2 ++ src/bin/proxmox-backup-proxy.rs | 3 +++ 4 files changed, 24 insertions(+) diff --git a/pbs-tools/src/lib.rs b/pbs-tools/src/lib.rs index 053b3c0c..cd8bb546 100644 --- a/pbs-tools/src/lib.rs +++ b/pbs-tools/src/lib.rs @@ -8,3 +8,20 @@ pub mod sha; pub mod ticket; pub mod async_lru_cache; + + +#[link(name = "c")] +extern "C" { + fn mallopt(para: isize, val: isize); +} + +/// Set MMAP_THRESHOLD to a fixed value (128K) +/// +/// This reduces RSS size by factor 10-20 when running backups (not +/// sure why). +pub fn setup_libc_malloc_opts() { + unsafe { + const M_MMAP_THRESHOLD: isize = -3; // from malloc.h + mallopt(M_MMAP_THRESHOLD, 4096*32); + } +} diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 50682637..a51d5bef 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1465,6 +1465,8 @@ impl ReadAt for BufferedDynamicReadAt { fn main() { + pbs_tools::setup_libc_malloc_opts(); + let backup_cmd_def = CliCommand::new(&API_METHOD_CREATE_BACKUP) .arg_param(&["backupspec"]) .completion_cb("repository", complete_repository) diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index e6fc5f23..ee037a3b 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -19,6 +19,8 @@ use proxmox_backup::auth_helpers::*; use proxmox_backup::config; fn main() { + pbs_tools::setup_libc_malloc_opts(); + proxmox_backup::tools::setup_safe_path_env(); if let Err(err) = proxmox_async::runtime::main(run()) { diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 523966cf..13025271 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -73,6 +73,9 @@ use proxmox_backup::server::do_verification_job; use proxmox_backup::server::do_prune_job; fn main() -> Result<(), Error> { + + pbs_tools::setup_libc_malloc_opts(); + proxmox_backup::tools::setup_safe_path_env(); let backup_uid = pbs_config::backup_user()?.uid; -- 2.30.2