From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.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 CF3CD2F7449 for ; Thu, 20 Nov 2025 03:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763607912; cv=none; b=Eb5hLmf4v+KqTnCSSzUYlb2e/+pv/IyHCxMeGo4UjWZsMYfuh2kkzhxxWagsce8C6pp4uz9afxWxDICP2trRHOZFGyJ+QbRZczIyZdxJbyI3+gzRPCtEWOH6YzuafQB2BxkpzUo6Uxydm1XFr8pO8YyS+2apqrY5QLR97vitsrc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763607912; c=relaxed/simple; bh=uPYbHox/+V283sb8om2P37+Ret4HbJlps5xc8E1rk6o=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=I8VqdVEAtHAr4C/AQU+FgBAkN8a/dLPb30IN5KGiWAuSmhClytInNvlQXuNyAljTBCnjmwxYcSgr57sMJvBTe1yOKYURBU3MRa8r6a4362Wbc4kdMzTLDIvI4Y54z07imBdBVoolsBwgXB7D+nL1TNsB5u1TiuLrWFF3CVElzaU= 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=gmTMIGEy; arc=none smtp.client-ip=91.218.175.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="gmTMIGEy" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763607897; 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: in-reply-to:in-reply-to:references:references; bh=mp9GsOxlS5mfbOTt7JkQadj8FOcXU3nLzOqalaTK7J8=; b=gmTMIGEy3i6I93R2sPQbtMUa79JbcV5wpW+rsn0T1+//CcMXZPMpTsNMKh0WgfL2rmzhgq ADk90CoVVwjbe3RjNiViIqT8mC2EN5Jomd5GyIkHb+plaECxd3MqAnCY1lrWF0ponxW9M7 l2DfKVoplZebUgVFAX6ZaGNYgOU5h80= From: Roman Gushchin To: Hui Zhu Cc: Andrew Morton , Johannes Weiner , Michal Hocko , 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 Subject: Re: [RFC PATCH 0/3] Memory Controller eBPF support In-Reply-To: (Hui Zhu's message of "Wed, 19 Nov 2025 09:34:05 +0800") References: Date: Wed, 19 Nov 2025 19:04:44 -0800 Message-ID: <87ldk1mmk3.fsf@linux.dev> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Hui Zhu writes: > From: Hui Zhu > > 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 > > 1. Custom memory reclamation strategies for specialized workloads > 2. Dynamic memory pressure monitoring and telemetry > 3. Memory accounting adjustments based on runtime conditions > 4. Integration with container orchestration systems for > intelligent resource management > 5. Research and experimentation with novel memory management > algorithms > > Design Overview > > This series introduces: > > 1. A new BPF struct ops type (`memcg_ops`) that allows eBPF > programs to implement custom behavior for memory charging > operations. > > 2. A hook point in the `try_charge_memcg()` fast path that > invokes registered eBPF programs to determine if custom > memory management should be applied. > > 3. The eBPF handler can inspect memory cgroup context and > optionally modify certain parameters (e.g., `nr_pages` for > reclamation size). > > 4. 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!