All of lore.kernel.org
 help / color / mirror / Atom feed
From: jboero <boeroboy@gmail.com>
To: selinux@vger.kernel.org
Cc: stephen.smalley.work@gmail.com, cgzones@googlemail.com,
	Johnny Boero <boeroboy@gmail.com>
Subject: [PATCH v1 0/3] setfiles: control relabeling parallelism from the environment
Date: Tue, 18 Aug 2026 14:23:30 -0500	[thread overview]
Message-ID: <20260818192340.119297-1-boeroboy@gmail.com> (raw)

From: Johnny Boero <boeroboy@gmail.com>

Hi,

This is the patch for the RFE at
https://github.com/SELinuxProject/selinux/issues/489, where a package
upgrade on an 88 core machine spent hours in restorecon with 87 cores
idle.  Stephen Smalley and Christian Göttsche both indicated on the
issue that switching the default thread count to 0 would be acceptable;
patch 2 does that, and patch 3 adds the environment variable the RFE
originally asked for.

Patches 2 and 3 are independent and either can be taken without the
other.

Patch 1 is a small fix noticed while touching the same code: "-T -1" is
currently accepted by strtoull(3) and wraps around to SIZE_MAX threads
instead of producing a usage error.

Patch 2 changes the setfiles(8)/restorecon(8) default from 1 thread to 0,
i.e. one thread per available CPU core.  Only the tools change; the
selinux_restorecon_parallel(3) default is untouched, so library callers
are unaffected.

Patch 3 adds RESTORECON_THREADS, with the same meaning as -T, which takes
precedence.  The motivation is reach: relabeling is driven from package
scriptlets and init scripts that a user cannot edit.  On the Fedora 44
system used for testing, 10 installed packages run restorecon from their
scriptlets and none of them pass -T, so the environment is the only way
to influence them without patching every spec file in the distribution.
An invalid value warns and is ignored rather than being fatal, since the
variable is inherited by every child process.

Measured with a dry run relabel of /usr/share (~588k files) on an 88 core
system:

  -T 1 / RESTORECON_THREADS=1   ~24s, 99% CPU
  default after this series     ~16s, ~1000% CPU

The speedup here is bounded by the directory walk and the syscall mix of
a dry run; a real relabel that writes contexts benefits more.

Two things I would like feedback on:

- Whether RESTORECON_THREADS is the right name, given the same binary is
  also setfiles(8).
- Whether an invalid value should warn and continue, as it does here, or
  be fatal.

Note that this series does not reach libsemanage, which calls
selinux_restorecon(3) single threaded on the policy store, or rpm's
selinux plugin, which labels each file inline with lsetfilecon(3) and
never goes through restorecon at all.  Both looked out of scope here.

Johnny Boero (3):
  policycoreutils/setfiles: reject invalid -T arguments
  policycoreutils/setfiles: use all CPU cores by default
  policycoreutils/setfiles: honor RESTORECON_THREADS

 policycoreutils/setfiles/restorecon.8 | 19 +++++++++--
 policycoreutils/setfiles/setfiles.8   | 20 +++++++++--
 policycoreutils/setfiles/setfiles.c   | 48 ++++++++++++++++++++++++---
 3 files changed, 79 insertions(+), 8 deletions(-)

-- 
2.55.0


             reply	other threads:[~2026-08-18 19:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 19:23 jboero [this message]
2026-08-18 19:23 ` [PATCH v1 1/3] policycoreutils/setfiles: reject invalid -T arguments jboero
2026-08-18 20:04   ` Stephen Smalley
2026-08-19 16:41     ` James Carter
2026-08-19 16:42       ` John Boero
2026-08-18 19:23 ` [PATCH v1 2/3] policycoreutils/setfiles: use all CPU cores by default jboero
2026-08-18 20:05   ` Stephen Smalley
2026-08-18 19:23 ` [PATCH v1 3/3] policycoreutils/setfiles: honor RESTORECON_THREADS jboero
2026-08-18 20:10   ` Stephen Smalley
2026-08-19 12:57 ` [PATCH v1 0/3] setfiles: control relabeling parallelism from the environment Stephen Smalley

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=20260818192340.119297-1-boeroboy@gmail.com \
    --to=boeroboy@gmail.com \
    --cc=cgzones@googlemail.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.