parse_bracketed_active_policy

Function parse_bracketed_active_policy 

Source
pub fn parse_bracketed_active_policy(s: &str) -> Option<&str>
Expand description

Extract the bracketed active policy from a kernel mm menu-style string such as "always [madvise] never" (THP enabled) or "always defer defer+madvise [madvise] never" (THP defrag). Returns the content between the first [ and first subsequent ], or None if either bracket is missing.

First-bracket-wins: if the string contains multiple [..] pairs (e.g. a hand-written test fixture or a malformed sysfs read), only the FIRST pair is returned; later pairs are ignored. The kernel emits exactly one bracketed token in practice — this scanner exists to decode that canonical shape, not to validate arbitrary input.

Exposed as a pure helper so downstream tooling that wants the active policy (not the full menu) does not have to re-implement the bracket scan. The raw field is kept on HostContext for consumers that want the menu; HostContext::thp_enabled_active and HostContext::thp_defrag_active route through this helper.