/proc

Table of Contents

1 /proc

1.1 /proc/meminfo

内存使用状况

[dirlt@umeng-ubuntu-pc] > cat /proc/meminfo
MemTotal:        3960316 kB
MemFree:          202908 kB
Buffers:           53632 kB
Cached:           764004 kB
SwapCached:       131884 kB
Active:          2484752 kB
Inactive:        1016724 kB
Active(anon):    2280636 kB
Inactive(anon):   814792 kB
Active(file):     204116 kB
Inactive(file):   201932 kB
Unevictable:          32 kB
Mlocked:              32 kB
SwapTotal:       4103164 kB
SwapFree:        2678984 kB
Dirty:              1492 kB
Writeback:             0 kB
AnonPages:       2629544 kB
Mapped:           122244 kB
Shmem:            411588 kB
Slab:             125096 kB
SReclaimable:      83480 kB
SUnreclaim:        41616 kB
KernelStack:        5904 kB
PageTables:        50164 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6083320 kB
Committed_AS:    7203968 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      362948 kB
VmallocChunk:   34359276724 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       57344 kB
DirectMap2M:     4052992 kB

可以使用/usr/bin/time来获取Page size

➜  debs git:(devel-yan) ✗ /usr/bin/time -v date
Fri Jun 12 11:53:44 CST 2015
Command being timed: "date"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: ?%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 760
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 241
Voluntary context switches: 1
Involuntary context switches: 1
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

1.2 /proc/stat

系统启动以来的多种统计信息

[dirlt@umeng-ubuntu-pc] > cat /proc/stat
cpu  25175536 13184 10088010 208990815 1165440 37 29476 0 0 0
cpu0 7597990 7286 3089511 49810301 706702 37 23258 0 0 0
cpu1 7914370 3065 2901460 50300065 188223 0 2403 0 0 0
cpu2 4922712 1228 2039477 54300492 171151 0 1921 0 0 0
cpu3 4740463 1604 2057560 54579955 99363 0 1892 0 0 0
intr 8881387947 2112 3 0 0 0 0 0 0 1 0 0 0 3175452 0 0 0 0 0 0 0 3554144 0 0 224677 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6681668 12 51519086 12401 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 12584201613
btime 1345525951
processes 234445
procs_running 3
procs_blocked 0
softirq 304218476 0 151026247 103572 14071723 3554590 0 262575 55846497 864372 78488900

1.3 /proc/swaps

当前系统上的交换分区及其空间利用信息. 优先级数字越低, 被使用到的可能性越大.

[dirlt@umeng-ubuntu-pc] > cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       4103164 1423572 -1

1.4 /proc/cmdline

在启动时传递至内核的相关参数信息. 这些信息通常由lilo或grub等启动管理工具进行传递.

[dirlt@umeng-ubuntu-pc] > cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.2.0-27-generic root=UUID=b25db1c7-e694-4eed-8d11-ea33047338cb ro quiet splash vt.handoff=7

1.5 /proc/version

内核版本

[dirlt@umeng-ubuntu-pc] > cat /proc/version
Linux version 3.2.0-27-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012

1.6 /proc/mounts

当前挂载的所有文件系统. see man fstab.

[dirlt@umeng-ubuntu-pc] > cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,relatime,size=1971356k,nr_inodes=492839,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,relatime,size=792064k,mode=755 0 0
/dev/disk/by-uuid/b25db1c7-e694-4eed-8d11-ea33047338cb / ext4 rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered 0 0
none /sys/fs/fuse/connections fusectl rw,relatime 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda3 /home ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
gvfs-fuse-daemon /home/dirlt/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0

1.7 /proc/modules

所有可用模块列表(lsmod): 模块名, 占用内存, 引用技术, 依赖模块, 加载状态

[dirlt@umeng-ubuntu-pc] > cat /proc/modules
pci_stub 12622 1 - Live 0x0000000000000000
vboxpci 23200 0 - Live 0x0000000000000000 (O)
vboxnetadp 13382 0 - Live 0x0000000000000000 (O)
vboxnetflt 23441 0 - Live 0x0000000000000000 (O)
vboxdrv 287082 3 vboxpci,vboxnetadp,vboxnetflt, Live 0x0000000000000000 (O)
bnep 18281 2 - Live 0x0000000000000000
rfcomm 47604 0 - Live 0x0000000000000000
bluetooth 180104 10 bnep,rfcomm, Live 0x0000000000000000
binfmt_misc 17540 1 - Live 0x0000000000000000
snd_hda_codec_realtek 223962 1 - Live 0x0000000000000000
ppdev 17113 0 - Live 0x0000000000000000
eeepc_wmi 13109 0 - Live 0x0000000000000000
asus_wmi 24456 1 eeepc_wmi, Live 0x0000000000000000
sparse_keymap 13890 1 asus_wmi, Live 0x0000000000000000
snd_hda_intel 33773 5 - Live 0x0000000000000000
snd_hda_codec 127706 2 snd_hda_codec_realtek,snd_hda_intel, Live 0x0000000000000000
snd_hwdep 13668 1 snd_hda_codec, Live 0x0000000000000000
snd_pcm 97188 3 snd_hda_intel,snd_hda_codec, Live 0x0000000000000000
snd_seq_midi 13324 0 - Live 0x0000000000000000
snd_rawmidi 30748 1 snd_seq_midi, Live 0x0000000000000000
snd_seq_midi_event 14899 1 snd_seq_midi, Live 0x0000000000000000
snd_seq 61896 2 snd_seq_midi,snd_seq_midi_event, Live 0x0000000000000000
snd_timer 29990 2 snd_pcm,snd_seq, Live 0x0000000000000000
snd_seq_device 14540 3 snd_seq_midi,snd_rawmidi,snd_seq, Live 0x0000000000000000
parport_pc 32866 1 - Live 0x0000000000000000
snd 78855 18 snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_rawmidi,snd_seq,snd_timer,snd_seq_device, Live 0
x0000000000000000
psmouse 87692 0 - Live 0x0000000000000000
serio_raw 13211 0 - Live 0x0000000000000000
soundcore 15091 1 snd, Live 0x0000000000000000
snd_page_alloc 18529 2 snd_hda_intel,snd_pcm, Live 0x0000000000000000
mac_hid 13253 0 - Live 0x0000000000000000
i915 472897 3 - Live 0x0000000000000000
wmi 19256 1 asus_wmi, Live 0x0000000000000000
drm_kms_helper 46978 1 i915, Live 0x0000000000000000
drm 242038 4 i915,drm_kms_helper, Live 0x0000000000000000
i2c_algo_bit 13423 1 i915, Live 0x0000000000000000
mei 41616 0 - Live 0x0000000000000000 (C)
video 19596 1 i915, Live 0x0000000000000000
lp 17799 0 - Live 0x0000000000000000
parport 46562 3 ppdev,parport_pc,lp, Live 0x0000000000000000
usbhid 47199 0 - Live 0x0000000000000000
hid 99559 1 usbhid, Live 0x0000000000000000
r8169 62099 0 - Live 0x0000000000000000

1.8 /proc/diskstats

磁盘设备I/O信息. https://www.kernel.org/doc/Documentation/iostats.txt

➜  logzilla git:(devel-yan) ✗ cat /proc/diskstats
   1       0 ram0 0 0 0 0 0 0 0 0 0 0 0
   1       1 ram1 0 0 0 0 0 0 0 0 0 0 0
   1       2 ram2 0 0 0 0 0 0 0 0 0 0 0
   1       3 ram3 0 0 0 0 0 0 0 0 0 0 0
   1       4 ram4 0 0 0 0 0 0 0 0 0 0 0
   1       5 ram5 0 0 0 0 0 0 0 0 0 0 0
   1       6 ram6 0 0 0 0 0 0 0 0 0 0 0
   1       7 ram7 0 0 0 0 0 0 0 0 0 0 0
   1       8 ram8 0 0 0 0 0 0 0 0 0 0 0
   1       9 ram9 0 0 0 0 0 0 0 0 0 0 0
   1      10 ram10 0 0 0 0 0 0 0 0 0 0 0
   1      11 ram11 0 0 0 0 0 0 0 0 0 0 0
   1      12 ram12 0 0 0 0 0 0 0 0 0 0 0
   1      13 ram13 0 0 0 0 0 0 0 0 0 0 0
   1      14 ram14 0 0 0 0 0 0 0 0 0 0 0
   1      15 ram15 0 0 0 0 0 0 0 0 0 0 0
   7       0 loop0 0 0 0 0 0 0 0 0 0 0 0
   7       1 loop1 0 0 0 0 0 0 0 0 0 0 0
   7       2 loop2 0 0 0 0 0 0 0 0 0 0 0
   7       3 loop3 0 0 0 0 0 0 0 0 0 0 0
   7       4 loop4 0 0 0 0 0 0 0 0 0 0 0
   7       5 loop5 0 0 0 0 0 0 0 0 0 0 0
   7       6 loop6 0 0 0 0 0 0 0 0 0 0 0
   7       7 loop7 0 0 0 0 0 0 0 0 0 0 0
   8       0 sda 79362 3272 2389658 33964 95789 28034 392276776 59220 0 39764 93112
   8       1 sda1 65147 2811 1997178 29560 10067 2800 155169272 11508 0 8304 41056
   8       2 sda2 2 0 4 0 0 0 0 0 0 0 0
   8       5 sda5 13126 411 381642 3768 63492 25111 185852104 34500 0 19012 38216
   8       6 sda6 737 19 7786 448 431 123 51255400 344 0 680 792
   8       7 sda7 161 31 1536 112 0 0 0 0 0 112 112
   8      16 sdb 862 1131 6908 3848 1 0 8 32 0 1032 3880
   8      17 sdb1 836 1128 6676 3716 1 0 8 32 0 900 3748

1.9 /proc/cpuinfo

1.10 /proc/crypto

所有可用的加密算法

[dirlt@umeng-ubuntu-pc] > cat /proc/crypto
name         : cbc(aes)
driver       : cbc(aes-generic)
module       : kernel
priority     : 100
refcnt       : 1
selftest     : passed
type         : blkcipher
blocksize    : 16
min keysize  : 16
max keysize  : 32
ivsize       : 16
geniv        : <default>

name         : hmac(sha256)
driver       : hmac(sha256-generic)
module       : kernel
priority     : 0
refcnt       : 2
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 32

name         : hmac(sha1)
driver       : hmac(sha1-generic)
module       : kernel
priority     : 0
refcnt       : 2
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 20

name         : stdrng
driver       : krng
module       : kernel
priority     : 200
refcnt       : 1
selftest     : passed
type         : rng
seedsize     : 0

name         : crc32c
driver       : crc32c-generic
module       : kernel
priority     : 100
refcnt       : 1
selftest     : passed
type         : shash
blocksize    : 1
digestsize   : 4

name         : aes
driver       : aes-generic
module       : kernel
priority     : 100
refcnt       : 1
selftest     : passed
type         : cipher
blocksize    : 16
min keysize  : 16
max keysize  : 32

name         : sha256
driver       : sha256-generic
module       : kernel
priority     : 0
refcnt       : 3
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 32

name         : sha224
driver       : sha224-generic
module       : kernel
priority     : 0
refcnt       : 1
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 28

name         : sha1
driver       : sha1-generic
module       : kernel
priority     : 0
refcnt       : 3
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 20

name         : md5
driver       : md5-generic
module       : kernel
priority     : 0
refcnt       : 1
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 16

name         : crc32c
driver       : crc32c-intel
module       : kernel
priority     : 200
refcnt       : 1
selftest     : passed
type         : shash
blocksize    : 1
digestsize   : 4

1.11 /proc/loadavg

Linux系统中Load Average含义

[dirlt@umeng-ubuntu-pc] > cat /proc/loadavg
2.46 2.14 2.16 15/736 11012
  • 前三列表示最近1分钟, 5分钟及15分钟的load average.
  • 第四列分别是处于可调度状态的进程数目和总进程数目.
  • 第五列是最近一个由内核创建的进程的PID.

1.12 /proc/slabinfo

内核slab分配器信息

[dirlt@umeng-ubuntu-pc] > sudo cat /proc/slabinfo
[sudo] password for dirlt:
slabinfo - version: 2.1
# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : sla
bdata <active_slabs> <num_slabs> <sharedavail>
ip6_dst_cache        100    100    320   25    2 : tunables    0    0    0 : slabdata      4      4      0
UDPLITEv6              0      0   1024   16    4 : tunables    0    0    0 : slabdata      0      0      0
UDPv6                 64     64   1024   16    4 : tunables    0    0    0 : slabdata      4      4      0
tw_sock_TCPv6        425    450    320   25    2 : tunables    0    0    0 : slabdata     18     18      0
TCPv6                221    221   1920   17    8 : tunables    0    0    0 : slabdata     13     13      0
flow_cache             0      0    104   39    1 : tunables    0    0    0 : slabdata      0      0      0
kcopyd_job             0      0   3240   10    8 : tunables    0    0    0 : slabdata      0      0      0
dm_uevent              0      0   2608   12    8 : tunables    0    0    0 : slabdata      0      0      0
dm_rq_target_io        0      0    408   20    2 : tunables    0    0    0 : slabdata      0      0      0
cfq_queue            510    510    232   17    1 : tunables    0    0    0 : slabdata     30     30      0
bsg_cmd                0      0    312   26    2 : tunables    0    0    0 : slabdata      0      0      0
mqueue_inode_cache     18     18    896   18    4 : tunables    0    0    0 : slabdata      1      1      0
fuse_request         104    104    608   26    4 : tunables    0    0    0 : slabdata      4      4      0
fuse_inode            46     46    704   23    4 : tunables    0    0    0 : slabdata      2      2      0
ecryptfs_key_record_cache      0      0    576   28    4 : tunables    0    0    0 : slabdata      0      0      0
ecryptfs_inode_cache      0      0    960   17    4 : tunables    0    0    0 : slabdata      0      0      0
hugetlbfs_inode_cache     28     28    576   28    4 : tunables    0    0    0 : slabdata      1      1      0
journal_handle       680    680     24  170    1 : tunables    0    0    0 : slabdata      4      4      0
journal_head         720    720    112   36    1 : tunables    0    0    0 : slabdata     20     20      0
revoke_record       4992   4992     32  128    1 : tunables    0    0    0 : slabdata     39     39      0
ext4_inode_cache   53478  53478    880   18    4 : tunables    0    0    0 : slabdata   2971   2971      0
ext4_free_data      3650   4015     56   73    1 : tunables    0    0    0 : slabdata     55     55      0
ext4_allocation_context   3810   3810    136   30    1 : tunables    0    0    0 : slabdata    127    127      0
ext4_io_end          261    406   1128   29    8 : tunables    0    0    0 : slabdata     14     14      0
ext4_io_page        1284   2816     16  256    1 : tunables    0    0    0 : slabdata     11     11      0
ext3_inode_cache       0      0    776   21    4 : tunables    0    0    0 : slabdata      0      0      0
ext3_xattr             0      0     88   46    1 : tunables    0    0    0 : slabdata      0      0      0
dquot                  0      0    256   16    1 : tunables    0    0    0 : slabdata      0      0      0
dnotify_mark        4230   4230    136   30    1 : tunables    0    0    0 : slabdata    141    141      0
dio                  100    100    640   25    4 : tunables    0    0    0 : slabdata      4      4      0
pid_namespace          0      0   2128   15    8 : tunables    0    0    0 : slabdata      0      0      0
user_namespace         0      0   1072   30    8 : tunables    0    0    0 : slabdata      0      0      0
UDP-Lite               0      0    832   19    4 : tunables    0    0    0 : slabdata      0      0      0
ip_fib_trie          292    292     56   73    1 : tunables    0    0    0 : slabdata      4      4      0
arp_cache             72     72    448   18    2 : tunables    0    0    0 : slabdata      4      4      0
UDP                   76     76    832   19    4 : tunables    0    0    0 : slabdata      4      4      0
tw_sock_TCP          240    240    256   16    1 : tunables    0    0    0 : slabdata     15     15      0
TCP                  140    252   1728   18    8 : tunables    0    0    0 : slabdata     14     14      0
blkdev_queue          51     51   1880   17    8 : tunables    0    0    0 : slabdata      3      3      0
blkdev_requests      374    374    368   22    2 : tunables    0    0    0 : slabdata     17     17      0
fsnotify_event      1632   1632    120   34    1 : tunables    0    0    0 : slabdata     48     48      0
bip-256                7      7   4224    7    8 : tunables    0    0    0 : slabdata      1      1      0
bip-128                0      0   2176   15    8 : tunables    0    0    0 : slabdata      0      0      0
bip-64                 0      0   1152   28    8 : tunables    0    0    0 : slabdata      0      0      0
bip-16                21     21    384   21    2 : tunables    0    0    0 : slabdata      1      1      0
sock_inode_cache    1149   1300    640   25    4 : tunables    0    0    0 : slabdata     52     52      0
net_namespace          0      0   2560   12    8 : tunables    0    0    0 : slabdata      0      0      0
shmem_inode_cache   2929   3375    640   25    4 : tunables    0    0    0 : slabdata    135    135      0
Acpi-ParseExt       3304   3304     72   56    1 : tunables    0    0    0 : slabdata     59     59      0
Acpi-State           204    204     80   51    1 : tunables    0    0    0 : slabdata      4      4      0
Acpi-Namespace      1428   1428     40  102    1 : tunables    0    0    0 : slabdata     14     14      0
task_delay_info     1764   1764    112   36    1 : tunables    0    0    0 : slabdata     49     49      0
taskstats             96     96    328   24    2 : tunables    0    0    0 : slabdata      4      4      0
proc_inode_cache    3001   3302    624   26    4 : tunables    0    0    0 : slabdata    127    127      0
sigqueue             150    150    160   25    1 : tunables    0    0    0 : slabdata      6      6      0
bdev_cache            76     76    832   19    4 : tunables    0    0    0 : slabdata      4      4      0
sysfs_dir_cache    18480  18480    144   28    1 : tunables    0    0    0 : slabdata    660    660      0
inode_cache         7515   8120    560   29    4 : tunables    0    0    0 : slabdata    280    280      0
dentry             63000  63000    192   21    1 : tunables    0    0    0 : slabdata   3000   3000      0
iint_cache             0      0    112   36    1 : tunables    0    0    0 : slabdata      0      0      0
buffer_head        54221  60684    104   39    1 : tunables    0    0    0 : slabdata   1556   1556      0
vm_area_struct     44863  48047    176   23    1 : tunables    0    0    0 : slabdata   2089   2089      0
mm_struct            252    252    896   18    4 : tunables    0    0    0 : slabdata     14     14      0
files_cache          465    506    704   23    4 : tunables    0    0    0 : slabdata     22     22      0
signal_cache         456    600   1088   30    8 : tunables    0    0    0 : slabdata     20     20      0
sighand_cache        285    315   2112   15    8 : tunables    0    0    0 : slabdata     21     21      0
task_xstate         1631   1824    832   19    4 : tunables    0    0    0 : slabdata     96     96      0
task_struct          758    820   5872    5    8 : tunables    0    0    0 : slabdata    164    164      0
anon_vma           12228  13328     72   56    1 : tunables    0    0    0 : slabdata    238    238      0
shared_policy_node  39239  42670     48   85    1 : tunables    0    0    0 : slabdata    502    502      0
numa_policy          680    680     24  170    1 : tunables    0    0    0 : slabdata      4      4      0
radix_tree_node    11597  15792    568   28    4 : tunables    0    0    0 : slabdata    564    564      0
idr_layer_cache     1320   1320    544   30    4 : tunables    0    0    0 : slabdata     44     44      0
dma-kmalloc-8192       0      0   8192    4    8 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-4096       0      0   4096    8    8 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-2048       0      0   2048   16    8 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-1024       0      0   1024   16    4 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-512        0      0    512   16    2 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-256        0      0    256   16    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-128        0      0    128   32    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-64         0      0     64   64    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-32         0      0     32  128    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-16         0      0     16  256    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-8          0      0      8  512    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-192        0      0    192   21    1 : tunables    0    0    0 : slabdata      0      0      0
dma-kmalloc-96         0      0     96   42    1 : tunables    0    0    0 : slabdata      0      0      0
kmalloc-8192          87     92   8192    4    8 : tunables    0    0    0 : slabdata     23     23      0
kmalloc-4096         200    240   4096    8    8 : tunables    0    0    0 : slabdata     30     30      0
kmalloc-2048         422    544   2048   16    8 : tunables    0    0    0 : slabdata     34     34      0
kmalloc-1024        1154   1280   1024   16    4 : tunables    0    0    0 : slabdata     80     80      0
kmalloc-512         2848   3328    512   16    2 : tunables    0    0    0 : slabdata    208    208      0
kmalloc-256        14079  14704    256   16    1 : tunables    0    0    0 : slabdata    919    919      0
kmalloc-128         3467   6816    128   32    1 : tunables    0    0    0 : slabdata    213    213      0
kmalloc-64         10415  12928     64   64    1 : tunables    0    0    0 : slabdata    202    202      0
kmalloc-32         10224  11648     32  128    1 : tunables    0    0    0 : slabdata     91     91      0
kmalloc-16          4608   4608     16  256    1 : tunables    0    0    0 : slabdata     18     18      0
kmalloc-8          31744  31744      8  512    1 : tunables    0    0    0 : slabdata     62     62      0
kmalloc-192         3055   4368    192   21    1 : tunables    0    0    0 : slabdata    208    208      0
kmalloc-96          4031   4116     96   42    1 : tunables    0    0    0 : slabdata     98     98      0
kmem_cache            32     32    256   16    1 : tunables    0    0    0 : slabdata      2      2      0
kmem_cache_node      128    128     64   64    1 : tunables    0    0    0 : slabdata      2      2      0

1.13 /proc/vmstat

虚拟内存统计信息

[dirlt@umeng-ubuntu-pc] > cat /proc/vmstat
nr_free_pages 39606
nr_inactive_anon 207905
nr_active_anon 575539
nr_inactive_file 51308
nr_active_file 51193
nr_unevictable 8
nr_mlock 8
nr_anon_pages 662833
nr_mapped 30562
nr_file_pages 242500
nr_dirty 288
nr_writeback 0
nr_slab_reclaimable 20951
nr_slab_unreclaimable 10401
nr_page_table_pages 12576
nr_kernel_stack 739
nr_unstable 0
nr_bounce 0
nr_vmscan_write 1043356
nr_vmscan_immediate_reclaim 310904
nr_writeback_temp 0
nr_isolated_anon 0
nr_isolated_file 0
nr_shmem 106998
nr_dirtied 14956613
nr_written 13377394
numa_hit 6181305909
numa_miss 0
numa_foreign 0
numa_interleave 5518
numa_local 6181305909
numa_other 0
nr_anon_transparent_hugepages 0
nr_dirty_threshold 92555
nr_dirty_background_threshold 46277
pgpgin 17601663
pgpgout 64310804
pswpin 491621
pswpout 789986
pgalloc_dma 0
pgalloc_dma32 5030620457
pgalloc_normal 1192146375
pgalloc_movable 0
pgfree 6222807408
pgactivate 4825471
pgdeactivate 4561700
pgfault 5884815503
pgmajfault 159176
pgrefill_dma 0
pgrefill_dma32 2727143
pgrefill_normal 3119709
pgrefill_movable 0
pgsteal_dma 0
pgsteal_dma32 4612169
pgsteal_normal 2661815
pgsteal_movable 0
pgscan_kswapd_dma 0
pgscan_kswapd_dma32 6468262
pgscan_kswapd_normal 4573712
pgscan_kswapd_movable 0
pgscan_direct_dma 0
pgscan_direct_dma32 275766
pgscan_direct_normal 246885
pgscan_direct_movable 0
zone_reclaim_failed 0
pginodesteal 0
slabs_scanned 1904768
kswapd_steal 7105516
kswapd_inodesteal 41781
kswapd_low_wmark_hit_quickly 10
kswapd_high_wmark_hit_quickly 980
kswapd_skip_congestion_wait 4130
pageoutrun 147240
allocstall 3159
pgrotated 884823
compact_blocks_moved 0
compact_pages_moved 0
compact_pagemigrate_failed 0
compact_stall 5
compact_fail 3
compact_success 2
htlb_buddy_alloc_success 0
htlb_buddy_alloc_fail 0
unevictable_pgs_culled 0
unevictable_pgs_scanned 0
unevictable_pgs_rescued 74
unevictable_pgs_mlocked 82
unevictable_pgs_munlocked 74
unevictable_pgs_cleared 0
unevictable_pgs_stranded 0
unevictable_pgs_mlockfreed 0
thp_fault_alloc 0
thp_fault_fallback 0
thp_collapse_alloc 0
thp_collapse_alloc_failed 0
thp_split 0

1.14 /proc/zoneinfo

内存区域(zone)信息

[dirlt@umeng-ubuntu-pc] > cat /proc/zoneinfo
Node 0, zone      DMA
  pages free     3977
        min      65
        low      81
        high     97
        scanned  0
        spanned  4080
        present  3913
    nr_free_pages 3977
    nr_inactive_anon 0
    nr_active_anon 0
    nr_inactive_file 0
    nr_active_file 0
    nr_unevictable 0
    nr_mlock     0
    nr_anon_pages 0
    nr_mapped    0
    nr_file_pages 0
    nr_dirty     0
    nr_writeback 0
    nr_slab_reclaimable 0
    nr_slab_unreclaimable 0
    nr_page_table_pages 0
    nr_kernel_stack 0
    nr_unstable  0
    nr_bounce    0
    nr_vmscan_write 0
    nr_vmscan_immediate_reclaim 0
    nr_writeback_temp 0
    nr_isolated_anon 0
    nr_isolated_file 0
    nr_shmem     0
    nr_dirtied   0
    nr_written   0
    numa_hit     0
    numa_miss    0
    numa_foreign 0
    numa_interleave 0
    numa_local   0
    numa_other   0
    nr_anon_transparent_hugepages 0
        protection: (0, 2906, 3912, 3912)
  pagesets
    cpu: 0
              count: 0
              high:  0
              batch: 1
  vm stats threshold: 6
    cpu: 1
              count: 0
              high:  0
              batch: 1
  vm stats threshold: 6
    cpu: 2
              count: 0
              high:  0
              batch: 1
  vm stats threshold: 6
    cpu: 3
              count: 0
              high:  0
              batch: 1
  vm stats threshold: 6
  all_unreclaimable: 1
  start_pfn:         16
  inactive_ratio:    1
Node 0, zone    DMA32
  pages free     36397
        min      12503
        low      15628
        high     18754
        scanned  0
        spanned  1044480
        present  744178
    nr_free_pages 36397
    nr_inactive_anon 122972
    nr_active_anon 492944
    nr_inactive_file 32614
    nr_active_file 31141
    nr_unevictable 0
    nr_mlock     0
    nr_anon_pages 528611
    nr_mapped    16731
    nr_file_pages 167055
    nr_dirty     202
    nr_writeback 0
    nr_slab_reclaimable 14391
    nr_slab_unreclaimable 3764
    nr_page_table_pages 5393
    nr_kernel_stack 217
    nr_unstable  0
    nr_bounce    0
    nr_vmscan_write 573794
    nr_vmscan_immediate_reclaim 248788
    nr_writeback_temp 0
    nr_isolated_anon 0
    nr_isolated_file 0
    nr_shmem     74754
    nr_dirtied   8249855
    nr_written   6854644
    numa_hit     5001386683
    numa_miss    0
    numa_foreign 0
    numa_interleave 0
    numa_local   5001386683
    numa_other   0
    nr_anon_transparent_hugepages 0
        protection: (0, 0, 1006, 1006)
  pagesets
    cpu: 0
              count: 62
              high:  186
              batch: 31
  vm stats threshold: 36
    cpu: 1
              count: 171
              high:  186
              batch: 31
  vm stats threshold: 36
    cpu: 2
              count: 62
              high:  186
              batch: 31
  vm stats threshold: 36
    cpu: 3
              count: 125
              high:  186
              batch: 31
  vm stats threshold: 36
  all_unreclaimable: 0
  start_pfn:         4096
  inactive_ratio:    4
Node 0, zone   Normal
  pages free     5426
        min      4327
        low      5408
        high     6490
        scanned  0
        spanned  261632
        present  257544
    nr_free_pages 5426
    nr_inactive_anon 81011
    nr_active_anon 80301
    nr_inactive_file 18852
    nr_active_file 20072
    nr_unevictable 8
    nr_mlock     8
    nr_anon_pages 131848
    nr_mapped    13831
    nr_file_pages 71702
    nr_dirty     172
    nr_writeback 0
    nr_slab_reclaimable 6568
    nr_slab_unreclaimable 6641
    nr_page_table_pages 7176
    nr_kernel_stack 523
    nr_unstable  0
    nr_bounce    0
    nr_vmscan_write 469562
    nr_vmscan_immediate_reclaim 62116
    nr_writeback_temp 0
    nr_isolated_anon 0
    nr_isolated_file 0
    nr_shmem     28316
    nr_dirtied   6708910
    nr_written   6523845
    numa_hit     1183081020
    numa_miss    0
    numa_foreign 0
    numa_interleave 5518
    numa_local   1183081020
    numa_other   0
    nr_anon_transparent_hugepages 0
        protection: (0, 0, 0, 0)
  pagesets
    cpu: 0
              count: 41
              high:  186
              batch: 31
  vm stats threshold: 24
    cpu: 1
              count: 170
              high:  186
              batch: 31
  vm stats threshold: 24
    cpu: 2
              count: 132
              high:  186
              batch: 31
  vm stats threshold: 24
    cpu: 3
              count: 185
              high:  186
              batch: 31
  vm stats threshold: 24
  all_unreclaimable: 0
  start_pfn:         1048576
  inactive_ratio:    1

1.15 /proc/<pid>

文件 说明
cmdline 启动参数
cwd 当前目录
environ 环境变量
exe 可执行文件
fd* 所有打开文件
io 运行IO信息
limits 运行资源限制
maps 虚拟内存布局
mount* 运行挂载点信息
net 运行网络参数信息
sched 进程调度信息
status 运行状态
oom* OOM权重分值

2 /proc/sys

在/proc/sys下面有一些可以动态修改的内核参数. 两种方式可以修改这些参数:

  • 使用sysctl工具来进行修改. 这种方式只能临时修改, 重启之后恢复原有设置. `sudo sysctl vm.swappiness=0`.
  • 修改/etc/sysctl.conf文件. 这样可以使设置永久生效.

3 /proc/sys/vm

3.1 /proc/sys/vm/overcommit_memory

  • OVERCOMMIT_GUESS=0
    • Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It ensures a seriously wild allocation fails while allowing overcommit to reduce swap usage. root is allowed to allocate slighly more memory in this mode. This is the default.
    • 用户申请内存的时候, 系统会"启发式"地判断是否通过.
  • OVERCOMMIT_ALWAYS=1
    • Always overcommit. Appropriate for some scientific applications.
    • 用户申请内存的时候, 系统不进行任何检查, 直接通过.
  • OVERCOMMIT_NEVER=2
    • Don't overcommit. The total address space commit for the system is not permitted to exceed swap + a configurable percentage (default is 50) of physical RAM. Depending on the percentage you use, in most situations this means a process will not be killed while accessing pages but will receive errors on memory allocation as appropriate.
    • 用户一次申请内存的大小不允许超过"可用内存"的大小, 计算这个"可用内存"使用overcommit_ratio参数. (Physical-RAM-Size) * ratio / 100 + (Swap-Size).

3.2 /proc/sys/vm/swappiness

使用swap分区程度. 设置为0表示, 系统会尽可能地减少page swap in/out操作(但不保证不使用swap分区).

3.3 /proc/sys/vm/dirty_*

控制脏页写回磁盘策略

➜  notes git:(master) ✗ ls /proc/sys/vm/dirty_*
/proc/sys/vm/dirty_background_bytes  /proc/sys/vm/dirty_bytes             /proc/sys/vm/dirty_ratio
/proc/sys/vm/dirty_background_ratio  /proc/sys/vm/dirty_expire_centisecs  /proc/sys/vm/dirty_writeback_centisecs

进程写操作时触发: 系统脏页比例超过dirty_ratio, 或者大小超过dirty_bytes.

后台pdflush(page dirty)定时检测: 时间周期是dirty_write_centisecs.

  • 系统脏页比例超过dirty_background_ratio, 或是大小超过dirty_background_bytes
  • 必须将时间超过dirty_expire_centisecs的脏页刷到磁盘

3.4 /proc/sys/vm/laptop_mode

膝上型计算机模式.

和传统方式唯一差别是, flusher/pdflush会找准磁盘运行时机, 将脏页面和正常IO请求一起写到磁盘上, 避免专门为了写磁盘而主动激活磁盘运行, 达到省电的目的.

多数Linux发布版会在机器使用电池电源时自动进行该模式, 而插上交流电源后恢复到常规模式.

3.5 /proc/sys/vm/drop_caches

用来释放kernel保存的buffers和cached. 其中buffers缓存inode(block cache), cached缓存文件页面(page cache)

  • 0 // 释放cached memory
  • 1 // 释放buffers
  • 2 // 释放两者

为了防止数据丢失,可以在修改这个文件之前先调用sync强制写盘.

3.6 /proc/sys/vm/panic_on_oom

This enables or disables panic on out-of-memory feature.

  • If this is set to 0, the kernel will kill some rogue process, called oom_killer. Usually, oom_killer can kill rogue processes and system will survive.
  • If this is set to 1, the kernel panics when out-of-memory happens. However, if a process limits using nodes by mempolicy/cpusets, and those nodes become memory exhaustion status, one process may be killed by oom-killer. No panic occurs in this case. Because other nodes' memory may be free. This means system total status may be not fatal yet.
  • If this is set to 2, the kernel panics compulsorily even on the above-mentioned.
  • The default value is 0. 1 and 2 are for failover of clustering. Please select either according to your policy of failover.

4 /proc/sys/net

4.1 /proc/sys/net/ipv4/ip_local_port_range

本地port分配范围. 本地client如果没有指定连接port的话那么就从这个范围内随机分配

➜  notes git:(master) ✗ cat /proc/sys/net/ipv4/ip_local_port_range
32768	61000

5 /proc/sys/fs

5.1 /proc/sys/fs/file-max

所有进程允许打开文件句柄数上限

5.2 /proc/sys/fs/nr_open

单个进程打开文件句柄数上限

5.3 /proc/sys/fs/file-nr

系统当前打开文件句柄数

5.4 /proc/sys/fs/epoll/max_user_watches

单个用户使用epoll进行监控的文件描述符上限

This specifies a limit on the total number of file descriptors that a user can register across all epoll instances on the system. The limit is per real user ID. Each registered file descriptor costs roughly 90 bytes on a 32-bit kernel, and roughly 160 bytes on a 64-bit kernel. Currently, the default value for max_user_watches is 1/25 (4%) of the available low memory, divided by the registration cost in bytes.

➜  notes git:(master) ✗ cat /proc/sys/fs/epoll/max_user_watches
1645137

6 /proc/sys/kernel

6.1 /proc/sys/kernel/hung_task_timeout_secs

>>> Detecting hung tasks in Linux

Sometimes tasks under Linux are blocked forever (essentially hung). Recent Linux kernels have an infrastructure to detect hung tasks. When this infrastructure is active it will periodically get activated to find out hung tasks and present a stack dump of those hung tasks (and maybe locks held). Additionally we can choose to panic the system when we detect atleast one hung task in the system. I will try to explain how khungtaskd works.

The infrastructure is based on a single kernel thread named as “khungtaskd”. So if you do a ps in your system and see that there is entry like [khungtaskd] you know it is there. I have one in my system: "136 root SW [khungtaskd]"

The loop of the khungtaskd daemon is a call to the scheduler for waking it up after ever 120 seconds (default value). The core algorithm is like this:

  1. Iterate over all the tasks in the system which are marked as TASK_UNINTERRUPTIBLE (additionally it does not consider UNINTERRUPTIBLE frozen tasks & UNINTERRUPTIBLE tasks that are newly created and never been scheduled out).
  2. If a task has not been switched out by the scheduler atleast once in the last 120 seconds it is considered as a hung task and its stack dump is displayed. If CONFIG_LOCKDEP is defined then it will also show all the locks the hung task is holding.

One can change the sampling interval of khungtaskd through the sysctl interface /proc/sys/kernel/hung_task_timeout_secs.


之前在hdfs一个datanode上面出现了磁盘损坏问题,然后在syslog里面发现了下面日志

May 14 00:02:50 dp46 kernel: INFO: task jbd2/sde1-8:3411 blocked for more than 120 seconds.
May 14 00:02:50 dp46 kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secsmahung_task_timeout_secs" disables this message.
May 14 00:02:50 dp46 kernel: jbd2/sde1-8   D 0000000000000000     0  3411      2 0x00000000
May 14 00:02:50 dp46 kernel: ffff880817a71a80 0000000000000046 ffff880096d12f00 0000000000000441
May 14 00:02:50 dp46 kernel: ffff880818052938 ffff880818052848 ffff88081805c3b8 ffff88081805c3b8
May 14 00:02:50 dp46 kernel: ffff88081b22e6b8 ffff880817a71fd8 000000000000f4e8 ffff88081b22e6b8
May 14 00:02:50 dp46 kernel: Call Trace:
May 14 00:02:50 dp46 kernel: [<ffffffff8109b809>] ? ktime_get_ts+0xa9/0xe0
May 14 00:02:50 dp46 kernel: [<ffffffff81110b10>] ? sync_page+0x0/0x50
May 14 00:02:50 dp46 kernel: [<ffffffff814ed1e3>] io_schedule+0x73/0xc0
May 14 00:02:50 dp46 kernel: [<ffffffff81110b4d>] sync_page+0x3d/0x50
May 14 00:02:50 dp46 kernel: [<ffffffff814eda4a>] __wait_on_bit_lock+0x5a/0xc0
May 14 00:02:50 dp46 kernel: [<ffffffff81110ae7>] __lock_page+0x67/0x70
May 14 00:02:50 dp46 kernel: [<ffffffff81090c30>] ? wake_bit_function+0x0/0x50
May 14 00:02:50 dp46 kernel: [<ffffffff811271a5>] ? pagevec_lookup_tag+0x25/0x40
May 14 00:02:50 dp46 kernel: [<ffffffff811261f2>] write_cache_pages+0x392/0x4a0
May 14 00:02:50 dp46 kernel: [<ffffffff81124c80>] ? __writepage+0x0/0x40
May 14 00:02:50 dp46 kernel: [<ffffffff81126324>] generic_writepages+0x24/0x30
May 14 00:02:50 dp46 kernel: [<ffffffffa00774d7>] journal_submit_inode_data_buffers+0x47/0x50 [jbd2]
May 14 00:02:50 dp46 kernel: [<ffffffffa00779e5>] jbd2_journal_commit_transaction+0x375/0x14b0 [jbd2]
May 14 00:02:50 dp46 kernel: [<ffffffff8100975d>] ? __switch_to+0x13d/0x320
May 14 00:02:50 dp46 kernel: [<ffffffff8107c0ec>] ? lock_timer_base+0x3c/0x70
May 14 00:02:50 dp46 kernel: [<ffffffff81090bf0>] ? autoremove_wake_function+0x0/0x40
May 14 00:02:50 dp46 kernel: [<ffffffffa007d928>] kjournald2+0xb8/0x220 [jbd2]
May 14 00:02:50 dp46 kernel: [<ffffffff81090bf0>] ? autoremove_wake_function+0x0/0x40
May 14 00:02:50 dp46 kernel: [<ffffffffa007d870>] ? kjournald2+0x0/0x220 [jbd2]
May 14 00:02:50 dp46 kernel: [<ffffffff81090886>] kthread+0x96/0xa0
May 14 00:02:50 dp46 kernel: [<ffffffff8100c14a>] child_rip+0xa/0x20
May 14 00:02:50 dp46 kernel: [<ffffffff810907f0>] ? kthread+0x0/0xa0
May 14 00:02:50 dp46 kernel: [<ffffffff8100c140>] ? child_rip+0x0/0x20

The JBD is the journaling block device that sits between the file system and the block device driver. The jbd2 version is for ext4.

7 /proc/net

7.1 /proc/net/tcp

所有tcp连接信息. netstat以及lsof等命令会读取这个文件.

之前遇到过netstat/lsof运行速度非常慢的问题. 通过strace发现是在读取这个文件时候非常耗时. 下面两个链接给出了这个问题的一些相关信息

7.2 /proc/net/dev

网卡设备流量信息

➜  logzilla git:(devel-yan) ✗ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  ppp0: 18559173   21273    0    0    0     0          0         0  2363487   19064    0    0    0     0       0          0
  eth0: 64611062   66682    0    0    0     0          0         0  9030687   62111    0    0    0     0       0          0
    lo: 21729683   27959    0    0    0     0          0         0 21729683   27959    0    0    0     0       0          0
docker0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
comments powered by Disqus