OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Eva Kurchatova <eva.kurchatova@virtuozzo.com>, khorenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
Date: Thu, 12 Nov 2026 04:27:08 +0000	[thread overview]
Message-ID: <010701a1ce027069-198dbb38-bcd4-445d-a10a-0daa4450fc2b-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261112042325.399633-1-eva.kurchatova@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/cgroup: hog_cpus_timed() never calls pthread_attr_destroy()
--

commit 3e0ad2c93c22b3e844f853e154c385c491c1c5ca
Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>

selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned

This patch pins each hog thread in test_cpucg_weight_overprovisioned() to
one CPU. The threads of each cgroup are spread one per allowed CPU, so the
test checks the cgroup weights and not the load balancer's placement.

> diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
> --- a/tools/testing/selftests/cgroup/test_cpu.c
> +++ b/tools/testing/selftests/cgroup/test_cpu.c

[ ... ]

> @@ -136,7 +138,13 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
>  	struct timespec ts_run = param->ts;
>  	struct timespec ts_remaining = ts_run;
>  	struct timespec ts_start;
> -	int i, ret;
> +	pthread_attr_t attr;
> +	cpu_set_t cpus, one;
> +	int i, ret, cpu = -1;
> +	/* Unpinned, as before, where the mask does not fit in a cpu_set_t */
> +	bool pin = param->pin && !sched_getaffinity(0, sizeof(cpus), &cpus);
> +
> +	pthread_attr_init(&attr);

[Severity: Low]
Is the pthread_attr_t initialized here ever released?  hog_cpus_timed()
calls pthread_attr_init(&attr) unconditionally, but none of its exit paths
call pthread_attr_destroy(&attr).

This covers the final "return 0", the early return after a failed
pthread_attr_setaffinity_np(), the return after a failed pthread_create(),
and the clock_gettime()/nanosleep() failure returns.

With pin set, glibc's pthread_attr_setaffinity_np() allocates a copy of the
cpuset inside attr, and pthread_attr_destroy() is what frees it.

The return value of pthread_attr_init() is also not checked.

The impact is small, since hog_cpus_timed() runs in a short-lived child
forked by cg_run_nowait() and the memory is reclaimed on exit.  Would it be
worth adding a pthread_attr_destroy(&attr) on the exit paths?

> @@ -145,7 +153,18 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
>  	for (i = 0; i < param->nprocs; i++) {
>  		pthread_t tid;
>  
> -		ret = pthread_create(&tid, NULL, &hog_cpu_thread_func, NULL);
> +		/* One hog per allowed CPU, in turn */
> +		if (pin) {
> +			do {
> +				cpu = (cpu + 1) % CPU_SETSIZE;
> +			} while (!CPU_ISSET(cpu, &cpus));
> +			CPU_ZERO(&one);
> +			CPU_SET(cpu, &one);
> +			ret = pthread_attr_setaffinity_np(&attr, sizeof(one), &one);
> +			if (ret != 0)
> +				return ret;
> +		}
> +		ret = pthread_create(&tid, &attr, &hog_cpu_thread_func, NULL);
>  		if (ret != 0)
>  			return ret;
>  	}

[ ... ]

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112042325.399633-1-eva.kurchatova@virtuozzo.com?part=1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-12  4:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:23 Eva Kurchatova
2026-11-12  4:27 ` no-reply [this message]
2026-11-12 11:49 ` Konstantin Khorenko
2026-11-12 11:49 ` Konstantin Khorenko

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=010701a1ce027069-198dbb38-bcd4-445d-a10a-0daa4450fc2b-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=eva.kurchatova@virtuozzo.com \
    --cc=khorenko@virtuozzo.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