From 688aa55c7930c883d5a8ab9d963af673ad805445 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 3 Dec 2010 19:33:56 +1100 Subject: [PATCH] Make threads spawn at regular intervals along chunk size thus speeding up compression. One more fix for unnecessary argument passing. --- rzip.c | 23 +++++++++++++++-------- stream.c | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/rzip.c b/rzip.c index bf57173..182a8f3 100644 --- a/rzip.c +++ b/rzip.c @@ -218,26 +218,26 @@ static void put_match(struct rzip_state *st, i64 p, i64 offset, i64 len) } while (len); } -/* write some data to a stream mmap encoded. Return -1 on failure */ -int write_sbstream(void *ss, int stream, i64 p, i64 len) +/* write some data to stream 1 mmap encoded. Return -1 on failure */ +int write_sbstream(void *ss, i64 p, i64 len) { struct stream_info *sinfo = ss; while (len) { i64 n, i; - n = MIN(sinfo->bufsize - sinfo->s[stream].buflen, len); + n = MIN(sinfo->bufsize - sinfo->s[1].buflen, len); for (i = 0; i < n; i++) { - memcpy(sinfo->s[stream].buf + sinfo->s[stream].buflen + i, + memcpy(sinfo->s[1].buf + sinfo->s[1].buflen + i, get_sb(p + i), 1); } - sinfo->s[stream].buflen += n; + sinfo->s[1].buflen += n; p += n; len -= n; - if (sinfo->s[stream].buflen == sinfo->bufsize) - flush_buffer(sinfo, stream); + if (sinfo->s[1].buflen == sinfo->bufsize) + flush_buffer(sinfo, 1); } return 0; } @@ -254,7 +254,7 @@ static void put_literal(struct rzip_state *st, i64 last, i64 p) put_header(st->ss, 0, len); - if (unlikely(len && write_sbstream(st->ss, 1, last, len))) + if (unlikely(len && write_sbstream(st->ss, last, len))) fatal("Failed to write_stream in put_literal\n"); last += len; } while (p > last); @@ -493,6 +493,7 @@ static void show_distrib(struct rzip_state *st) static void hash_search(struct rzip_state *st, double pct_base, double pct_multiple) { + struct stream_info *sinfo = st->ss; i64 cksum_limit = 0, p, end; tag t = 0; struct { @@ -540,6 +541,12 @@ static void hash_search(struct rzip_state *st, double pct_base, double pct_multi i64 reverse, mlen, offset = 0; p++; + /* Flush stream 1 at equal intervals if the buffer has not + * filled to bufsize */ + if (sinfo->s[1].eos < p / (st->chunk_size / control.threads) && + p >= STREAM_BUFSIZE) { + flush_buffer(sinfo, 1); + } sb.offset_search = p; t = next_tag(st, p, t); diff --git a/stream.c b/stream.c index cf6fe17..0c07309 100644 --- a/stream.c +++ b/stream.c @@ -21,8 +21,6 @@ #include "rzip.h" -#define STREAM_BUFSIZE (1024 * 1024 * 10) - struct compress_thread{ uchar *s_buf; /* Uncompressed buffer -> Compressed buffer */ uchar c_type; /* Compression type */ @@ -919,6 +917,8 @@ void flush_buffer(struct stream_info *sinfo, int stream) { long i = sinfo->thread_no; + sinfo->s[stream].eos++; + /* Make sure this thread doesn't already exist */ wait_sem(&cthread[i].free);