Hui Zhu hui.zhu@linux.dev writes:
From: Hui Zhu zhuhui@kylinos.cn
This series proposes adding eBPF support to the Linux memory controller, enabling dynamic and extensible memory management policies at runtime.
Background
The memory controller (memcg) currently provides fixed memory accounting and reclamation policies through static kernel code. This limits flexibility for specialized workloads and use cases that require custom memory management strategies.
By enabling eBPF programs to hook into key memory control operations, administrators can implement custom policies without recompiling the kernel, while maintaining the safety guarantees provided by the BPF verifier.
Use Cases
- Custom memory reclamation strategies for specialized workloads
- Dynamic memory pressure monitoring and telemetry
- Memory accounting adjustments based on runtime conditions
- Integration with container orchestration systems for intelligent resource management
- Research and experimentation with novel memory management algorithms
Design Overview
This series introduces:
A new BPF struct ops type (`memcg_ops`) that allows eBPF programs to implement custom behavior for memory charging operations.
A hook point in the `try_charge_memcg()` fast path that invokes registered eBPF programs to determine if custom memory management should be applied.
The eBPF handler can inspect memory cgroup context and optionally modify certain parameters (e.g., `nr_pages` for reclamation size).
A reference counting mechanism using `percpu_ref` to safely manage the lifecycle of registered eBPF struct ops instances.
Can you please describe how these hooks will be used in practice? What's the problem you can solve with it and can't without?
I generally agree with an idea to use BPF for various memcg-related policies, but I'm not sure how specific callbacks can be used in practice.
Thanks!