Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
sysctl_tuner: show command associated with process that sets sysctl
this will help diagnose the cause of sysctl changes that disable
auto-tuning.

Signed-off-by: Alan Maguire <[email protected]>
  • Loading branch information
alan-maguire committed Nov 26, 2024
commit b893c8b3730b1e913496c609a8fc7128323e5ca2
24 changes: 22 additions & 2 deletions src/sysctl_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ void fini(struct bpftuner *tuner)
bpftuner_bpf_fini(tuner);
}

static const char *pid2cmd(int pid, char *cmd, size_t cmdsize)
{
char cmdline[64];
FILE *fp;

snprintf(cmdline, sizeof(cmdline) - 1, "/proc/%d/cmdline", pid);
fp = fopen(cmdline, "r");
if (fp) {
fgets(cmd, cmdsize - 1, fp);
fclose(fp);
}
if (strlen(cmd) == 0)
strncpy(cmd, "?", 2);
return cmd;
}

void event_handler(struct bpftuner *tuner, struct bpftune_event *event,
__attribute__((unused))void *ctx)
{
Expand Down Expand Up @@ -80,9 +96,13 @@ void event_handler(struct bpftuner *tuner, struct bpftune_event *event,
* gc_thresh3 in neigh table tuner for example.
*/
if (strstr(path, event->str)) {
char cmd[1024] = {};

bpftune_log(BPFTUNE_LOG_LEVEL,
"user (pid %ld) modified sysctl '%s' that tuner '%s' uses; disabling '%s' for namespace cookie %ld\n",
event->pid, event->str, t->name, t->name,
"pid %ld, cmd '%s' modified sysctl '%s' that tuner '%s' uses; disabling '%s' for namespace cookie %ld\n",
event->pid,
pid2cmd(event->pid, cmd, sizeof(cmd)),
event->str, t->name, t->name,
event->netns_cookie);
bpftuner_netns_fini(t, event->netns_cookie, BPFTUNE_MANUAL);
break;
Expand Down