diff --git a/lrztar b/lrztar index fa776d6..a9b66ed 100755 --- a/lrztar +++ b/lrztar @@ -22,14 +22,14 @@ function lrztar_local() { local p="${@:1:$(($#-1))}" s="${!#}" tname= fname= \ - v_w=0 v_O=0 v_S=0 v_D=0 v_P=0 v_q=0 v_L=0 \ + v_w=0 v_O=0 v_S=0 v_D=0 v_p=0 v_q=0 v_L=0 \ v_n=0 v_l=0 v_b=0 v_g=0 v_z=0 v_M=0 v_U=0 \ v_T=0 v_N=0 v_v=0 v_f=0 v_d=0 v_h=0 x= i= OPTERR=0 trap '[[ -z $tname ]] || rm -rf "$tname" &> /dev/null' 1 2 3 15 which tar &> /dev/null || { printf "lrztar: no tar in your path\n"; return 1; } which lrzip &> /dev/null || { printf "lrztar: no lrzip in your path\n"; return 1; } - while getopts w:O:S:DPqL:nlbgzMUT:N:vfodtVh x; do + while getopts w:O:S:DqL:nlbgzMUT:N:p:vfodtVh x; do [[ $x == [otV] ]] || ((v_$x=1)) &> /dev/null \ || { printf "lrztar: invalid option for lrztar %s\n" "$x"; return 1; } done diff --git a/main.c b/main.c index 50ee6cc..346252e 100644 --- a/main.c +++ b/main.c @@ -37,9 +37,8 @@ static void usage(void) print_output(" -S suffix specify compressed suffix (default '.lrz')\n"); print_output(" -f force overwrite of any existing files\n"); print_output(" -D delete existing files\n"); - print_output(" -P don't set permissions on output file - may leave it world-readable\n"); print_output(" -q don't show compression progress\n"); - print_output(" -L level set lzma/bzip2/gzip compression level (1-9, default 9)\n"); + print_output(" -L level set lzma/bzip2/gzip compression level (1-9, default 7)\n"); print_output(" -n no backend compression - prepare for other compressor\n"); print_output(" -l lzo compression (ultra fast)\n"); print_output(" -b bzip2 compression\n"); @@ -49,6 +48,7 @@ static void usage(void) print_output(" -U Use unlimited window size beyond ramsize (potentially much slower)\n"); print_output(" -T value Compression threshold with LZO test. (0 (nil) - 10 (high), default 1)\n"); print_output(" -N value Set nice value to value (default 19)\n"); + print_output(" -p value Set processor count to override number of threads\n"); print_output(" -v[v] Increase verbosity\n"); print_output(" -V show version\n"); print_output(" -t test compressed file integrity\n"); @@ -289,8 +289,7 @@ static void decompress_file(void) if (unlikely(fd_out == -1)) fatal("Failed to create %s: %s\n", control.outfile, strerror(errno)); - if (!NO_SET_PERMS) - preserve_perms(fd_in, fd_out); + preserve_perms(fd_in, fd_out); } else fd_out = open_tmpoutfile(); @@ -487,8 +486,7 @@ static void compress_file(void) } else fd_out = open_tmpoutfile(); - if (!NO_SET_PERMS) - preserve_perms(fd_in, fd_out); + preserve_perms(fd_in, fd_out); /* write zeroes to 24 bytes at beginning of file */ if (unlikely(write(fd_out, header, sizeof(header)) != sizeof(header))) @@ -539,7 +537,7 @@ int main(int argc, char *argv[]) if (strstr(argv[0], "lrunzip")) control.flags |= FLAG_DECOMPRESS; - control.compression_level = 9; + control.compression_level = 7; control.ramsize = get_ram(); control.window = 0; control.threshold = 1.0; /* default lzo test compression threshold (level 1) with LZMA compression */ @@ -563,7 +561,7 @@ int main(int argc, char *argv[]) else if (!strstr(eptr,"NOCONFIG")) read_config(&control); - while ((c = getopt(argc, argv, "L:hdS:tVvDfqo:w:nlbMUO:T:N:gPzi")) != -1) { + while ((c = getopt(argc, argv, "L:hdS:tVvDfqo:w:nlbMUO:T:N:p:gzi")) != -1) { switch (c) { case 'L': control.compression_level = atoi(optarg); @@ -664,8 +662,10 @@ int main(int argc, char *argv[]) fatal("Can only use one of -l, -b, -g, -z or -n\n"); control.flags |= FLAG_ZLIB_COMPRESS; break; - case 'P': - control.flags |= FLAG_NO_SET_PERMS; + case 'p': + control.threads = atoi(optarg); + if (control.threads < 1) + fatal("Must have at least one thread\n"); break; case 'z': if (control.flags & FLAG_NOT_LZMA) diff --git a/man/lrzip.1 b/man/lrzip.1 index 75348c9..5e4dbb9 100644 --- a/man/lrzip.1 +++ b/man/lrzip.1 @@ -39,9 +39,8 @@ Here is a summary of the options to lrzip\&. \-S suffix specify compressed suffix (default '.lrz') \-f force overwrite of any existing files \-D delete existing files - \-P don't set permissions on output file. It may leave it world-readable \-q don't show compression progress - \-L level set rzip/lzma/bzip2/gzip compression level (1\-9, default 9) + \-L level set rzip/lzma/bzip2/gzip compression level (1\-9, default 7) \-n no backend compression. Prepare for other compressor \-l lzo compression (ultra fast) \-b bzip2 compression @@ -51,7 +50,8 @@ Here is a summary of the options to lrzip\&. \-U Use unlimited window size beyond ramsize (potentially much slower) \-T value Compression threshold with LZO test. (0 (nil) - 10 (high), default 1) \-N value Set nice value to value (default 19) - \-v[v] Increase verbosity + \-p value Set processor count to override number of threads +-v[v] Increase verbosity \-V show version \-t test compressed file integrity \-i show compressed file information @@ -85,7 +85,7 @@ limit. It is limited to 2GB on 32bit machines. lrzip will always reduce the window size to the biggest it can be without running out of memory. .IP .IP "\fB-L 1\&.\&.9\fP" -Set the compression level from 1 to 9. The default is to use level 9, which +Set the compression level from 1 to 9. The default is to use level 7, which gives good all round compression. The compression level is also strongly related to how much memory lrzip uses. See the \-w option for details. .IP @@ -169,11 +169,6 @@ If this option is specified then lrzip will delete the source file after successful compression or decompression. When this option is not specified then the source files are not deleted. .IP -.IP "\fB-P\fP" -If this option is specified then lrzip will not try to set the file -permissions on writing the file. This helps when writing to a brain -damaged filesystem like fat32 on windows. -.IP .IP "\fB-q\fP" If this option is specified then lrzip will not show the percentage progress while compressing. Note that compression happens in @@ -185,6 +180,13 @@ The default nice value is 19. This option can be used to set the priority scheduling for the lrzip backup or decompression. Valid nice values are from \-20 to 19. Note this does NOT speed up or slow down compression. .IP +.IP "\fB-p value\fP" +Set the number of processor count to determine the number of threads to run. +Normally lrzip will scale according to the number of CPUs it detects. Using +this will override the value in case you wish to use less CPUs to either +decrease the load on your machine, or to improve compression. Setting it to +1 will maximise compression but will not attempt to use more than one CPU. +.IP .IP "\fB-t\fP" This tests the compressed file integrity. It does this by decompressing it to a temporary file and then deleting it. diff --git a/rzip.c b/rzip.c index bc0303c..44edca8 100644 --- a/rzip.c +++ b/rzip.c @@ -841,6 +841,9 @@ retry: } else mmap_stdin(sb.buf_low, st); + if (MAXRAM) + print_maxverbose("Succeeded in allocating %lld sized mmap\n", st->mmap_size); + if (st->mmap_size < st->chunk_size) print_verbose("Compression window is larger than ram allocated, will proceed with unlimited mode possibly much slower\n"); diff --git a/rzip.h b/rzip.h index 7d54861..eed59f2 100644 --- a/rzip.h +++ b/rzip.h @@ -182,12 +182,11 @@ static inline i64 get_ram(void) #define FLAG_ZPAQ_COMPRESS 1024 #define FLAG_VERBOSITY 2048 #define FLAG_VERBOSITY_MAX 4096 -#define FLAG_NO_SET_PERMS 8192 -#define FLAG_STDIN 16384 -#define FLAG_STDOUT 32768 -#define FLAG_INFO 65536 -#define FLAG_MAXRAM 131072 -#define FLAG_UNLIMITED 262144 +#define FLAG_STDIN 8192 +#define FLAG_STDOUT 16384 +#define FLAG_INFO 32768 +#define FLAG_MAXRAM 65536 +#define FLAG_UNLIMITED 131072 #define FLAG_VERBOSE (FLAG_VERBOSITY | FLAG_VERBOSITY_MAX) #define FLAG_NOT_LZMA (FLAG_NO_COMPRESS | FLAG_LZO_COMPRESS | FLAG_BZIP2_COMPRESS | FLAG_ZLIB_COMPRESS | FLAG_ZPAQ_COMPRESS) @@ -206,7 +205,6 @@ static inline i64 get_ram(void) #define VERBOSE (control.flags & FLAG_VERBOSE) #define VERBOSITY (control.flags & FLAG_VERBOSITY) #define MAX_VERBOSE (control.flags & FLAG_VERBOSITY_MAX) -#define NO_SET_PERMS (control.flags & FLAG_NO_SET_PERMS) #define STDIN (control.flags & FLAG_STDIN) #define STDOUT (control.flags & FLAG_STDOUT) #define INFO (control.flags & FLAG_INFO)