是否有任何命令可以获取Linux系统的虚拟内存大小,缓存大小和前端总线速度?Linux中的交换与虚拟内存相同吗?
是否有任何命令可以获取Linux系统的虚拟内存大小,缓存大小和前端总线速度?Linux中的交换与虚拟内存相同吗?
Answers:
这个问题完全包含在您先前的问题中。如何找到Linux系统的虚拟内存大小和缓存大小?。正如我对这个问题的回答所指出的那样,该sudo dmidecode --type processor
命令为您提供“外部时钟”速度,而FSB速度是该速度的倍数(通常为2或4倍)。
如果这对您不起作用,则应编辑原始问题,并告诉我们您得到了什么输出或错误是什么。您越具体,其他人就能为您提供更好的帮助。
正如《 The Journeyman》极客所指出的那样,通常可以从lshw
cpu相关输出中为“ clock”报告的值中,从中获得相同的“ External Clock”度量。
*-cpu
description: CPU
product: Genuine Intel(R) CPU T2300 @ 1.66GHz
vendor: Intel Corp.
physical id: 400
bus info: cpu@0
version: 6.14.8
serial: 0000-06E8-0000-0000-0000-0000
slot: Microprocessor
size: 1GHz
capacity: 1800MHz
width: 32 bits
clock: 133MHz
capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon bts pni monitor est tm2 xtpr pdcm cpufreq
configuration: id=0
最后,您可能会在的输出中找到外部时钟速度dmesg
,尽管这绝不是访问此信息的标准方法。您可以通过BIOS设置或查找CPU规格来找到FSB速度,尽管这些并非特定于Linux。
dmidecode
仅适用于x86。ARM处理器没有该命令,并且经常返回无用的值,例如不正确的BogMIPS。
是的,交换是虚拟内存。
虚拟内存大小 使用swapon -s或free
$ swapon -s
Filename Type Size Used Priority
/dev/sda6 partition 1004020 39620 -1
$ free
total used free shared buffers cached
Mem: 3087892 2879036 208856 0 394288 835052
-/+ buffers/cache: 1649696 1438196
Swap: 1004020 39620 964400
缓存大小 从/ proc / cpuinfo获取。“ 缓存大小 ”字段为您提供了CPU上的缓存。在多核计算机上,您将看到每个处理器一个条目,以及它自己的缓存值。
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 14
model name : Genuine Intel(R) CPU T2300 @ 1.66GHz
stepping : 8
cpu MHz : 1000.000
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
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 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon bts pni monitor est tm2 xtpr pdcm
bogomips : 3324.64
clflush size : 64
power management:
前端总线(FSB)速度 可以使用--type处理器参数从dmidecode实用程序中获得该速度。您需要sudo权限才能运行此命令。FSB由“ 外部时钟 ” 报告的速度指示。实际速度通常是报告速度的4倍,因为每个时钟周期都会执行许多指令。
$ sudo dmidecode --type processor
# dmidecode 2.9
SMBIOS 2.4 present.
Handle 0x0400, DMI type 4, 32 bytes
Processor Information
Socket Designation: Microprocessor
Type: Central Processor
Family: Pentium M
Manufacturer: Intel
ID: E8 06 00 00 FF FB E9 BF
Signature: Type 0, Family 6, Model 14, Stepping 8
Flags:
FPU (Floating-point unit on-chip)
VME (Virtual mode extension)
DE (Debugging extension)
PSE (Page size extension)
TSC (Time stamp counter)
MSR (Model specific registers)
PAE (Physical address extension)
MCE (Machine check exception)
CX8 (CMPXCHG8 instruction supported)
APIC (On-chip APIC hardware supported)
SEP (Fast system call)
MTRR (Memory type range registers)
PGE (Page global enable)
MCA (Machine check architecture)
CMOV (Conditional move instruction supported)
PAT (Page attribute table)
CLFSH (CLFLUSH instruction supported)
DS (Debug store)
ACPI (ACPI supported)
MMX (MMX technology supported)
FXSR (Fast floating-point save and restore)
SSE (Streaming SIMD extensions)
SSE2 (Streaming SIMD extensions 2)
SS (Self-snoop)
HTT (Hyper-threading technology)
TM (Thermal monitor supported)
PBE (Pending break enabled)
Version: Not Specified
Voltage: 3.3 V
External Clock: 133 MHz
Max Speed: 1800 MHz
Current Speed: 1000 MHz
Status: Populated, Enabled
Upgrade: None
L1 Cache Handle: 0x0700
L2 Cache Handle: 0x0701
L3 Cache Handle: Not Provided
在Linux机器上尝试以下操作: cat /proc/pal/cpu0/cache_info
这将显示如下内容:
Cache levels : 3
Unique caches : 5
Data Cache level 1:
Size : 16384 bytes
Attributes : WriteThrough
Associativity : 4
Line size : 64 bytes
Stride : 128 bytes
Store latency : 0 cycle(s)
Load latency : 1 cycle(s)
Store hints :
Load hints : [Temporal, level 1]
Alias boundary : 4096 byte(s)
Tag LSB : 12
Tag MSB : 49
Instruction Cache level 1:
Size : 16384 bytes
Attributes :
Associativity : 4
Line size : 64 bytes
Stride : 128 bytes
Store latency : N/A
Load latency : 1 cycle(s)
Store hints :
Load hints : [Temporal, level 1]
Alias boundary : 4096 byte(s)
Tag LSB : 12
Tag MSB : 49
Data Cache level 2:
Size : 262144 bytes
Attributes : WriteBack
Associativity : 8
Line size : 128 bytes
Stride : 128 bytes
Store latency : 7 cycle(s)
Load latency : 5 cycle(s)
Store hints : [Temporal, level 1][Non-temporal, all levels]
Load hints : [Temporal, level 1][Non-temporal, level 1][Non-temporal, all levels]
Alias boundary : 4096 byte(s)
Tag LSB : 15
Tag MSB : 49
Instruction Cache level 2:
Size : 524288 bytes
Attributes :
Associativity : 8
Line size : 128 bytes
Stride : 128 bytes
Store latency : N/A
Load latency : 7 cycle(s)
Store hints :
Load hints : [Temporal, level 1][Non-temporal, level 1][Non-temporal, all levels]
Alias boundary : 4096 byte(s)
Tag LSB : 16
Tag MSB : 49
Data/Instruction Cache level 3:
Size : 4194304 bytes
Attributes : Unified WriteBack
Associativity : 8
Line size : 128 bytes
Stride : 128 bytes
Store latency : 7 cycle(s)
Load latency : 14 cycle(s)
Store hints : [Temporal, level 1]
Load hints : [Temporal, level 1][Non-temporal, level 1]
Alias boundary : 4096 byte(s)
Tag LSB : 19
Tag MSB : 49
试试看ulimit -a
,在我的机器上它将显示类似以下内容:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31321
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 31321
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
free
在我的机器上运行,结果是这样的:
total used free shared buffers cached
Mem: 4024900 606472 3418428 0 85768 366980
-/+ buffers/cache: 153724 3871176
Swap: 3998716 0 3998716
我编写了以下代码来测试一个进程可以创建多少个线程:
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<stdio.h>
using namespace std;
#define MAX_THREAD_NUM 1100
void * threadTest(void* arg){
while(true){
sleep(5);
}
pthread_exit(NULL);
}
int main(){
for(int i = 0;i< MAX_THREAD_NUM;i++){
pthread_t tid;
cout<<"create thread "<< i <<"... "<<endl;
int ret = pthread_create(&tid,NULL,&threadTest,NULL);
if(ret !=0){
perror("pthread_create error");
}
pthread_detach(tid);
}
while(true){
sleep(5);
}
return 0;
}
结果是这样的:
create thread 378...
create thread 379...
create thread 380...
create thread 381...
create thread 382...
pthread_create error: Cannot allocate memory
create thread 383...
pthread_create error: Cannot allocate memory
create thread 384...
pthread_create error: Cannot allocate memory
create thread 385...
pthread_create error: Cannot allocate memory
create thread 386...
pthread_create error: Cannot allocate memory