加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

PID_MAX在Linux中所依赖的因素是什么?

发布时间:2020-12-14 00:43:29 所属栏目:Linux 来源:网络整理
导读:我检查了两个 linux系统,两者都是64位,但两者的PID_MAX不同. 在一个系统上(SYSTEM1) cat /proc/sys/kernel/pid_max32768 SYSTEM1配置: dmesg | grep -i smp.*allow getconf PAGESIZE4096cat /proc/cpuinfo | awk '/^processor/{print $3}' | tail -111cat /
我检查了两个 linux系统,两者都是64位,但两者的PID_MAX不同.

在一个系统上(SYSTEM1)

cat /proc/sys/kernel/pid_max
32768

SYSTEM1配置:

dmesg | grep -i smp.*allow

getconf PAGESIZE
4096

cat /proc/cpuinfo | awk '/^processor/{print $3}' | tail -1
11
cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 0
cpu cores   : 6
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 1
cpu cores   : 6
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 2
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 2
cpu cores   : 6
apicid      : 4
initial apicid  : 4
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 3
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 1300.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 3
cpu cores   : 6
apicid      : 6
initial apicid  : 6
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 4
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 4
cpu cores   : 6
apicid      : 8
initial apicid  : 8
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 5
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 1200.000
cache size  : 15360 KB
physical id : 0
siblings    : 6
core id     : 5
cpu cores   : 6
apicid      : 10
initial apicid  : 10
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4389.48
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 6
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 0
cpu cores   : 6
apicid      : 32
initial apicid  : 32
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 7
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 1
cpu cores   : 6
apicid      : 34
initial apicid  : 34
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 8
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 2
cpu cores   : 6
apicid      : 36
initial apicid  : 36
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 9
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 2201.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 3
cpu cores   : 6
apicid      : 38
initial apicid  : 38
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 10
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 1200.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 4
cpu cores   : 6
apicid      : 40
initial apicid  : 40
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

processor   : 11
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz
stepping    : 7
microcode   : 1803
cpu MHz     : 1200.000
cache size  : 15360 KB
physical id : 1
siblings    : 6
core id     : 5
cpu cores   : 6
apicid      : 42
initial apicid  : 42
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips    : 4392.34
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical,48 bits virtual
power management:

而在其他(SYSTEM2),它是

cat /proc/sys/kernel/pid_max
65536

SYSTEM2配置:

dmesg | grep -i smp.*allow

SMP: Allowing 64 CPUs,61 hotplug CPUs

getconf PAGESIZE
4096

cat /proc/cpuinfo | awk '/^processor/{print $3}' | tail -1
2

cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 23
model name  : Intel(R) Xeon(R) CPU           X5450  @ 3.00GHz
stepping    : 6
microcode   : 4294967295
cpu MHz     : 2992.467
cache size  : 6144 KB
physical id : 0
siblings    : 3
core id     : 0
cpu cores   : 3
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 10
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good unfair_spinlock pni ssse3 cx16 sse4_1 hypervisor lahf_lm
bogomips    : 5984.93
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical,48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 23
model name  : Intel(R) Xeon(R) CPU           X5450  @ 3.00GHz
stepping    : 6
microcode   : 4294967295
cpu MHz     : 2992.467
cache size  : 6144 KB
physical id : 0
siblings    : 3
core id     : 1
cpu cores   : 3
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 10
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good unfair_spinlock pni ssse3 cx16 sse4_1 hypervisor lahf_lm
bogomips    : 5984.93
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical,48 bits virtual
power management:

processor   : 2
vendor_id   : GenuineIntel
cpu family  : 6
model       : 23
model name  : Intel(R) Xeon(R) CPU           X5450  @ 3.00GHz
stepping    : 6
microcode   : 4294967295
cpu MHz     : 2992.467
cache size  : 6144 KB
physical id : 0
siblings    : 3
core id     : 2
cpu cores   : 3
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 10
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good unfair_spinlock pni ssse3 cx16 sse4_1 hypervisor lahf_lm
bogomips    : 5984.93
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical,48 bits virtual
power management:

从手册页.

proc/sys/kernel/pid_max This file (new in Linux 2.5) specifies the
value at which PIDs wrap around (i.e.,the value in this file is one
greater than the maximum PID). The default value for this file,
32768,results in the same range of PIDs as on earlier kernels. On
32-bit platfroms,32768 is the maximum value for pid_max. On 64-bit
systems,pid_max can be set to any value up to 2^22 (PID_MAX_LIMIT,
approximately 4 million).

请注意,这两个系统都具有相同的Linux内核,但SYSTEM2在hyper-V上运行.

现在,我的问题是负责改变pid_max的因素是什么?
先感谢您.

解决方法

pid_max是根据可能的CPU数设置的,您可以在 pid.c line 597的内核源中看到它们

pid_max = min(pid_max_max,max_t(int,pid_max,PIDS_PER_CPU_DEFAULT * num_possible_cpus()));

num_possible_cpus()返回系统中可能存在的最大CPU数(包括启动后可插入的热插拔CPU).

如您所见,表达式包括最小值和最大值.

最小值是pid_max的初始值,它是从宏PID_MAX_DEFAULT派生的,它将是0x1000或0x8000,具体取决于编译时配置设置CONFIG_BASE_SMALL.

最大值是pid_max_max,而pid_max_max又来自某些内核编译时配置设置,特别是CONFIG_BASE_SMALL和PAGE_SIZE.这在宏PID_MAX_LIMIT see threads.h line 33中定义:

#define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : 
    (sizeof(long) > 4 ? 4 * 1024 * 1024 : PID_MAX_DEFAULT))

所以把所有这些放在一个例子中:在我的系统上(Centos 6):

> PAGESIZE是4096
> CONFIG_BASE_SMALL为0
>因此,PID_MAX_DEFAULT将为0x8000(32768)
> PID_MAX_LIMIT将是4 * 1024 * 1024 = 4194304
因此,> max_pid将在4194304< = max_pid< = 32768的范围内
从userland,您可以检查文件/ sys / devices / system / cpu / possible中可能的CPU数量.此文件中的数据格式有点奇怪 – 它将是0-max形式的字符串,例如0-15表示最多16个CPU(注意该数字为零计数).

有关此文件和此目录中其他文件的详细信息,请参阅cputopology.txt.

有关CPU热插拔的详细信息,请参阅 cpu-hotplug.txt

如果要检查内核编译时配置设置,请查看this answer以获取一些提示.

NB.给出的内核行号对内核4.7有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读