aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-05 23:45:46 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-05 23:57:47 +0200
commit2b7df394057c013fd042b85a4d5fd0104ba4a9be (patch)
tree763cfb2f588f2cde22afbf3582f4cf2c3abf2bb1 /lib
parent1faedb4a6a4e49c8c26c48fbd03f16902276155a (diff)
Set sane defaults for backlog and job count
Instead of defaulting to -j 1 and -Q 10 times the job count if no option is provided, let tar2sqfs and gensquashfs use all available CPUs and about roughly half the available RAM, if this information can be gathered. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfshelper/writer.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/sqfshelper/writer.c b/lib/sqfshelper/writer.c
index e57ad76..7626b1c 100644
--- a/lib/sqfshelper/writer.c
+++ b/lib/sqfshelper/writer.c
@@ -13,14 +13,57 @@
#include <string.h>
+#ifdef HAVE_SYS_SYSINFO_H
+#include <sys/sysinfo.h>
+
+static size_t os_get_num_jobs(void)
+{
+ int nprocs;
+
+ nprocs = get_nprocs_conf();
+ return nprocs < 1 ? 1 : nprocs;
+}
+
+static size_t os_get_max_ram(void)
+{
+ struct sysinfo info;
+
+ if (sysinfo(&info)) {
+ perror("sysinfo");
+ return 0;
+ }
+
+ return info.totalram;
+}
+#else
+static size_t os_get_num_jobs(void)
+{
+ return 1;
+}
+
+static size_t os_get_max_ram(void)
+{
+ (void)cfg;
+ return 0;
+}
+#endif
+
void sqfs_writer_cfg_init(sqfs_writer_cfg_t *cfg)
{
+ size_t max_ram;
+
memset(cfg, 0, sizeof(*cfg));
- cfg->num_jobs = 1;
+ cfg->num_jobs = os_get_num_jobs();
cfg->block_size = SQFS_DEFAULT_BLOCK_SIZE;
cfg->devblksize = SQFS_DEVBLK_SIZE;
cfg->comp_id = compressor_get_default();
+
+ max_ram = os_get_max_ram();
+ cfg->max_backlog = (max_ram / 2) / cfg->block_size;
+
+ if (cfg->max_backlog < 1)
+ cfg->max_backlog = 10 * cfg->num_jobs;
}
int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)