@@ -119,12 +119,12 @@ network streams.
119119
120120## Sample Data
121121
122- Sample data begins at offset 64 and extends to ` string_table_offset ` . Samples
123- are grouped into blocks of at most 1 MiB of decoded data. Within a block,
124- samples use delta compression to minimize redundancy when consecutive samples
125- from the same thread have identical or similar call stacks. Each block can be
126- decoded on its own once the string and frame tables are loaded, so a reader
127- only needs to decode one block at a time .
122+ Sample data begins at offset 64 and extends to ` string_table_offset ` . Each
123+ block has a header followed by its columns. The columns together take at most
124+ 1 MiB on disk and at most 1 MiB when decoded. Within a block, samples use
125+ delta compression to minimize redundancy when consecutive samples from the
126+ same thread have identical or similar call stacks. Once the reader loads the
127+ string and frame tables, it can decode each block on its own .
128128
129129### Block Format
130130
@@ -659,16 +659,25 @@ patterns benefit from kernel read-ahead.
659659
660660The implementation uses ` madvise() ` to hint the access pattern to the kernel:
661661` MADV_SEQUENTIAL ` indicates the file will be read linearly, enabling
662- aggressive read-ahead. ` MADV_WILLNEED ` requests pre-faulting of pages.
663- On Linux, ` MAP_POPULATE ` pre-faults all pages at mmap time rather than on
664- first access, moving page fault overhead from the parsing loop to the
665- initial mapping for more predictable performance. For large files (over
666- 32 MB), ` MADV_HUGEPAGE ` requests transparent huge pages (2 MB instead of
667- 4 KB) to reduce TLB pressure when accessing large amounts of data.
668-
669- On Windows, the implementation falls back to standard file I/O with full
670- file buffering. Profiling data files are typically small enough (tens to
671- hundreds of megabytes) that this is acceptable.
662+ aggressive read-ahead. For large files (over 32 MB), ` MADV_HUGEPAGE ` requests
663+ transparent huge pages (2 MB instead of 4 KB) to reduce TLB pressure when
664+ accessing large amounts of data. Pages are not loaded up front, only when
665+ replay reaches them.
666+
667+ On Linux, the reader also gives back memory it no longer needs. Once the
668+ string and frame tables have been parsed, and after each sample block has
669+ been replayed, it uses ` MADV_DONTNEED ` to tell the kernel those pages can be
670+ dropped. The mapping is read-only, so if a dropped page is needed again, the
671+ kernel reads it back from the file. This keeps the memory used for sample
672+ data small, however large the file is.
673+
674+ On Windows, the reader uses standard file I/O instead. When a file is opened,
675+ it only reads the header and the part after the sample data, which holds the
676+ string and frame tables, the statistics and the footer. During replay,
677+ samples are read into a reusable buffer. The reader requests the smaller of
678+ 2 MiB and the sample section size. A complete block, including its header,
679+ fits in this buffer. When the buffer runs low, the bytes not yet
680+ replayed are moved to the start and the rest is filled from the file.
672681
673682The writer buffers samples in the current block and writes each completed
674683block with a single call, so individual samples never cause a write.
0 commit comments