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

Workaround for Linux CGroup V2 causing dropped packets with recording and a memory limit set #3004

Draft
wants to merge 1 commit into
base: 0.x
Choose a base branch
from
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