From: Tao Cui <cui.tao@linux.dev>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: cui.tao@linux.dev, Tejun Heo <tj@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Suren Baghdasaryan <surenb@google.com>,
Shuah Khan <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Ziyang Men <ziyang.meme@gmail.com>,
Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH v2] selftests/cgroup: add PSI pressure trigger and validation tests
Date: Mon, 10 Aug 2026 17:42:38 +0800 [thread overview]
Message-ID: <53467765-7ffa-4da4-9473-2ea770048f96@linux.dev> (raw)
In-Reply-To: <anS3saMkFog89yxy@localhost.localdomain>
Hi Michal,
在 2026/8/7 00:52, Michal Koutný 写道:
> Hi,
> thanks for continuing with this.
>
Thanks -- though honestly I owe you the thanks. Your v1 review is what
got me to drop the memory-pressure approach and churn_memory(), and to
keep the runner out of the cgroup. v2 basically exists because you took
the time on v1. Still only my second selftests patch, so still feeling
my way around the conventions here (clearly -- see below).
> On Tue, Jul 28, 2026 at 04:37:42PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
>> +/* Trigger smoke test: second on same fd -> EBUSY; IRQ rejects "some". */
>> +static int test_proc_triggers(const char *root)
>> +{
>> + static const char *const resources[] = { "io", "memory", "cpu" };
>> + int ret = KSFT_FAIL;
>> + int fd = -1;
>> + int i;
>> +
>> + (void)root;
>
> WTH?
>
Yeah, bogus. Dropping the param entirely; details in my reply to Suren.
>> +
>> + for (i = 0; i < (int)ARRAY_SIZE(resources); i++) {
>
> This (int) cast is quite uncommon, look around.
>
Dropping it, size_t loop var.
>> +/* Induce deterministic CPU pressure (more hogs than CPUs). */
>> +static int test_cgroup_trigger_fire(const char *root)
>> +{
>> + char *cg = NULL, *cpupress = NULL;
>> + int fd = -1, ret = KSFT_FAIL;
>> + struct pollfd pfd;
>> + long ncpus, i;
>> + pid_t pid;
>> +
>> + cg = cg_name(root, "psi_trigger_test");
>> + if (!cg)
>> + goto cleanup;
>> + if (cg_create(cg))
>> + goto cleanup;
>> +
>> + cpupress = cg_control(cg, "cpu.pressure");
>> + if (!cpupress)
>> + goto cleanup;
>> + fd = open(cpupress, O_RDWR);
>> + if (fd < 0) {
>> + ksft_print_msg("open cpu.pressure: %s\n", strerror(errno));
>> + goto cleanup;
>> + }
>> +
>> + /* 1us threshold in a 1s window: any cpu stall fires it. */
>> + errno = 0;
>> + if (write_trigger(fd, "some 1 1000000") <= 0) {
>> + ksft_print_msg("arming trigger failed: %s\n", strerror(errno));
>> + goto cleanup;
>> + }
>
> When I see this, could you increase the window size to 2000000 (so that
> it has potential to run for unprivileged users)?
>
Yes, "some 1 2000000".
>> +
>> + ncpus = sysconf(_SC_NPROCESSORS_ONLN);
>> + if (ncpus <= 0)
>> + ncpus = 1;
>> +
>> + pid = fork();
>> + if (pid < 0) {
>> + ksft_print_msg("fork: %s\n", strerror(errno));
>> + goto cleanup;
>> + }
>> + if (pid == 0) {
>> + /* Enter the cgroup, then over-subscribe it with CPU hogs. */
>> + if (cg_enter_current(cg))
>> + _exit(KSFT_FAIL);
>> + for (i = 0; i < ncpus; i++) {
>> + if (fork() == 0) {
>> + for (;;)
>> + asm volatile("" ::: "memory");
>> + _exit(0);
>> + }
>> + }
>> + for (;;)
>> + asm volatile("" ::: "memory"); /* child is also a hog */
>> + _exit(0);
>> + }
>
> This part could be replaced with generalized hog_cpus_timed() from
> test_cpu.c (after move to cgroup_util.c).
>
Agreed it shouldn't be open-coded. One snag though: hog_cpus_timed()
runs for a fixed duration and returns, but here I want hogs that keep
running until the trigger fires and then get killed. So I'll move a
shared helper into cgroup_util.[ch] and call it from both spots, rather
than using hog_cpus_timed() as-is.
>> +int main(int argc, char **argv)
>> +{
>> + char root[PATH_MAX];
>> + int mempress_fd;
>> + int i;
>> +
>> + (void)argc;
>
> What's up with this?
>
Leftover, removed.
>> +
>> + ksft_print_header();
>> + ksft_set_plan(ARRAY_SIZE(tests));
>> +
>> + if (cg_find_unified_root(root, sizeof(root), NULL))
>> + ksft_exit_skip("cgroup v2 isn't mounted\n");
>> +
>> + /* PSI must be enabled (CONFIG_PSI=y, not default-disabled). */
>> + mempress_fd = open("/proc/pressure/memory", O_RDONLY);
>> + if (mempress_fd < 0)
>> + ksft_exit_skip("PSI unavailable (CONFIG_PSI=n or psi=0)\n");
>> + close(mempress_fd);
>> +
>> + if (cg_read_strstr(root, "cgroup.controllers", "memory"))
>> + ksft_exit_skip("memory controller isn't available\n");
>> + if (cg_read_strstr(root, "cgroup.subtree_control", "memory"))
>> + if (cg_write(root, "cgroup.subtree_control", "+memory"))
>> + ksft_exit_skip("failed to enable memory controller\n");
>
> The memory controller is unnecessary now, right?
>
Right. v1 leftover, CPU pressure now, so that setup is dead code.
Dropping it.
I'll fold all of this into v3.
Thanks,
Tao
>
> Regards,
> Michal
next prev parent reply other threads:[~2026-08-10 9:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 8:37 [PATCH v2] selftests/cgroup: add PSI pressure trigger and validation tests Tao Cui
2026-08-06 16:52 ` Michal Koutný
2026-08-06 17:12 ` Suren Baghdasaryan
2026-08-10 9:42 ` Tao Cui [this message]
2026-08-09 3:44 ` Suren Baghdasaryan
2026-08-10 9:22 ` Tao Cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53467765-7ffa-4da4-9473-2ea770048f96@linux.dev \
--to=cui.tao@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=cuitao@kylinos.cn \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=ziyang.meme@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox