scx/scheds/kernel-examples/scx_userland.h
Andrea Righi 1e9e6778bc scx_userland: allocate tasks array based on kernel.pid_max
Currently the array of enqueued tasks is statically allocated to a fixed
size of USERLAND_MAX_TASKS to avoid potential deadlocks that could be
introduced by performing dynamic allocations in the enqueue path.

However, this also adds a limit on the maximum pid that the scheduler
can handle, since the pid is used as the index to access the array.

In fact, it is quite easy to trigger the following failure on an average
desktop system (making this scheduler pretty much unusable in such
scenario):

 $ sudo scx_userland
 ...
 Failed to enqueue task 33258: No such file or directory
 EXIT: BPF scheduler unregistered

Prevent this by using sysctl's kernel.pid_max as the size of the tasks
array (and still allocate it all at once during initialization).

The downside of this change is that scx_userland may require additional
memory to start and in small systems it could even trigger OOMs. For
this reason add an explicit message to the command help, suggesting to
reduce kernel.pid_max in case of OOM conditions.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2023-12-13 17:33:10 +01:00

18 lines
389 B
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta, Inc */
#ifndef __SCX_USERLAND_COMMON_H
#define __SCX_USERLAND_COMMON_H
/*
* An instance of a task that has been enqueued by the kernel for consumption
* by a user space global scheduler thread.
*/
struct scx_userland_enqueued_task {
__s32 pid;
u64 sum_exec_runtime;
u64 weight;
};
#endif // __SCX_USERLAND_COMMON_H