From nobody Sun Feb 8 14:10:11 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 8B32028851E for ; Sat, 20 Dec 2025 04:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766204016; cv=none; b=F2kUxHMrgOHYvNdv+APVkXqHxSQ5OaoRdAVB+lwk885xZcWQe6999J1k6rB2sfMwQvcfWSIeTUhMngp5FGpF0O5DRLil68fbnmGyGWAzjC+cWVWdu1991doPv2q+x1Q+1MQGLxu/yaz/Zp1X8JSptjeuJVP8k8mL+X9DuMxwuCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766204016; c=relaxed/simple; bh=sHPsyNlGwapdtwFXeCRG6V1BkpgFoTlWyZIFQZMiBxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XmdaCX4p7ali7b5Q5P6zd9UH2AVinLpD4LP9ICeCqGaC8lfKpegrMJ+NQ75foyRqBSZ7BuDm2bYOuVh3tJDVgIe1xI5q4HvFugBVzSLJR4eUx6DM/Tdu5BN5n77Y7ngf1kLsixU/4NYCLIAXa6vI4gkLM9oEX/xh+aGl4iNHqMo= 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=M/9+lxqK; arc=none smtp.client-ip=91.218.175.188 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="M/9+lxqK" 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=1766204008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7evlJ586VgwqQZOIWkPuRy5AVJIYePbARo3wNs1uXHA=; b=M/9+lxqKjAkS2Whu6IcPHOC6uS+J6BOmEpuqgYioua9snBxaNXqlLZhjaWCnuzS2je4zrx ZHUdxUP8dKpFKRqfiaEjLrl7Rmc0Hd0JYC94Ckw80fDzWFSWtbsI4oBICkByRMErctY2lJ ND+aF6yGAOrYSKaC92M0A4oGHt89zCs= From: Roman Gushchin To: bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: JP Kobryn , Alexei Starovoitov , Daniel Borkmann , Shakeel Butt , Michal Hocko , Johannes Weiner , Roman Gushchin Subject: [PATCH bpf-next v2 5/7] mm: introduce BPF kfunc to access memory events Date: Fri, 19 Dec 2025 20:12:48 -0800 Message-ID: <20251220041250.372179-6-roman.gushchin@linux.dev> In-Reply-To: <20251220041250.372179-1-roman.gushchin@linux.dev> References: <20251220041250.372179-1-roman.gushchin@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: JP Kobryn Introduce BPF kfunc to access memory events, e.g.: MEMCG_LOW, MEMCG_MAX, MEMCG_OOM, MEMCG_OOM_KILL etc. Signed-off-by: JP Kobryn Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/bpf_memcontrol.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c index d84fe6f3ed43..858eb43766ce 100644 --- a/mm/bpf_memcontrol.c +++ b/mm/bpf_memcontrol.c @@ -103,6 +103,22 @@ __bpf_kfunc unsigned long bpf_mem_cgroup_usage(struct = mem_cgroup *memcg) return mem_cgroup_usage(memcg, false) * PAGE_SIZE; } =20 +/** + * bpf_mem_cgroup_memory_events - Read memory cgroup's memory event value + * @memcg: memory cgroup + * @event: memory event id + * + * Returns current memory event count. + */ +__bpf_kfunc unsigned long bpf_mem_cgroup_memory_events(struct mem_cgroup *= memcg, + enum memcg_memory_event event) +{ + if (event >=3D MEMCG_NR_MEMORY_EVENTS) + return (unsigned long)-1; + + return atomic_long_read(&memcg->memory_events[event]); +} + /** * bpf_mem_cgroup_page_state - Read memory cgroup's page state counter * @memcg: memory cgroup @@ -137,6 +153,7 @@ BTF_ID_FLAGS(func, bpf_get_mem_cgroup, KF_TRUSTED_ARGS = | KF_ACQUIRE | KF_RET_NUL BTF_ID_FLAGS(func, bpf_put_mem_cgroup, KF_TRUSTED_ARGS | KF_RELEASE) =20 BTF_ID_FLAGS(func, bpf_mem_cgroup_vm_events, KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_mem_cgroup_memory_events, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_mem_cgroup_usage, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_mem_cgroup_page_state, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_mem_cgroup_flush_stats, KF_TRUSTED_ARGS | KF_SLEEPA= BLE) --=20 2.52.0