🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7814

[RFC PATCH 0/2] memcg_ext: dynamic memory.low and memory.min protection

#7814
From: Hui Zhu
Date: Tue, 27 Oct 2026 09:11
57 lines
10776 bytes
From: Hui Zhu <zhuhui@kylinos.cn>

This follows the memcg_ext RFC [1], which adds bpf_memcg_ops - a
struct_ops type attaching memory controller policy to a cgroup - and
one member, high_policy().  Its cover letter names dynamic protection
as future work; these two patches are that.

Why it matters: memory.low and memory.min protect a cgroup by a fixed
threshold and have no idea whether it is using the memory.  A
high-priority cgroup that holds a large working set and then goes idle
keeps suppressing reclaim on its siblings, and that memory is wasted.
A policy program sees the real activity - page faults, charges - and
can grant or withdraw protection as it changes.

The hooks are not new: [2] proposed the same below-low and below-min
decision on its own memcg_bpf_ops type.  Only the carrier changes
here.  bpf_memcg_ops already supplies attach, the ancestor walk,
result combination and the re-entry guard, so protection costs two
members and one walk helper shared with high_policy().

Patch 1 adds low_policy() and min_policy().  A program gets a
read-only snapshot of the check the kernel is making - the memcg, the
reclaim target, the threshold and the usage - and returns a request;
BPF_MEMCG_PROT_BELOW, the only one so far, treats the cgroup as below
its threshold, so reclaim skips it and counts it in memory.events.
The kernel compares elow/emin first and asks BPF only when it found
the cgroup unprotected, and ORs the answers of the cgroup and every
ancestor, so a policy can only add protection, never take it away.

Patch 2 is the prog_tests runner: attach both policies to a child,
fault 8M of anonymous memory into it, reclaim from its parent, and
check that both hooks were consulted and that the ctx described the
check faithfully.  Both answer NO_OPINION, so nothing about reclaim's
outcome is asserted.  A working example that does answer BELOW, so
reclaim skips one cgroup and takes the memory from a sibling instead,
is maintained out of tree at [3], released under GPLv2.

[1] https://lore.kernel.org/all/20260921192559.2619635-1-shakeel.butt@linux.dev/
[2] https://lore.kernel.org/all/cover.1779760876.git.zhuhui@kylinos.cn/
[3] https://github.com/teawater/memcg-async-reclaim/tree/memcg_ext_plus

Hui Zhu (2):
  memcg_ext: add memory.low and memory.min protection policies
  selftests/bpf: Add bpf_memcg_ops protection test

 include/linux/bpf_memcontrol.h                | 104 ++++++++++-
 include/linux/memcontrol.h                    |  23 ++-
 mm/bpf_memcontrol.c                           | 162 ++++++++++++++----
 .../bpf/prog_tests/memcg_ops_protection.c     | 151 ++++++++++++++++
 .../bpf/progs/memcg_ops_protection.c          |  72 ++++++++
 5 files changed, 470 insertions(+), 42 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/memcg_ops_protection.c
 create mode 100644 tools/testing/selftests/bpf/progs/memcg_ops_protection.c

-- 
2.43.0
Technical Details
Message-ID: <cover.1793086858.git.zhuhui@kylinos.cn>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352315-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352315-linux-kernel-netdev=dewy.ru
From: hui.zhu@linux.dev (Hui Zhu)
Newsgroups: linux.kernel.netdev
Subject: [RFC PATCH 0/2] memcg_ext: dynamic memory.low and memory.min protection
Date: Tue, 27 Oct 2026 17:11:58 +0800
Organization: Usenet Network
Message-ID: <cover.1793086858.git.zhuhui@kylinos.cn>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1500864"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Ih0n8FcH57vJ8YYmUIk4EtfbU8c= sha256:l0AWxVGiYgh8zWu/dt4Co6BYzI9P/2Sd5mR2oX6v0AA=
	sha1:CqX/oS1Z0FC6IKigqZpltx45Zk0= sha256:lyMLtp+mmEs58R9tNSaPj6A7wdvKg2j9hEsBviNjgVk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 869A0125BDE; Tue, 27 Oct 2026 12:17:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Fo_XgEhbXRJp;
	Tue, 27 Oct 2026 12:17:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352315-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 6CCE8125BE4; Tue, 27 Oct 2026 12:16:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 319E32E1D4; Tue, 27 Oct 2026 09:12:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793092358;
	b=T4ZtKDVF3T+N/FS+JHfZX1XUQcfxdNLurKvXkCsui8V2756LMe0p8RXvv425IY7NEFz9
	 HBawMrOHbxPVoXJ+otmU7fV8IUxcyfyP85tcQpGRmtkYN3f2OTfqf9sTL95haZgmgu3eL
	 dM957EFQkUP0mfiXZQe8v3vFGzSR/nOMhjl5bu5BHZqG/ikYDUworMwpl2rMNnzoPx/GT
	 HsBCUN+ZbbOEEM0BekyCHqtxK+BsYQUCOewzbLIcbCPTuiCsuw84Cwo2oBz4oJ8kA5nEn
	 qjD6l5cRIGyi5CGJ80MdIdWeY1cxk4RQmn8mR6wv8inY+QS6Yg3ojSVXQjORlY8yqVA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092358;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=Ndi2448wVUZuF68kqWF0v2z9NaMIBNKc9nVCJQzYI1k=;
	b=c+W4TDvAXT2OVs7azpcwfE/NcQX0pxfTrw3DjAeCMir/p3/jc1t2Gk7kFAxEO/nuyGD5
	 sTjRz+zH6ImL4tPqApsm1WKzDhvIYZwx8gMdfvcCo2nbiRo7jMSfcEM7Sly8oJm5HMOdG
	 s26INlU2CHGPWqZorHd+5Hitu8iFNzXsLupdGW59FlmLTfUE47hievHd+CV4+I4mtr0pI
	 QNWG4fIb/Ru7jbnMs3KWCrtzz0zqrIVbWqQ6XKK+cNrARXfd6GmSQWTaFgTpcdbqy7Pnv
	 EctDhgt4M25AsvviliWW05nY3BFGY1FuavPleJMP+yoYR1T0u+Kqs7tb4E4/HK8bGuA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="bA2/gm+I";
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 08A68606A329;
	Tue, 27 Oct 2026 09:12:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=bA2/gm+I
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.174
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793092357;
	b=pvyUAg4BSU29xoylbSY1JZqUFIjPAqOcoz0WIirWLaVcV4IX54lHYGRgH1YesDvW/a3B
	 R3KWDq3n0amW8nov9lXCwDFRTr/jAfZ6bNJlpgOVBRStgIn/SmdGRn7v6m6WrpRcYBzPS
	 7Xd7q7R3IzBUGvBRKXQCPIk9nUKtUMpULvwF96tpmf9mYqSyFE6wvPStUFlta1qRlsg/O
	 QQsejxEAHTP5VXOBQ01hQbAQleclJd0lNagbtmXpv+T9e5EjNiRCBvRryP4ocWbK9nHsO
	 pNucmuK6nfpTEtIx34KGgaTYLzHd84tJuhC7gT/AP4kXfVntwRMOlhiPeKSTau8piog==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092357;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=Ndi2448wVUZuF68kqWF0v2z9NaMIBNKc9nVCJQzYI1k=;
	b=ZxlHPFXavD+XBlbjPPD3v8dCnfdcvxFzR7Pm3Gh0syG/FYPbomndENR9lccSL7JEi7uo
	 6LWgmpEXthb2TAOUMRrHvnTmeOyxDndUwSHDLyFCFFHg2IYgPL/RWuFjvDVVhgF+og4Mv
	 suB4O6JL7+z5Z/4pu+acg/w/KbuElWFc4cJafCGYvw2dvgDtXpKT0Wj4Cr/ZCMY5X/jOL
	 80cWw7E7ytOBAC9PieIls83tdZ0NJpTWSdb6xE0V19yXywGE1cnHl+mfc2bnLvupgYFPk
	 JVswZQMRs4ztVDMvT3Gze30vTEqfdOAjUjktei/oFW0ZXo6L4noL2O8KH4gzZLPb8sA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="bA2/gm+I";
	arc=none smtp.remote-ip=91.218.175.174
X-Received: from mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BCF9606A31E
	for <netdev@vger.kernel.org>; Tue, 27 Oct 2026 09:12:29 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2BCF9606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=Iy2EZRXCQMOBxljPF+GT6qR9TSW/M2vcb/khwUxJInc=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793092348; v=1; x=1793697148;
 b=bA2/gm+InVPxrA8/cUeuKfkv9tlw8WkJfCJkOBEDJtQCHB0HWSave9Iz76npyrcxJMqpPc1t
 uCc6jbvmBvAjzUUwt9MB4DHn/lLKKxWsS6jwJ3eh4ZlxhovExca29l8pVbWHLXsWABOthurUun7
 yDoOp3aXMoQ0FUfbTaxkhPds=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta11.migadu.com with ESMTPS id e68cbb451e1e33a5;
	Tue, 27 Oct 2026 09:12:27 +0000
X-Mizu-Trace-ID: e68cbb451e1e33a5
X-Migadu-Flow: FLOW_OUT
X-Cc: Hui Zhu <zhuhui@kylinos.cn>
X-Mailer: git-send-email 2.43.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list