• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEM_EVENTS_BPF_TYES_H_
18 #define MEM_EVENTS_BPF_TYES_H_
19 
20 #include <inttypes.h>
21 
22 #define MEM_EVENT_PROC_NAME_LEN 16  // linux/sched.h
23 #define MEM_EVENTS_RINGBUF_SIZE 4096
24 
25 typedef unsigned int mem_event_type_t;
26 /* Supported mem_event_type_t */
27 #define MEM_EVENT_OOM_KILL 0
28 #define MEM_EVENT_BASE MEM_EVENT_OOM_KILL
29 #define MEM_EVENT_DIRECT_RECLAIM_BEGIN 1
30 #define MEM_EVENT_DIRECT_RECLAIM_END 2
31 #define MEM_EVENT_KSWAPD_WAKE 3
32 #define MEM_EVENT_KSWAPD_SLEEP 4
33 
34 // This always comes after the last valid event type
35 #define NR_MEM_EVENTS 5
36 
37 /* BPF-Rb Paths */
38 #define MEM_EVENTS_AMS_RB "/sys/fs/bpf/map_bpfMemEvents_ams_rb"
39 #define MEM_EVENTS_LMKD_RB "/sys/fs/bpf/map_bpfMemEvents_lmkd_rb"
40 #define MEM_EVENTS_TEST_RB "/sys/fs/bpf/map_bpfMemEventsTest_rb"
41 
42 /* BPF-Prog Paths */
43 #define MEM_EVENTS_AMS_OOM_MARK_VICTIM_TP \
44     "/sys/fs/bpf/prog_bpfMemEvents_tracepoint_oom_mark_victim_ams"
45 #define MEM_EVENTS_LMKD_VMSCAN_DR_BEGIN_TP \
46     "/sys/fs/bpf/prog_bpfMemEvents_tracepoint_vmscan_mm_vmscan_direct_reclaim_begin_lmkd"
47 #define MEM_EVENTS_LMKD_VMSCAN_DR_END_TP \
48     "/sys/fs/bpf/prog_bpfMemEvents_tracepoint_vmscan_mm_vmscan_direct_reclaim_end_lmkd"
49 #define MEM_EVENTS_LMKD_VMSCAN_KSWAPD_WAKE_TP \
50     "/sys/fs/bpf/prog_bpfMemEvents_tracepoint_vmscan_mm_vmscan_kswapd_wake_lmkd"
51 #define MEM_EVENTS_LMKD_VMSCAN_KSWAPD_SLEEP_TP \
52     "/sys/fs/bpf/prog_bpfMemEvents_tracepoint_vmscan_mm_vmscan_kswapd_sleep_lmkd"
53 #define MEM_EVENTS_TEST_OOM_MARK_VICTIM_TP \
54     "/sys/fs/bpf/prog_bpfMemEventsTest_tracepoint_oom_mark_victim"
55 
56 /* Struct to collect data from tracepoints */
57 struct mem_event_t {
58     uint64_t type;
59 
60     union EventData {
61         struct OomKill {
62             uint32_t pid;
63             uint64_t timestamp_ms;
64             uint64_t oom_score_adj;
65             uint32_t uid;
66             char process_name[MEM_EVENT_PROC_NAME_LEN];
67             uint64_t total_vm_kb;
68             uint64_t anon_rss_kb;
69             uint64_t file_rss_kb;
70             uint64_t shmem_rss_kb;
71             uint64_t pgtables_kb;
72         } oom_kill;
73 
74         struct KswapdWake {
75             uint32_t node_id;
76             uint32_t zone_id;
77             uint32_t alloc_order;
78         } kswapd_wake;
79 
80         struct KswapdSleep {
81             uint32_t node_id;
82         } kswapd_sleep;
83     } event_data;
84 };
85 
86 /* Expected args for tracepoints */
87 
88 struct mark_victim_args {
89     uint64_t __ignore;
90     /* Actual fields start at offset 8 */
91     uint32_t pid;
92     uint32_t __data_loc_comm;
93     uint64_t total_vm;
94     uint64_t anon_rss;
95     uint64_t file_rss;
96     uint64_t shmem_rss;
97     uint32_t uid;
98     uint64_t pgtables;
99     short oom_score_adj;
100 };
101 
102 struct direct_reclaim_begin_args {
103     char __ignore[24];
104 };
105 
106 struct direct_reclaim_end_args {
107     char __ignore[16];
108 };
109 
110 struct kswapd_wake_args {
111     uint64_t __ignore;
112     /* Actual fields start at offset 8 */
113     uint32_t nid;
114     uint32_t zid;
115     uint32_t order;
116 };
117 
118 struct kswapd_sleep_args {
119     uint64_t __ignore;
120     /* Actual fields start at offset 8 */
121     uint32_t nid;
122 };
123 
124 #endif /* MEM_EVENTS_BPF_TYES_H_ */
125