Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_tail: Add option file_cache_advise to reduce file cache usage #8422

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plugins/in_tail/tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,13 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_tail_config, skip_empty_lines),
"Allows to skip empty lines."
},

#ifdef __linux__
drbugfinder-work marked this conversation as resolved.
Show resolved Hide resolved
{
FLB_CONFIG_MAP_BOOL, "file_cache_advise", "true",
0, FLB_TRUE, offsetof(struct flb_tail_config, file_cache_advise),
"Use posix_fadvise for file access. Advise not to use kernel file cache."
},
#endif
#ifdef FLB_HAVE_INOTIFY
{
FLB_CONFIG_MAP_BOOL, "inotify_watcher", "true",
Expand Down
3 changes: 3 additions & 0 deletions plugins/in_tail/tail_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ struct flb_tail_config {
int skip_long_lines; /* skip long lines */
int skip_empty_lines; /* skip empty lines (off) */
int exit_on_eof; /* exit fluent-bit on EOF, test */
#ifdef __linux__
int file_cache_advise; /* Use posix_fadvise for file access */
#endif

int progress_check_interval; /* watcher interval */
int progress_check_interval_nsec; /* watcher interval */
Expand Down
17 changes: 16 additions & 1 deletion plugins/in_tail/tail_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,13 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
if (flb_tail_file_exists(st, ctx) == FLB_TRUE) {
return -1;
}


#ifdef __linux__
if (ctx->file_cache_advise) {
flb_plg_debug(ctx->ins, "file will be read in POSIX_FADV_DONTNEED mode %s", path);
}
#endif

fd = open(path, O_RDONLY);
if (fd == -1) {
flb_errno();
Expand Down Expand Up @@ -1429,6 +1435,15 @@ 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");
drbugfinder-work marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif

read_size = file_buffer_capacity;

if (file->decompression_context != NULL) {
Expand Down
Loading