-
Notifications
You must be signed in to change notification settings - Fork 31
feat(memtrack): pause producers under ring pressure #543
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
Open
not-matthias
wants to merge
11
commits into
cod-3222-add-ebpf-based-dwarffp-unwinding
from
feat/memtrack-pause-worker
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c6f76e4
perf(memtrack): poll ring buffers every 1ms
not-matthias c0b2ba2
fix(memtrack): count stack-ring overflow as dropped events
not-matthias c0c4c19
fix(memtrack): keep stack hashing scratch inside the ring record
not-matthias a87e1f1
feat(memtrack): pause producers under ring pressure
not-matthias ebfbdef
test(memtrack): measure ring-pressure pause under an allocation storm
not-matthias 38ea912
test(memtrack): ignore duplicate frees in cross-variant comparison
not-matthias c023567
fix(memtrack): never resume a reused pid
not-matthias e594058
fixup! feat(memtrack): pause producers under ring pressure
not-matthias db9cfa5
feat(memtrack): log process stops and count them per reason
not-matthias 4953b6c
fixup! feat(memtrack): pause producers under ring pressure
not-matthias 3d58b73
fixup! fix(memtrack): never resume a reused pid
not-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
| #ifndef __PRESSURE_BPF_H__ | ||
| #define __PRESSURE_BPF_H__ | ||
|
|
||
| #include <bpf/bpf_helpers.h> | ||
|
|
||
| #include "map_helpers.h" | ||
| #include "process_tracking.h" | ||
| #include "stopped.h" | ||
|
|
||
| /* Ring pressure stop. Call only after submit/discard or a failed reserve: | ||
| * stopping with a live reservation would wedge the ring. A tracked producer | ||
| * that writes while the ring is over the watermark is stopped and recorded, | ||
| * so processes that do not write keep running. Userspace resumes the | ||
| * recorded producers once it has flushed the ring. */ | ||
|
|
||
| #define MEMTRACK_PRESSURE_HEADROOM_FRAC 4 /* stop at (FRAC-1)/FRAC = 75% used */ | ||
|
|
||
| static __always_inline int memtrack_ring_over_watermark(void* ring) { | ||
| __u64 size = bpf_ringbuf_query(ring, BPF_RB_RING_SIZE); | ||
| __u64 avail = bpf_ringbuf_query(ring, BPF_RB_AVAIL_DATA); | ||
| return avail >= size - size / MEMTRACK_PRESSURE_HEADROOM_FRAC; | ||
| } | ||
|
|
||
| static __always_inline void memtrack_check_ring_pressure(void* ring, __u32 current_tgid) { | ||
| if (!memtrack_ring_over_watermark(ring)) { | ||
| return; | ||
| } | ||
|
|
||
| /* Never stop an untracked process that happens to trigger a probe. */ | ||
| if (!is_tracked(current_tgid)) { | ||
| return; | ||
| } | ||
|
|
||
| memtrack_stop_current(&pressure_stopped, current_tgid); | ||
| } | ||
|
|
||
| #endif /* __PRESSURE_BPF_H__ */ |
This file contains hidden or 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,35 @@ | ||
| #ifndef __STOPPED_H__ | ||
| #define __STOPPED_H__ | ||
|
|
||
| #include <bpf/bpf_helpers.h> | ||
|
|
||
| #include "map_helpers.h" | ||
|
|
||
| #define MEMTRACK_SIGCONT 18 | ||
| #define MEMTRACK_SIGSTOP 19 | ||
|
|
||
| /* tgid -> 1 for every process BPF stopped, one map per reason. A process is | ||
| * recorded before its stop can take effect, and userspace resumes only | ||
| * recorded processes, so a process stopped for both reasons resumes once | ||
| * neither map holds it. Sized like tracked_pids. */ | ||
| BPF_HASH_MAP(pressure_stopped, __u32, __u8, 10000); | ||
| BPF_HASH_MAP(attach_stopped, __u32, __u8, 10000); | ||
|
|
||
| /* Stop the current process and record it in `map`. SIGSTOP is queued before | ||
| * the record is written: it only takes effect on return to user mode, so any | ||
| * SIGCONT sent after userspace sees the record cancels or ends the stop. | ||
| * Requires task context with IRQs enabled, where the signal is queued | ||
| * synchronously rather than via irq_work. */ | ||
| static __always_inline void memtrack_stop_current(void* map, __u32 tgid) { | ||
| if (bpf_send_signal(MEMTRACK_SIGSTOP) != 0) { | ||
| return; | ||
| } | ||
|
|
||
| __u8 marker = 1; | ||
| if (bpf_map_update_elem(map, &tgid, &marker, BPF_ANY) != 0) { | ||
| /* Unrecorded, so nothing would resume it. */ | ||
| bpf_send_signal(MEMTRACK_SIGCONT); | ||
| } | ||
| } | ||
|
|
||
| #endif /* __STOPPED_H__ */ | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this stop-record map is full while the process is also held for attach work or ring pressure, the failed update sends
SIGCONTwithout checking that other hold. The process can then run while it is supposed to remain stopped, allowing events during an attach or ring drain.Knowledge Base Used: eBPF memory tracker
Prompt To Fix With AI