Posted at

kernel.pid_max

More than 3 years have passed since last update.

linux-2.6.32-573.3.1.el6.x86_64

pid_max:

PID allocation wrap value. When the kernel's next PID value
reaches this value, it wraps back to a minimum PID value.
PIDs of value pid_max or larger are not allocated.


  • デフォルトは 32768


    • CONFIG_BASE_SMALL が有効な場合は 4096



#define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000)


  • ただしプロセッサ数が基準を超える場合は次の通り自動調整が施される

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);

- pid_max(再利用開始となる境界値)

- min(A, B)
- A: pid_max_max = PID_MAX_LIMIT
- sizeof(long) > 4 = 64bit の時: 4 * 1024 * 1024 = 4,194,304
- 満たさない場合は PID_MAX_DEFAULT = 32,768 が使われる
- B: max(a,b)
- a: pid_max = PID_MAX_DEFAULT = 32,768
- b: PIDS_PER_CPU_DEFAULT = 1024 * num_possible_cpus()
- 挙動
- A は充分に大きいので基本的に B が pid_max の値となる
- デフォルト値がかわるのは b が 32,768 を超える時
- つまり 32,768 / 1,024 = 32 CPU を超える場合
- pid_max_min(再利用する際の開始値)
- pid_max_min = RESERVED_PIDS + 1
- RESERVED_PIDS = 300
- PIDS_PER_CPU_MIN = 8 * num_possible_cpus()


  • num_possible_cpus() は sysfs から確認可能

Additionally, CPU topology information is provided under

/sys/devices/system/cpu and includes these files. The internal
source for the output is in brackets ("[]").

kernel_max: the maximum CPU index allowed by the kernel configuration.
[NR_CPUS-1]
offline: CPUs that are not online because they have been
HOTPLUGGED off (see cpu-hotplug.txt) or exceed the limit
of CPUs allowed by the kernel configuration (kernel_max
above). [~cpu_online_mask + cpus >= NR_CPUS]
online: CPUs that are online and being scheduled [cpu_online_mask]
possible: CPUs that have been allocated resources and can be
brought online if they are present. [cpu_possible_mask]
present: CPUs that have been identified as being present in the
system. [cpu_present_mask]

The format for the above output is compatible with cpulist_parse()
[see <linux/cpumask.h>]. Some examples follow.
In this example, there are 64 CPUs in the system but cpus 32-63 exceed
the kernel max which is limited to 0..31 by the NR_CPUS config option
being 32. Note also that CPUs 2 and 4-31 are not online but could be
brought online as they are both present and possible.
kernel_max: 31
offline: 2,4-31,32-63
online: 0-1,3
possible: 0-31
present: 0-31

$ for i in kernel_max offline online possible present; do echo ${i} $(cat /sys/devices/system/cpu/${i}); done;

kernel_max 4095
offline
online 0-31
possible 0-31
present 0-31


  • num_possible_cpus() は set_cpu_possible() で設定された cpu_possible_bits の値を返している

  • set_cpu_possible() は次のコール階層をもつ

  • ACPI Table にある MADT: Multiple Apic Description Table のエントリ数に応じてコールされる

  • MADT の内容は procfs から参照できる



start_kernel()

└-setup_arch()
└-acpi_boot_init()
└-acpi_process_madt()
└-acpi_parse_madt_lapic_entries()
└-acpi_table_parse_madt()
└-acpi_table_parse_entries()
├-cpi_parse_x2apic()
| └-set_cpu_possible()
└-acpi_parse_lapic()
└-set_cpu_possible()