PIDS_PER_CPU_DEFAULT有什么意义?

时间:2014-02-27 06:34:56

标签: process linux-kernel kernel limit cpu

PIDS_PER_CPU_DEFAULT有什么意义,并定义linux / threads.h中定义的PIDS_PER_CPU_MIN? 我知道PID的最大值可以增加到大约400万,默认值是32768,但我无法将max pid值与PIDS_PER_CPU_DEFAULT相关联。

1 个答案:

答案 0 :(得分:1)

评论给出了一个很好的解释:

include/linux/threads.h

/*
 * Define a minimum number of pids per cpu.  Heuristically based
 * on original pid max of 32k for 32 cpus.  Also, increase the
 * minimum settable value for pid_max on the running system based
 * on similar defaults.  See kernel/pid.c:pidmap_init() for details.
 */
#define PIDS_PER_CPU_DEFAULT    1024
#define PIDS_PER_CPU_MIN        8

kernel/pid.c

void __init pidmap_init(void)
{
    /* Veryify no one has done anything silly */
    BUILD_BUG_ON(PID_MAX_LIMIT >= PIDNS_HASH_ADDING);

    /* bump default and minimum pid_max based on number of cpus */
    pid_max = min(pid_max_max, max_t(int, pid_max,
                            PIDS_PER_CPU_DEFAULT * num_possible_cpus()));
    pid_max_min = max_t(int, pid_max_min,
                            PIDS_PER_CPU_MIN * num_possible_cpus());
    pr_info("pid_max: default: %u minimum: %u\n", pid_max, pid_max_min);
    .
    .

在初始时,他们正在调整"default and minimum pid_max based on number of cpus"

您希望在系统中运行的最大pids数取决于可用的CPU数。 (我认为两个CPU在理论上可以运行两倍于一个CPU的并发进程,效率相同。)由于CPU的数量可能会从启动变为启动,因此在内核初始化时调整pid_max