-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36d4473
commit 95c489e
Showing
6 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef _NETDATA_OOMKILL_H_ | ||
#define _NETDATA_OOMKILL_H_ 1 | ||
|
||
// to try and only use 4096 bytes in the map and no more given 4 byte keys & 1 | ||
// byte values, we choose a very small number. | ||
#define NETDATA_OOMKILL_MAX_ENTRIES 64 | ||
|
||
// /sys/kernel/debug/tracing/events/oom/mark_victim/ | ||
struct netdata_oom_mark_victim_entry { | ||
u64 pad; // This is not used with eBPF | ||
int pid; // offset:8; size:4; signed:1; | ||
}; | ||
|
||
#endif /* _NETDATA_OOMKILL_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ NETDATA_APPS= btrfs \ | |
mount \ | ||
msync \ | ||
nfs \ | ||
oomkill \ | ||
process \ | ||
socket \ | ||
softirq \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#define KBUILD_MODNAME "oomkill_netdata" | ||
#include <linux/bpf.h> | ||
#include <linux/ptrace.h> | ||
#include <linux/oom.h> | ||
#include <linux/threads.h> | ||
|
||
#include "bpf_helpers.h" | ||
#include "netdata_ebpf.h" | ||
|
||
struct bpf_map_def SEC("maps") tbl_oomkill = { | ||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) | ||
.type = BPF_MAP_TYPE_HASH, | ||
#else | ||
.type = BPF_MAP_TYPE_PERCPU_HASH, | ||
#endif | ||
.key_size = sizeof(int), | ||
.value_size = sizeof(__u8), | ||
.max_entries = NETDATA_OOMKILL_MAX_ENTRIES | ||
}; | ||
|
||
SEC("tracepoint/oom/mark_victim") | ||
int netdata_oom_mark_victim(struct netdata_oom_mark_victim_entry *ptr) { | ||
int key = ptr->pid; | ||
u8 val = 0; | ||
bpf_map_update_elem(&tbl_oomkill, &key, &val, BPF_ANY); | ||
return 0; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |