From 6ef7cd8769f8813c0d426c7e5f1fd23018a5ff6c Mon Sep 17 00:00:00 2001 From: Anuj Singh Date: Thu, 2 Apr 2026 10:17:50 -0700 Subject: [PATCH] in_tail: fix file_cache_advise causing high disk IOPS The posix_fadvise(POSIX_FADV_DONTNEED) call was placed before the read and evicted the entire file from the page cache on every chunk cycle. This forced every subsequent read to go to disk, causing excessive IOPS. Move the call to after read and processing, and scope it to only the already-consumed byte range (0 to stream_offset) so that kernel readahead pages for upcoming reads are preserved. Signed-off-by: Anuj Singh --- plugins/in_tail/tail_file.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/in_tail/tail_file.c b/plugins/in_tail/tail_file.c index 06c51d7d68d..9b36bfbdc0c 100644 --- a/plugins/in_tail/tail_file.c +++ b/plugins/in_tail/tail_file.c @@ -1698,15 +1698,6 @@ int flb_tail_file_chunk(struct flb_tail_file *file) file_buffer_capacity = (file->buf_size - file->buf_len) - 1; } - #ifdef __linux__ - if (ctx->file_cache_advise) { - if (posix_fadvise(file->fd, 0, 0, POSIX_FADV_DONTNEED) == -1) { - flb_errno(); - flb_plg_error(ctx->ins, "error during posix_fadvise"); - } - } - #endif - read_size = file_buffer_capacity; if (file->decompression_context != NULL) { @@ -1822,6 +1813,15 @@ int flb_tail_file_chunk(struct flb_tail_file *file) file->buf_len -= processed_bytes; file->buf_data[file->buf_len] = '\0'; +#ifdef __linux__ + /* Evict only the already-processed byte range from the page cache + * so that kernel readahead for upcoming reads is preserved. */ + if (ctx->file_cache_advise && file->stream_offset > 0) { + posix_fadvise(file->fd, 0, file->stream_offset, + POSIX_FADV_DONTNEED); + } +#endif + #ifdef FLB_HAVE_SQLDB if (file->config->db) { flb_tail_db_file_offset(file, file->config);