Merge pull request #3753 from poettering/tasks-max-scale

Add support for relative TasksMax= specifications, and bump default for services
This commit is contained in:
Lennart Poettering
2016-07-22 17:40:12 +02:00
committed by GitHub
17 changed files with 239 additions and 60 deletions
+55
View File
@@ -832,6 +832,61 @@ uint64_t physical_memory_scale(uint64_t v, uint64_t max) {
return r;
}
uint64_t system_tasks_max(void) {
#if SIZEOF_PID_T == 4
#define TASKS_MAX ((uint64_t) (INT32_MAX-1))
#elif SIZEOF_PID_T == 2
#define TASKS_MAX ((uint64_t) (INT16_MAX-1))
#else
#error "Unknown pid_t size"
#endif
_cleanup_free_ char *value = NULL, *root = NULL;
uint64_t a = TASKS_MAX, b = TASKS_MAX;
/* Determine the maximum number of tasks that may run on this system. We check three sources to determine this
* limit:
*
* a) the maximum value for the pid_t type
* b) the cgroups pids_max attribute for the system
* c) the kernel's configure maximum PID value
*
* And then pick the smallest of the three */
if (read_one_line_file("/proc/sys/kernel/pid_max", &value) >= 0)
(void) safe_atou64(value, &a);
if (cg_get_root_path(&root) >= 0) {
value = mfree(value);
if (cg_get_attribute("pids", root, "pids.max", &value) >= 0)
(void) safe_atou64(value, &b);
}
return MIN3(TASKS_MAX,
a <= 0 ? TASKS_MAX : a,
b <= 0 ? TASKS_MAX : b);
}
uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
uint64_t t, m;
assert(max > 0);
/* Multiply the system's task value by the fraction v/max. Hence, if max==100 this calculates percentages
* relative to the system's maximum number of tasks. Returns UINT64_MAX on overflow. */
t = system_tasks_max();
assert(t > 0);
m = t * v;
if (m / t != v) /* overflow? */
return UINT64_MAX;
return m / max;
}
int update_reboot_parameter_and_warn(const char *param) {
int r;
+3
View File
@@ -186,6 +186,9 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
uint64_t physical_memory(void);
uint64_t physical_memory_scale(uint64_t v, uint64_t max);
uint64_t system_tasks_max(void);
uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
int update_reboot_parameter_and_warn(const char *param);
int version(void);