Skip to content
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

fix: the policy does not check memory in analyzer mode #8540

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion agent/src/flow_generator/flow_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ pub fn _new_flow_map_and_receiver(
flow_timeout: Option<FlowTimeout>,
ignore_idc_vlan: bool,
) -> (ModuleConfig, FlowMap, Receiver<Arc<BatchedBox<TaggedFlow>>>) {
let (_, mut policy_getter) = Policy::new(1, 0, 1 << 10, 1 << 14, false);
let (_, mut policy_getter) = Policy::new(1, 0, 1 << 10, 1 << 14, false, false);
policy_getter.disable();
let queue_debugger = QueueDebugger::new();
let (output_queue_sender, output_queue_receiver, _) =
Expand Down
16 changes: 14 additions & 2 deletions agent/src/policy/first_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ pub struct FirstPath {
fast: FastPath,

fast_disable: bool,
memory_check_disable: bool,

memory_limit: AtomicU64,
}
Expand All @@ -261,7 +262,13 @@ impl FirstPath {
const POLICY_LIMIT: u64 = 500000;
const MEMORY_LIMIT: u64 = 1 << 20;

pub fn new(queue_count: usize, level: usize, map_size: usize, fast_disable: bool) -> FirstPath {
pub fn new(
queue_count: usize,
level: usize,
map_size: usize,
fast_disable: bool,
memory_check_disable: bool,
) -> FirstPath {
FirstPath {
group_ip_map: Some(AHashMap::new()),
vector_4: Vector4::default(),
Expand All @@ -281,6 +288,7 @@ impl FirstPath {

fast: FastPath::new(queue_count, map_size),
fast_disable,
memory_check_disable,
memory_limit: AtomicU64::new(0),
}
}
Expand Down Expand Up @@ -365,6 +373,10 @@ impl FirstPath {
}

fn memory_check(&self, size: u64) -> bool {
if self.memory_check_disable {
return true;
}

let Ok(current) = get_memory_rss() else {
warn!("Cannot check policy memory: Get process memory failed.");
return true;
Expand Down Expand Up @@ -804,7 +816,7 @@ mod tests {
}

fn generate_table() -> PResult<FirstPath> {
let mut first = FirstPath::new(1, 8, 1 << 16, false);
let mut first = FirstPath::new(1, 8, 1 << 16, false, false);
let acl = Acl::new(
1,
vec![10],
Expand Down
11 changes: 9 additions & 2 deletions agent/src/policy/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,17 @@ impl Policy {
map_size: usize,
forward_capacity: usize,
fast_disable: bool,
memory_check_disable: bool,
) -> (PolicySetter, PolicyGetter) {
let policy = Box::into_raw(Box::new(Policy {
labeler: Labeler::default(),
table: FirstPath::new(queue_count, level, map_size, fast_disable),
table: FirstPath::new(
queue_count,
level,
map_size,
fast_disable,
memory_check_disable,
),
forward: Forward::new(queue_count, forward_capacity),
nat: RwLock::new(vec![AHashMap::new(), AHashMap::new()]),
first_hit: 0,
Expand Down Expand Up @@ -738,7 +745,7 @@ mod test {

#[test]
fn test_policy_normal() {
let (mut setter, mut getter) = Policy::new(10, 0, 1024, 1024, false);
let (mut setter, mut getter) = Policy::new(10, 0, 1024, 1024, false, false);
let interface: PlatformData = PlatformData {
mac: 0x002233445566,
ips: vec![IpSubnet {
Expand Down
1 change: 1 addition & 0 deletions agent/src/trident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ impl AgentComponents {
user_config.get_fast_path_map_size(candidate_config.dispatcher.max_memory),
user_config.processors.packet.policy.forward_table_capacity,
user_config.processors.packet.policy.fast_path_disabled,
candidate_config.capture_mode == PacketCaptureType::Analyzer,
);
synchronizer.add_flow_acl_listener(Box::new(policy_setter));
policy_setter.set_memory_limit(max_memory);
Expand Down
Loading