From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 02F5813D891 for ; Mon, 26 Jan 2026 01:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769391621; cv=none; b=AZlodFeNpvtdjM0r22okDmKhPI//t5JPOhGcIQRQgCOL9YK3IZ1jlGYw3eNSUwtqTuSPBlb79aWMsXH4hAOmRCywkSLINLshVad85+KuFYfG85PKKoYQcp4otzfLveIs4z0PSQ9LZOPz9YMD34IMMTa9MHCKERSpE6PCXGY1qiw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769391621; c=relaxed/simple; bh=st4oG32XzB15pUzcYQ7SBJEdkYV85I4fNj6S9F09L7I=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=pXIfvkdL5HBOclsI3z8tKhNq/3JqCKalfGC+izFZvw2P7JOZD6LqeaVnhHjynaCdaueO4kXoWYgxJeUGHM6ukEpIfh1RTSQyHXUCsSrFnCyvhdz44tsOlMQTm84upBZrXSFsVvkXcZK7NaOudU/Od3ikhNOlY82NdMEx0yjeFYM= 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=JtIvEjky; arc=none smtp.client-ip=91.218.175.177 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="JtIvEjky" Precedence: bulk X-Mailing-List: netdev@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=1769391617; 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=qOS/I3qY1vByTUV0rzQTBMazz/yNAmJFWVeZH3R10+Y=; b=JtIvEjkyz6fJcB1qcAm9UeGr45TrQiuC4U97SwoSQWERAEd26ARBHVe7+Pw+4xl7KifCNB 9NYXe7CylOwE4gcUYajwfyysJZAzkYijiu3765UOhj/R84ibbkDA0AHNiazLN02H6fY7JY Q2NWiGJKpBl1suunAWTwKhLgjyy1ZxU= Date: Mon, 26 Jan 2026 01:40:13 +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: <8ee851c5676facd43c45cdd5d434d92d85628e43@linux.dev> TLS-Required: No Subject: Re: [RFC PATCH bpf-next v3 09/12] selftests/bpf: Add tests for memcg_bpf_ops To: "JP Kobryn" , "Andrew Morton" , "Johannes Weiner" , "Michal Hocko" , "Roman Gushchin" , "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" , davem@davemloft.net, "Jakub Kicinski" , "Jesper Dangaard Brouer" , "Willem de Bruijn" , "Jason Xing" , "Paul Chaignon" , "Anton Protopopov" , "Amery Hung" , "Chen Ridong" , "Lance Yang" , "Jiayuan Chen" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: "Hui Zhu" , "Geliang Tang" In-Reply-To: References: X-Migadu-Flow: FLOW_OUT 2026=E5=B9=B41=E6=9C=8824=E6=97=A5 04:47, "JP Kobryn" =E5=86=99=E5=88=B0: >=20 >=20Hi Hui, >=20 >=20On 1/23/26 1:00 AM, Hui Zhu wrote: >=20 >=20>=20 >=20> From: Hui Zhu > > Add a comprehensive selftest suite for the `memcg_bpf_ops` > > functionality. These tests validate that BPF programs can correctly > > influence memory cgroup throttling behavior by implementing the new > > hooks. > > The test suite is added in `prog_tests/memcg_ops.c` and covers > > several key scenarios: > > 1. `test_memcg_ops_over_high`: > > Verifies that a BPF program can trigger throttling on a low-priority > > cgroup by returning a delay from the `get_high_delay_ms` hook when a > > high-priority cgroup is under pressure. > > 2. `test_memcg_ops_below_low_over_high`: > > Tests the combination of the `below_low` and `get_high_delay_ms` > > hooks, ensuring they work together as expected. > > 3. `test_memcg_ops_below_min_over_high`: > > Validates the interaction between the `below_min` and > > `get_high_delay_ms` hooks. > > The test framework sets up a cgroup hierarchy with high and low > > priority groups, attaches BPF programs, runs memory-intensive > > workloads, and asserts that the observed throttling (measured by > > workload execution time) matches expectations. > > The BPF program (`progs/memcg_ops.c`) uses a tracepoint on > > `memcg:count_memcg_events` (specifically PGFAULT) to detect memory > > pressure and trigger the appropriate hooks in response. This test > > suite provides essential validation for the new memory control > > mechanisms. > > Signed-off-by: Geliang Tang > > Signed-off-by: Hui Zhu > > --- > >=20 >=20[..] >=20 >=20>=20 >=20> diff --git a/tools/testing/selftests/bpf/prog_tests/memcg_ops.c b/t= ools/testing/selftests/bpf/prog_tests/memcg_ops.c > > new file mode 100644 > > index 000000000000..9a8d16296f2d > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/memcg_ops.c > > @@ -0,0 +1,537 @@ > >=20 >=20[..] >=20 >=20>=20 >=20> + > > +static void > > +real_test_memcg_ops_child_work(const char *cgroup_path, > > + char *data_filename, > > + char *time_filename, > > + int read_times) > > +{ > > + struct timeval start, end; > > + double elapsed; > > + FILE *fp; > > + > > + if (!ASSERT_OK(join_parent_cgroup(cgroup_path), "join_parent_cgrou= p")) > > + goto out; > > + > > + if (env.verbosity >=3D VERBOSE_NORMAL) > > + printf("%s %d begin\n", __func__, getpid()); > > + > > + gettimeofday(&start, NULL); > > + > > + if (!ASSERT_OK(write_file(data_filename), "write_file")) > > + goto out; > > + > > + if (env.verbosity >=3D VERBOSE_NORMAL) > > + printf("%s %d write_file done\n", __func__, getpid()); > > + > > + if (!ASSERT_OK(read_file(data_filename, read_times), "read_file")) > > + goto out; > > + > > + gettimeofday(&end, NULL); > > + > > + elapsed =3D (end.tv_sec - start.tv_sec) + > > + (end.tv_usec - start.tv_usec) / 1000000.0; > > + > > + if (env.verbosity >=3D VERBOSE_NORMAL) > > + printf("%s %d end %.6f\n", __func__, getpid(), elapsed); > > + > > + fp =3D fopen(time_filename, "w"); > > + if (!ASSERT_OK_PTR(fp, "fopen")) > > + goto out; > > + fprintf(fp, "%.6f", elapsed); > > + fclose(fp); > > + > > +out: > > + exit(0); > > +} > > + > >=20 >=20[..] >=20 >=20>=20 >=20> +static void real_test_memcg_ops(int read_times) > > +{ > > + int ret; > > + char data_file1[] =3D "/tmp/test_data_XXXXXX"; > > + char data_file2[] =3D "/tmp/test_data_XXXXXX"; > > + char time_file1[] =3D "/tmp/test_time_XXXXXX"; > > + char time_file2[] =3D "/tmp/test_time_XXXXXX"; > > + pid_t pid1, pid2; > > + double time1, time2; > > + > > + ret =3D mkstemp(data_file1); > > + if (!ASSERT_GT(ret, 0, "mkstemp")) > > + return; > > + close(ret); > > + ret =3D mkstemp(data_file2); > > + if (!ASSERT_GT(ret, 0, "mkstemp")) > > + goto cleanup_data_file1; > > + close(ret); > > + ret =3D mkstemp(time_file1); > > + if (!ASSERT_GT(ret, 0, "mkstemp")) > > + goto cleanup_data_file2; > > + close(ret); > > + ret =3D mkstemp(time_file2); > > + if (!ASSERT_GT(ret, 0, "mkstemp")) > > + goto cleanup_time_file1; > > + close(ret); > > + > > + pid1 =3D fork(); > > + if (!ASSERT_GE(pid1, 0, "fork")) > > + goto cleanup; > > + if (pid1 =3D=3D 0) > > + real_test_memcg_ops_child_work(CG_LOW_DIR, > > + data_file1, > > + time_file1, > > + read_times); > >=20 >=20Would it be better to call exit() after real_test_memcg_ops_child_wor= k() > instead of within it? This way the fork/exit/wait logic is contained in > the same scope making the lifetimes easier to track. I had to go back > and search for the call to exit() since at a glance this function > appears to proceed to call fork() and waitpid() from within both parent > and child procs (though it really does not). > I will fix it. Best, Hui