-
Notifications
You must be signed in to change notification settings - Fork 0
feat(governor): group store wired + deterministic eviction tests #56
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #pragma once | ||
|
|
||
| #include "heidi-kernel/gov_rule.h" | ||
|
|
||
| #include <array> | ||
| #include <cstdint> | ||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| namespace heidi { | ||
| namespace gov { | ||
|
|
||
| constexpr size_t kMaxGroups = 256; | ||
| constexpr size_t kMaxPidGroupMap = 8192; | ||
|
|
||
| struct GroupPolicy { | ||
| std::array<char, kMaxGroupIdLen + 1> group_id{}; | ||
| uint64_t last_update_ns = 0; | ||
|
|
||
| std::optional<uint8_t> cpu_max_pct; | ||
| std::optional<uint32_t> cpu_quota_us; | ||
| std::optional<uint32_t> cpu_period_us; | ||
|
|
||
| std::optional<uint64_t> mem_max_bytes; | ||
| std::optional<uint64_t> mem_high_bytes; | ||
|
|
||
| std::optional<uint32_t> pids_max; | ||
|
|
||
| std::optional<ViolationAction> default_action; | ||
| std::optional<uint32_t> apply_deadline_ms; | ||
|
|
||
| bool has_any_policy() const; | ||
| }; | ||
|
|
||
| class GroupPolicyStore { | ||
| public: | ||
| enum class EvictReason : uint8_t { | ||
| NONE = 0, | ||
| GROUP_EVICTED = 1, | ||
| PIDMAP_EVICTED = 2, | ||
| }; | ||
|
|
||
| struct Stats { | ||
| size_t group_count = 0; | ||
| size_t pid_group_map_count = 0; | ||
| uint64_t group_evictions = 0; | ||
| uint64_t pidmap_evictions = 0; | ||
| uint64_t attach_failures = 0; | ||
| uint64_t cgroup_unavailable_count = 0; | ||
| int last_err = 0; | ||
| }; | ||
|
|
||
| bool upsert_group(const char* group_id, const GovApplyMsg& msg); | ||
| bool map_pid_to_group(int32_t pid, const char* group_id); | ||
| const GroupPolicy* get_group(const char* group_id) const; | ||
| const char* get_group_for_pid(int32_t pid) const; | ||
| Stats get_stats() const; | ||
| void clear(); | ||
|
|
||
| void set_time_for_test(uint64_t seq) { | ||
| test_seq_ = seq; | ||
| } | ||
| uint64_t get_time_for_test() const { | ||
| return test_seq_; | ||
| } | ||
| void tick(); | ||
|
|
||
| static constexpr uint64_t kTimeIncrement = 1000000000ULL; | ||
|
|
||
| private: | ||
| uint64_t get_time() const; | ||
| void evict_oldest_group(); | ||
| void evict_oldest_pid_entry(); | ||
|
|
||
| struct GroupEntry { | ||
| GroupPolicy policy; | ||
| bool in_use = false; | ||
| }; | ||
|
|
||
| struct PidEntry { | ||
| std::array<char, kMaxGroupIdLen + 1> group_id{}; | ||
| uint64_t last_seen_ns = 0; | ||
| bool in_use = false; | ||
| }; | ||
|
|
||
| GroupEntry groups_[kMaxGroups]; | ||
| PidEntry pid_map_[kMaxPidGroupMap]; | ||
| size_t group_count_ = 0; | ||
| size_t pid_map_count_ = 0; | ||
| Stats stats_; | ||
| uint64_t test_seq_ = 0; | ||
| }; | ||
|
|
||
| } // namespace gov | ||
| } // namespace heidi | ||
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.
The
PidEntrystruct is missing a field to store the actual process ID. Since PIDs are sparse and can exceed the fixed size of thepid_map_array, the mapping logic must store the PID explicitly to perform correct lookups.