Cache aware scheduling is currently controlled only through global
debugfs knobs, but the right aggressiveness is workload and platform
specific. A multi-threaded Verilator run is one example: its RSS is
large while only a small part of it is hot, so an RSS-based footprint
estimate should not decide whether it is aggregated; and packing its
threads onto the SMT siblings of one LLC beats spreading them across
LLCs on some platforms (e.g. AMD EPYC Turin) but not on others (e.g.
EPYC Milan). Such choices cannot be made globally for the whole
machine.

This series adds per-process (per mm_struct) control. The first
patch splits the llc_aggr_tolerance debugfs knob into independent
thread-count and footprint tolerances and hardens the unbounded
percentage knobs against multiplication overflow. The second adds
prctl(PR_SCHED_CACHE), a single prctl command whose sub-command
selects GET or SET, covering a per-process enable, both tolerances
and the overaggr percentage, plus an inherit mask choosing which
attributes survive execve() (fork() always inherits). The remaining
two patches add selftests and documentation.

A numactl-like launcher built on this interface, llcctl, is
available at:

  https://github.com/cyyself/llcctl

It sets the attributes and the inherit mask on itself and executes
the target command, so the whole process tree runs with the
requested settings, e.g.:

  llcctl -d -- ./membw-hungry        # opt out, spread across LLCs
  llcctl -n 2 -p 100 -- make -j16    # pack up to 2 threads/core

Tested on x86-64 in QEMU with an EPYC-like topology (128 CPUs, 8 LLC
domains of 8 cores / 16 threads each): the selftests pass as both
root and an unprivileged user, and aggregation was verified end to
end by observing thread placement of a 24-thread spinner with and
without llcctl (evenly spread by default; packed into a single LLC
with raised tolerances). No new dmesg warnings.

Yangyu Chen (4):
  sched/cache: Split llc_aggr_tolerance into nr and size tolerances
  sched/cache: Add PR_SCHED_CACHE prctl for per-mm control
  selftests/prctl: Add PR_SCHED_CACHE tests
  docs/scheduler: Document cache aware scheduling controls

 Documentation/scheduler/index.rst             |   1 +
 Documentation/scheduler/sched-cache.rst       | 125 ++++++
 include/linux/mm_types.h                      |  10 +-
 include/linux/sched.h                         |  16 +
 include/uapi/linux/prctl.h                    |  38 ++
 kernel/fork.c                                 |   2 +-
 kernel/sched/debug.c                          |   6 +-
 kernel/sched/fair.c                           | 205 +++++++--
 kernel/sched/sched.h                          |   3 +-
 kernel/sched/syscalls.c                       | 120 ++++++
 kernel/sys.c                                  |   5 +
 .../trace/beauty/include/uapi/linux/prctl.h   |  37 ++
 tools/testing/selftests/prctl/.gitignore      |   1 +
 tools/testing/selftests/prctl/Makefile        |  15 +-
 tools/testing/selftests/prctl/config          |   1 +
 tools/testing/selftests/prctl/sched-cache.c   | 394 ++++++++++++++++++
 16 files changed, 931 insertions(+), 48 deletions(-)
 create mode 100644 Documentation/scheduler/sched-cache.rst
 create mode 100644 tools/testing/selftests/prctl/sched-cache.c


base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
-- 
2.47.3


Reply via email to