Skip to content

Commit 8e0941e

Browse files
drbugfinder-workedsiper
authored andcommitted
in_tail: Add option file_cache_advise to reduce file cache usage
This commit will add option file_cache_advise to the tail plugin. It allows to set the posix_fadvise in POSIX_FADV_DONTNEED mode. This will reduce the usage of the kernel file cache. Feature is enabled by default. Signed-off-by: Richard Treu <richard.treu@sap.com>
1 parent 158e675 commit 8e0941e

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

plugins/in_tail/tail.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,13 @@ static struct flb_config_map config_map[] = {
705705
0, FLB_TRUE, offsetof(struct flb_tail_config, skip_empty_lines),
706706
"Allows to skip empty lines."
707707
},
708-
708+
#ifdef __linux__
709+
{
710+
FLB_CONFIG_MAP_BOOL, "file_cache_advise", "true",
711+
0, FLB_TRUE, offsetof(struct flb_tail_config, file_cache_advise),
712+
"Use posix_fadvise for file access. Advise not to use kernel file cache."
713+
},
714+
#endif
709715
#ifdef FLB_HAVE_INOTIFY
710716
{
711717
FLB_CONFIG_MAP_BOOL, "inotify_watcher", "true",

plugins/in_tail/tail_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ struct flb_tail_config {
9393
int skip_long_lines; /* skip long lines */
9494
int skip_empty_lines; /* skip empty lines (off) */
9595
int exit_on_eof; /* exit fluent-bit on EOF, test */
96+
#ifdef __linux__
97+
int file_cache_advise; /* Use posix_fadvise for file access */
98+
#endif
9699

97100
int progress_check_interval; /* watcher interval */
98101
int progress_check_interval_nsec; /* watcher interval */

plugins/in_tail/tail_file.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,13 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
946946
if (flb_tail_file_exists(st, ctx) == FLB_TRUE) {
947947
return -1;
948948
}
949-
949+
950+
#ifdef __linux__
951+
if (ctx->file_cache_advise) {
952+
flb_plg_debug(ctx->ins, "file will be read in POSIX_FADV_DONTNEED mode %s", path);
953+
}
954+
#endif
955+
950956
fd = open(path, O_RDONLY);
951957
if (fd == -1) {
952958
flb_errno();
@@ -1435,6 +1441,15 @@ int flb_tail_file_chunk(struct flb_tail_file *file)
14351441
file_buffer_capacity = (file->buf_size - file->buf_len) - 1;
14361442
}
14371443

1444+
#ifdef __linux__
1445+
if (ctx->file_cache_advise) {
1446+
if (posix_fadvise(file->fd, 0, 0, POSIX_FADV_DONTNEED) == -1) {
1447+
flb_errno();
1448+
flb_plg_error(ctx->ins, "error during posix_fadvise");
1449+
}
1450+
}
1451+
#endif
1452+
14381453
read_size = file_buffer_capacity;
14391454

14401455
if (file->decompression_context != NULL) {

0 commit comments

Comments
 (0)