tail:Fix tail -f sparse file growth handling #12080
<!-- gnu-comment-bot -->
GNU testsuite comparison:
Congrats! The gnu test tests/pr/options is no longer failing!
make this a named function?
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will degrade performance by 3.24%
<details>
<summary>:warning: <b>Different runtime environments detected</b></summary>
Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.
> Open the report in CodSpeed to investigate
</details>
❌ 1 regressed benchmark ✅ 338 untouched benchmarks ⏩ 46 skipped benchmarks[^skipped]
[!WARNING]
Please fix the performance issues or acknowledge them on CodSpeed.
Performance Changes
| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ❌ | Simulation | [` uniq_check_chars[(10000, "1")] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Atail_12015?uri=src%2Fuu%2Funiq%2Fbenches%2Funiq_bench.rs%3A%3Auniq_check_chars%5B%2810000%2C+%221%22%29%5D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 14.4 ms | 14.9 ms | -3.24% |
[!TIP]
Investigate this regression by commenting @codspeedbot fix this regression` on this PR, or directly use the CodSpeed MCP with your agent.
---
<sub>Comparing <code>mattsu2020:tail_12015</code> (8af08a5) with <code>main</code> (bd73c58)</sub>
<a href="https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Atail_12015?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
I'm not even sure there was a need for that in the first place... this is a weird JS idiom that popped up after I noped out of there. The new added function looks fine tho.
if chunk.fill(reader)?.is_none() {
Requested changes.
Is it possible to add a test? Thanks
reader is already a BufRead, could we just check reader.fill_buf()?.is_empty() instead of copying into a BytesChunk?
please drop the "old implementation" part, something like "make sure we stream instead of buffering the new data" is enough
I have revised the comment.
it has been conflicting for more than 7 days, sorry! please rebase it
xtqqczze
mattsu2020
Summary
Fixes tail -f behavior when a followed sparse file grows by a very large amount, such as via truncate -s 1P.
The follow path previously used BytesChunkBuffer::new(u64::MAX), which consumed all newly readable bytes into memory before printing. For sparse file holes, those bytes are read as NULs, so a large logical size increase could cause tail to consume excessive memory and get killed.
This changes follow-mode output to read one chunk to detect whether new data exists and preserve header behavior, then stream the remaining data directly to stdout with io::copy.
Fixes #12015.
Validation