Re: [LSF/MM/BPF TOPIC] Using BPF in MM

Yafang Shao
2026-04-29T02:44:10Z

On Tue, Apr 28, 2026 at 7:58 AM Roman Gushchin <roman.gushchin@linux.dev> wrote:
>
> [LSF/MM/BPF TOPIC] Using BPF in MM
> ----------------------------------
>
> Over the last decade, BPF successfully penetrated into multiple kernel
> subsystems: started as a feature to filter (out) networking packets,
> it captured its place in networking, tracing, security, HID drivers,
> and scheduling. Memory management is a logical next step, and recently
> we saw a growing number of proposals in this area.
>
> In (approximately) historical order:
> - BPF OOM
> - BPF-based memcg stats access (landed)
> - BPF-based NUMA balancing
> - eBPF-mm
> - cache_ext (BPF Page Cache)
> - memcg_ext
>
> There are some obvious target which haven't been covered yet:
> - BPF-driven readahead control
> - BPF-driven KSM
> - BPF-driven guest memory control
>
> Despite a large number of suggestions only a relatively small feature
> (query memcg statistics from BPF) made it to upstream.

We are exploring an alternative approach that leverages livepatch
combined with BPF to modularize struct_ops-based kernel hooks. This
allows us to deploy these hooks as out-of-tree modules without direct
kernel modification or the immediate need for upstreaming.

https://lore.kernel.org/live-patching/20260402092607.96430-1-laoar.shao@gmail.com/
https://lore.kernel.org/live-patching/20260416001628.2062468-1-song@kernel.org/
https://lore.kernel.org/bpf/CAPhsuW53pymgmFsHSkSwDvEAJ=+Rp2T102JYe4i9kgdePpR=6Q@mail.gmail.com/

In practice, we first introduce the BPF hooks via a livepatch and
subsequently attach BPF programs to them. Below is a recent use case
from our production environment (though not MM related) for reference:

https://lore.kernel.org/live-patching/CALOAHbDnNba_w_nWH3-S9GAXw0+VKuLTh1gy5hy9Yqgeo4C0iA@mail.gmail.com/

In one of our clusters, we needed to route BGP traffic through
specific NICs based on destination IP addresses. To achieve this
without service interruption, we applied a livepatch to
bond_xmit_3ad_xor_slave_get() to introduce a new hook,
bond_get_slave_hook(). We then attached a BPF program to this hook to
select the outgoing NIC by parsing the SKB. Because the destination
IPs must be adjusted on demand, a static livepatch alone was
insufficient; the BPF integration provided the necessary dynamic
flexibility.

To fully support this architecture, several work-in-progress
enhancements are being developed for both the livepatch and BPF
subsystems.

+Song, Petr (CC'd for their expertise in BPF and livepatch).

--
Regards
Yafang