OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org, Sashiko <no-reply@sashiko.virtuozzo.com>
Subject: [Devel] [PATCH hci-8.1 v5 0/2] sched: Fix incorrect nproc report inside CT
Date: Thu, 19 Nov 2026 10:54:01 +0100	[thread overview]
Message-ID: <20261119-ct-invalid-nrpoc-v5-0-ff22216f458b@virtuozzo.com> (raw)

We observed weird nproc behavior - it reported 64 CPUs
no matter what the CT limits were or how many CPUs the host
actually had.

nproc code uses sched_getaffinity syscall under the hood[1].
It appears that this syscall returned complete nonsence when
called from VE - we ignored both num_online_vcpus and
cgroup cpuset limitations.

Now it is fixed and a new selftest is added.

[1]: https://github.com/coreutils/gnulib/blob/master/lib/nproc.c#L144
https://virtuozzo.atlassian.net/browse/VSTOR-141682

Signed-off-by: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
---
Changes in v5:
- Patch 2: fixed incorrect byte size passed to sched_getaffinity,
  added check for root and removed extra line.
- Link to v4: http://lore.virtuozzo.com/20261118-ct-invalid-nrpoc-v4-0-30baaeda3f87@virtuozzo.com

Changes in v4:
- Patch 1: updated comment about setaffinity and commit mesage.
- Patch 2: added include and used CPU_SETSIZE.
- Link to v3: http://lore.virtuozzo.com/20261029-ct-invalid-nrpoc-v3-0-89d4b0b7d520@virtuozzo.com

Changes in v3:
- Patch 1: num_online_vcpus() -> task_nr_cpus(p)
- Patch 2: updated a comment and moved CPU check in setup fixture to the top.
- Link to v2: http://lore.virtuozzo.com/20261028-ct-invalid-nrpoc-v2-0-968fe985ce27@virtuozzo.com

Changes in v2:
- Updated vCPU logic in patch 1. Now we don't return actual
  cpumask, insted first min(vcpu, count(mask)) bits are set.
  This is closer to the real CT resources.
- Patch 2: adjusted logic and added one more test.
- Link to v1: http://lore.virtuozzo.com/20261027-ct-invalid-nrpoc-v1-0-48727c3afe16@virtuozzo.com

---
Vladimir Riabchun (2):
      sched: Fix sched_getaffinity syscall
      selftests: ve: Test sched_getaffinity in VE

 kernel/sched/syscalls.c                            |  18 +-
 tools/testing/selftests/ve/.gitignore              |   1 +
 tools/testing/selftests/ve/Makefile                |   1 +
 .../selftests/ve/ve_sched_getaffinity_test.c       | 214 +++++++++++++++++++++
 4 files changed, 229 insertions(+), 5 deletions(-)
---
base-commit: d816dd0e4cdc45208ba0c488d295c5b2f943e079
change-id: 20261027-ct-invalid-nrpoc-f183b3ba691d

Best regards,
--  
Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>

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

             reply	other threads:[~2026-11-19  9:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:54 Vladimir Riabchun [this message]
2026-11-19  9:54 ` [Devel] [PATCH hci-8.1 v5 1/2] sched: Fix sched_getaffinity syscall Vladimir Riabchun
2026-11-19 17:32   ` Konstantin Khorenko
2026-11-19  9:54 ` [Devel] [PATCH hci-8.1 v5 2/2] selftests: ve: Test sched_getaffinity in VE Vladimir Riabchun
2026-11-19 10:01   ` no-reply
2026-11-19 17:32   ` Konstantin Khorenko
2026-11-19 17:32 ` [Devel] [PATCH hci-8.1 v5 0/2] sched: Fix incorrect nproc report inside CT 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=20261119-ct-invalid-nrpoc-v5-0-ff22216f458b@virtuozzo.com \
    --to=vladimir.riabchun@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=no-reply@sashiko.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