On 8/13/25 1:53 PM, Shakeel Butt wrote:
What I think is the right approach is to have BPF struct ops based
approach with possible callback 'is this socket under pressure' or maybe
'is this socket isolated' and then you can do whatever you want in those
callbacks. In this way your can follow the same approach of caching the
result in kernel (lower bits of sk->sk_memcg).
I am CCing bpf list to get some suggestions or concerns on this
approach.
I have quickly looked at the set. In patch 11, it sets a bit in sk->sk_memcg.
On the bpf side, there are already cgroup bpf progs that can do bpf_setsockopt
on a sk, so the same can be done here. The bpf_setsockopt does not have to set
option/knob that is only available in the uapi in case we don't want to expose
this to the user space.
The cgroup bpf prog (BPF_CGROUP_INET_SOCK_CREATE) can already be run when a
"inet" sock is created. This hook (i.e. attach_type) does not have access to
bpf_setsockopt but should be easy to add.
For more comprehensive mem charge policy that needs new bpf hook, that probably
will need struct_ops instead of another cgroup attach_type but that will be
implementation details.