diff options
Diffstat (limited to 'xdelta3-blkcache.h')
-rw-r--r-- | xdelta3-blkcache.h | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/xdelta3-blkcache.h b/xdelta3-blkcache.h index 36a5c90..82d720e 100644 --- a/xdelta3-blkcache.h +++ b/xdelta3-blkcache.h @@ -26,9 +26,6 @@ typedef struct _main_blklru main_blklru; typedef struct _main_blklru_list main_blklru_list; - -#define XD3_INVALID_OFFSET XOFF_T_MAX - struct _main_blklru_list { main_blklru_list *next; @@ -43,6 +40,10 @@ struct _main_blklru main_blklru_list link; }; +#define MAX_LRU_SIZE 32U +#define XD3_MINSRCWINSZ (XD3_ALLOCSIZE * MAX_LRU_SIZE) +#define XD3_MAXSRCWINSZ (1ULL << 31) + XD3_MAKELIST(main_blklru_list,main_blklru,link); static usize_t lru_size = 0; @@ -128,7 +129,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, /* Note: The API requires a power-of-two blocksize and srcwinsz * (-B). The logic here will use a single block if the entire file * is known to fit into srcwinsz. */ - option_srcwinsz = xd3_xoff_roundup (option_srcwinsz); + option_srcwinsz = xd3_pow2_roundup (option_srcwinsz); /* Though called "lru", it is not LRU-specific. We always allocate * a maximum number of source block buffers. If the entire file @@ -156,7 +157,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, * is the point at which external decompression may begin. Set the * system for a single block. */ lru_size = 1; - lru[0].blkno = XD3_INVALID_OFFSET; + lru[0].blkno = (xoff_t) -1; blksize = option_srcwinsz; main_blklru_list_push_back (& lru_list, & lru[0]); XD3_ASSERT (blksize != 0); @@ -165,7 +166,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, source->blksize = blksize; source->name = sfile->filename; source->ioh = sfile; - source->curblkno = XD3_INVALID_OFFSET; + source->curblkno = (xoff_t) -1; source->curblk = NULL; source->max_winsize = option_srcwinsz; @@ -183,7 +184,6 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, if (!sfile->size_known && source->onblk < blksize) { source_size = source->onblk; - source->onlastblk = source_size; sfile->size_known = 1; } @@ -195,10 +195,8 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, /* Modify block 0, change blocksize. */ blksize = option_srcwinsz / MAX_LRU_SIZE; source->blksize = blksize; - source->onblk = blksize; - source->onlastblk = blksize; - source->max_blkno = MAX_LRU_SIZE - 1; - + source->onblk = blksize; /* xd3 sets onblk */ + /* Note: source->max_winsize is unchanged. */ lru[0].size = blksize; lru_size = MAX_LRU_SIZE; @@ -261,7 +259,7 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, if (option_verbose > 1) { - short_sprintf (nbufs, " #bufs %"W"u", lru_size); + short_sprintf (nbufs, " #bufs %u", lru_size); } XPR(NT "source %s %s blksize %s window %s%s%s\n", @@ -296,7 +294,7 @@ main_getblk_lru (xd3_source *source, xoff_t blkno, return 0; } /* No going backwards in a sequential scan. */ - if (blru->blkno != XD3_INVALID_OFFSET && blru->blkno > blkno) + if (blru->blkno != (xoff_t) -1 && blru->blkno > blkno) { return XD3_TOOFARBACK; } @@ -312,13 +310,9 @@ main_getblk_lru (xd3_source *source, xoff_t blkno, main_blklru_list_remove (blru); main_blklru_list_push_back (& lru_list, blru); (*blrup) = blru; - IF_DEBUG1 (DP(RINT "[getblk_lru] HIT blkno = %"Q"u lru_size=%"W"u\n", - blkno, lru_size)); return 0; } } - IF_DEBUG1 (DP(RINT "[getblk_lru] MISS blkno = %"Q"u lru_size=%"W"u\n", - blkno, lru_size)); } if (do_src_fifo) @@ -336,7 +330,7 @@ main_getblk_lru (xd3_source *source, xoff_t blkno, lru_filled += 1; (*is_new) = 1; (*blrup) = blru; - blru->blkno = XD3_INVALID_OFFSET; + blru->blkno = -1; return 0; } @@ -437,7 +431,7 @@ main_read_seek_source (xd3_stream *stream, if (nread != source->blksize) { - IF_DEBUG1 (DP(RINT "[getblk] short skip block nread = %"Z"u\n", + IF_DEBUG1 (DP(RINT "[getblk] short skip block nread = %zu\n", nread)); stream->msg = "non-seekable input is short"; return XD3_INVALID_INPUT; @@ -446,7 +440,7 @@ main_read_seek_source (xd3_stream *stream, sfile->source_position += nread; blru->size = nread; - IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q"u size %"W"u\n", + IF_DEBUG1 (DP(RINT "[getblk] skip blkno %"Q"u size %u\n", skip_blkno, blru->size)); XD3_ASSERT (sfile->source_position <= pos); @@ -474,6 +468,7 @@ main_getblk_func (xd3_stream *stream, main_file *sfile = (main_file*) source->ioh; main_blklru *blru; int is_new; + int did_seek = 0; size_t nread = 0; if (allow_fake_source) @@ -510,10 +505,20 @@ main_getblk_func (xd3_stream *stream, { return ret; } + + /* Indicates that another call to main_getblk_lru() may be + * needed */ + did_seek = 1; } XD3_ASSERT (sfile->source_position == pos); + if (did_seek && + (ret = main_getblk_lru (source, blkno, & blru, & is_new))) + { + return ret; + } + if ((ret = main_read_primary_input (sfile, (uint8_t*) blru->blk, source->blksize, @@ -527,24 +532,24 @@ main_getblk_func (xd3_stream *stream, if (option_verbose > 3) { - if (blru->blkno != XD3_INVALID_OFFSET) + if (blru->blkno != (xoff_t)-1) { if (blru->blkno != blkno) { - XPR(NT "source block %"Q"u read %"Z"u ejects %"Q"u (lru_hits=%u, " + XPR(NT "source block %"Q"u read %zu ejects %"Q"u (lru_hits=%u, " "lru_misses=%u, lru_filled=%u)\n", blkno, nread, blru->blkno, lru_hits, lru_misses, lru_filled); } else { - XPR(NT "source block %"Q"u read %"Z"u (lru_hits=%u, " + XPR(NT "source block %"Q"u read %zu (lru_hits=%u, " "lru_misses=%u, lru_filled=%u)\n", blkno, nread, lru_hits, lru_misses, lru_filled); } } else { - XPR(NT "source block %"Q"u read %"Z"u (lru_hits=%u, lru_misses=%u, " + XPR(NT "source block %"Q"u read %zu (lru_hits=%u, lru_misses=%u, " "lru_filled=%u)\n", blkno, nread, lru_hits, lru_misses, lru_filled); } @@ -556,7 +561,7 @@ main_getblk_func (xd3_stream *stream, blru->size = nread; blru->blkno = blkno; - IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q"u onblk %"Z"u pos %"Q"u " + IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q"u onblk %zu pos %"Q"u " "srcpos %"Q"u\n", blkno, nread, pos, sfile->source_position)); |