Repository navigation
squashfs: readMetadata improve memory usage allocate only size bytes instead of whole block - #461
Conversation
|
I am trying to understand how this makes such a difference. Let's say (for simplicity's sake) that blocks are 100 bytes in size, and I am reading 300 bytes with starting offset of 50. So I would read:
The only difference between the existing code and this change seems to be that the last block, I read 50 instead of 100 bytes, because I limit reading the data from the block to whatever is left in I do see why it is logically correct. |
…instead of whole block
d20f36b to
621361c
Compare
|
your example is correct. the real gain here is when reading inodes which are small.
|
|
So we save on the following places:
Since we read the whole block from disk into memory anyways, shouldn't that dominate the first, and it will make no difference? As before, this change is fine and works well. I still don't understand why it would make such a difference. |
|
the block is not read from disk on every call. An 8 KB metadata block holds 250 inodes of 32 bytes. Listing a directory whose inodes are in that block costs:
the block read is amortized over all the inodes it contains, the copy is not. |
|
Aha! That makes sense! |
Benchmarks
readMetadataused to copy from the requested offset to the end of the metadata block, up to 8 KiB, even whenthe caller needed a few dozen bytes, e.g. for each inode of a directory being listed. It now copies exactly
sizebytes.
Apple M4 Max,
benchstatof 8 runs (ReadDir) and 6 runs (WalkImage).BenchmarkReadDir:ReadDirof a directory nested 4 levels deep, image built withFinalizeTime per entry is now flat (~115 ns warm) instead of growing with the size of the directory (239 → 550 ns).
The number of allocations does not change: each one is just smaller.
BenchmarkWalkImage:fs.WalkDirover a whole image,Info()on every entry, and inwalk+readevery regularfile opened by path and read to the end. Synthetic Node.js application package built with
mksquashfs(gzip):278 MiB compressed, 1.3 GiB of data, 82,912 files, 14,061 directories
If requested I can provide the code used for benchmarking