From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E4571D90DF for ; Fri, 21 Nov 2025 02:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763693203; cv=none; b=r74dgVIepFhtyiiqoLGpF2+Nd4G0iTFQWM5+yjYHf1FI1CEIAwAFZV6aWKVl7mRuBWLA1hgM8EsZTL9olTCnn4os/JVzXPCczXLaFKttuq8sbDvS9I4a8qAbqIBystzZnBGFWp9nUI4Qp4lwbHft7J9w/m9upgLH1EB7HSPoUAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763693203; c=relaxed/simple; bh=9wRUpNCdJ+h3gNqDsWyecL8H/HjoIYfVBoT5t0mijps=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=fRZKd3a371++uNvD0O+26l8eS7HPtfT7kmscPCANxSEZPEEqWIRpNPX4+aBfxwf9SoWuyvvg+WN7XJ1qhSgBCLYFhsfcR3cr3CHLOxa6Xxo5CxzdYL8f+6EWPG9uw2AZS1jL7XFGU92r2RRZE5UoxmWC6gP2/QHTKHLTvHU1uCM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=RXKuJU/R; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="RXKuJU/R" Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763693196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0yYZn6QK5gg9APsMYldZKsKSIWjXDUkqOUS9S8IfOMQ=; b=RXKuJU/RA1cAjc1XUBHWdIB9doG2Wk814x1wLnldU/d0slv40i246MHbcPxCVv8Z7ah4GX tU01cPDa5Zxf/9up0Y0JiDZQe0KB46S33I1BVcb7IkEpeZNkoRR1xAhu/BizuIrlwYWvtW gpBi8k0becQydlkbV7NHMiRxNgU9NF0= Date: Fri, 21 Nov 2025 02:46:31 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: hui.zhu@linux.dev Message-ID: TLS-Required: No Subject: Re: [RFC PATCH 0/3] Memory Controller eBPF support To: "Michal Hocko" Cc: "Roman Gushchin" , "Andrew Morton" , "Johannes Weiner" , "Shakeel Butt" , "Muchun Song" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Martin KaFai Lau" , "Eduard Zingerman" , "Song Liu" , "Yonghong Song" , "John Fastabend" , "KP Singh" , "Stanislav Fomichev" , "Hao Luo" , "Jiri Olsa" , "Shuah Khan" , "Peter Zijlstra" , "Miguel Ojeda" , "Nathan Chancellor" , "Kees Cook" , "Tejun Heo" , "Jeff Xu" , mkoutny@suse.com, "Jan Hendrik Farr" , "Christian Brauner" , "Randy Dunlap" , "Brian Gerst" , "Masahiro Yamada" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, "Hui Zhu" In-Reply-To: References: <87ldk1mmk3.fsf@linux.dev> <895f996653b3385e72763d5b35ccd993b07c6125@linux.dev> X-Migadu-Flow: FLOW_OUT 2025=E5=B9=B411=E6=9C=8821=E6=97=A5 03:20, "Michal Hocko" =E5=86=99=E5=88=B0: >=20 >=20On Thu 20-11-25 09:29:52, hui.zhu@linux.dev wrote: > [...] >=20 >=20>=20 >=20> 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. > >=20=20 >=20> Hi Roman, > >=20=20 >=20> Following are some ideas that can use ebpf memcg: > >=20=20 >=20> Priority=E2=80=91Based Reclaim and Limits in Multi=E2=80=91Tenant = Environments: > > On a single machine with multiple tenants / namespaces / containers, > > under memory pressure it=E2=80=99s hard to decide =E2=80=9Cwho shoul= d be squeezed first=E2=80=9D > > with static policies baked into the kernel. > > Assign a BPF profile to each tenant=E2=80=99s memcg: > > Under high global pressure, BPF can decide: > > Which memcgs=E2=80=99 memory.high should be raised (delaying reclaim= ), > > Which memcgs should be scanned and reclaimed more aggressively. > >=20=20 >=20> Online Profiling / Diagnosing Memory Hotspots: > > A cgroup=E2=80=99s memory keeps growing, but without patching the ke= rnel it=E2=80=99s > > difficult to obtain fine=E2=80=91grained information. > > Attach BPF to the memcg charge/uncharge path: > > Record large allocations (greater than N KB) with call stacks and > > owning file/module, and send them to user space via a BPF ring buffe= r. > > Based on sampled data, generate: > > =E2=80=9CTop N memory allocation stacks in this container over the l= ast 10 minutes,=E2=80=9D > > Reports of which objects / call paths are growing fastest. > > This makes it possible to pinpoint the root cause of host memory > > anomalies without changing application code, which is very useful > > in operations/ops scenarios. > >=20=20 >=20> SLO=E2=80=91Driven Auto Throttling / Scale=E2=80=91In/Out Signals: > > Use eBPF to observe memory usage slope, frequent reclaim, > > or near=E2=80=91OOM behavior within a memcg. > > When it decides =E2=80=9COOM is imminent,=E2=80=9D instead of just k= illing/raising > > limits, it can emit a signal to a control=E2=80=91plane component. > > For example, send an event to a user=E2=80=91space agent to trigger > > automatic scaling, QPS adjustment, or throttling. > >=20=20 >=20> Prevent a cgroup from launching a large=E2=80=91scale fork+malloc = attack: > > BPF checks per=E2=80=91uid or per=E2=80=91cgroup allocation behavior= over the > > last few seconds during memcg charge. > >=20 >=20AFAIU, these are just very high level ideas rather than anything you = are > trying to target with this patch series, right? >=20 >=20All I can see is that you add a reclaim hook but it is not really cle= ar > to me how feasible it is to actually implement a real memory reclaim > strategy this way. >=20 >=20In prinicipal I am not really opposed but the memory reclaim process = is > rather involved process and I would really like to see there is > something real to be done without exporting all the MM code to BPF for > any practical use. Is there any POC out there? Hi Michal, I apologize for not delivering a more substantial POC. I was hesitant to add extensive eBPF support to memcg because I wasn't certain it aligned with the community's vision=E2=80=94and such support would require introducing many eBPF hooks into memcg. I will add more eBPF hook to memcg and provide a more meaningful POC in the next version. Best, Hui > --=20 >=20Michal Hocko > SUSE Labs >