Skip to content

Commit

Permalink
Optimize block statistics in fsindex
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 26, 2024
1 parent 63d3000 commit e808e7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix build without c-pages, but with c-fsindex
* Add the ability to detect truncated archives
* Replace all memory related API to debug-enabled
* Optimize block statistics in fsindex

2024-05-25 Konstantin Kushnir <[email protected]>
* Add support for writer in C
Expand Down
16 changes: 12 additions & 4 deletions generic/fsindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,22 @@ void Cookfs_FsindexModifyBlockUsage(Cookfs_Fsindex *i, int idx, int count) {
if (idx < 0)
return;

CookfsLog(printf("Cookfs_FsindexModifyBlockUsage: increase block index [%d] by [%d]", idx, count));
CookfsLog(printf("Cookfs_FsindexModifyBlockUsage: increase block"
" index [%d] by [%d]", idx, count));
// check if we have enough space in the block index
if (i->blockIndexSize <= idx) {
CookfsLog(printf("Cookfs_FsindexModifyBlockUsage: expand block index buffer from [%d] to [%d]", i->blockIndexSize, idx + 1));
// Increase blockIndexSize by idx+100 to reduce memory reallocations
// when filling the index and modifying block statistics
// block by block.
int maxBlockIndexSize = idx + 100;
CookfsLog(printf("Cookfs_FsindexModifyBlockUsage: expand block index"
" buffer from [%d] to [%d]", i->blockIndexSize,
maxBlockIndexSize));
// expand our block index
i->blockIndex = (int *)ckrealloc(i->blockIndex, sizeof(int) * (idx + 1));
i->blockIndex = (int *)ckrealloc(i->blockIndex,
sizeof(int) * maxBlockIndexSize);
// initialize newly allocated block indexes with zeros
for (; i->blockIndexSize <= idx; i->blockIndexSize++) {
for (; i->blockIndexSize < maxBlockIndexSize; i->blockIndexSize++) {
i->blockIndex[i->blockIndexSize] = 0;
}
} else {
Expand Down

0 comments on commit e808e7d

Please sign in to comment.