Skip to content

Commit 6ef7cd8

Browse files
committed
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 <singholt@amazon.com>
1 parent 66ffbe4 commit 6ef7cd8

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

plugins/in_tail/tail_file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,15 +1698,6 @@ int flb_tail_file_chunk(struct flb_tail_file *file)
16981698
file_buffer_capacity = (file->buf_size - file->buf_len) - 1;
16991699
}
17001700

1701-
#ifdef __linux__
1702-
if (ctx->file_cache_advise) {
1703-
if (posix_fadvise(file->fd, 0, 0, POSIX_FADV_DONTNEED) == -1) {
1704-
flb_errno();
1705-
flb_plg_error(ctx->ins, "error during posix_fadvise");
1706-
}
1707-
}
1708-
#endif
1709-
17101701
read_size = file_buffer_capacity;
17111702

17121703
if (file->decompression_context != NULL) {
@@ -1822,6 +1813,15 @@ int flb_tail_file_chunk(struct flb_tail_file *file)
18221813
file->buf_len -= processed_bytes;
18231814
file->buf_data[file->buf_len] = '\0';
18241815

1816+
#ifdef __linux__
1817+
/* Evict only the already-processed byte range from the page cache
1818+
* so that kernel readahead for upcoming reads is preserved. */
1819+
if (ctx->file_cache_advise && file->stream_offset > 0) {
1820+
posix_fadvise(file->fd, 0, file->stream_offset,
1821+
POSIX_FADV_DONTNEED);
1822+
}
1823+
#endif
1824+
18251825
#ifdef FLB_HAVE_SQLDB
18261826
if (file->config->db) {
18271827
flb_tail_db_file_offset(file, file->config);

0 commit comments

Comments
 (0)