Skip to content
Draft
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
14 changes: 14 additions & 0 deletions record.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <libgen.h>
#include <fcntl.h>

#include <glib.h>
#include <jansson.h>
Expand Down Expand Up @@ -464,6 +465,19 @@ int janus_recorder_save_frame(janus_recorder *recorder, char *buffer, uint lengt
header->seq_number = htons(seq);
header->timestamp = htonl(timestamp);
}

/* Mark the file as POSIX_FADV_DONTNEED, since we won't be reading from it at all. This
* prevents polution of the page cache, but also fixes a nasty bug where CGroupsV2
* considers the page cache to be used kernel memory, and won't allocate new UDP
* buffer space if it's full, leading to dropped packets. Can't just do this once
* at the start unfortunately, so we do it every ~100 packets.
*/
recorder->unflushed_count++;
if (recorder->unflushed_count == 100) {
posix_fadvise(fileno(recorder->file), 0, 0, POSIX_FADV_DONTNEED);
recorder->unflushed_count = 0;
}

/* Done */
janus_mutex_unlock_nodebug(&recorder->mutex);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions record.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ typedef struct janus_recorder {
volatile gint destroyed;
/*! \brief Reference counter for this instance */
janus_refcount ref;
/*! \brief Used to flush the page cache every n packets */
int unflushed_count;
} janus_recorder;

/*! \brief Initialize the recorder code
Expand Down