diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index 858b9555f..64e70f7c5 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -33,6 +35,19 @@ #include #include +struct sched_attr { + unsigned int size; + unsigned int sched_policy; + unsigned long long sched_flags; + int sched_nice; + unsigned int sched_priority; + unsigned long long sched_runtime; + unsigned long long sched_deadline; + unsigned long long sched_period; + unsigned int sched_util_min; + unsigned int sched_util_max; +}; + std::string Modprobe::MakeCanonical(const std::string& module_path) { auto start = module_path.find_last_of('/'); if (start == std::string::npos) { @@ -497,6 +512,17 @@ bool Modprobe::LoadModulesParallel(int num_threads) { // Load independent modules in parallel auto thread_function = [&] { +#if defined(__NR_sched_setattr) && defined(SCHED_FLAG_RESET_ON_FORK) + int pid = getpid(); + sched_attr attr = {}; + attr.size = sizeof(attr); + attr.sched_flags = + (SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP_MIN); + attr.sched_util_min = 1024; + + syscall(__NR_sched_setattr, pid, attr, 0); +#endif + std::unique_lock lk(vector_lock); while (!mods_path_to_load.empty()) { auto ret_load = true;