编辑
2024-01-14
工作知识
0

从c程序来理解X86汇编

回顾x86汇编

简单的代码

#include <stdio.h> int main() { int a = 5; int b = a + 6; return 0; }

gcc -g -O0 simple.c -o simple gdb ./simple

(gdb) b main Breakpoint 1 at 0x1129: file simple.c, line 3. (gdb) r Starting program: /home/vivien/test/simple Breakpoint 1, main () at simple.c:3 3 { (gdb) n 2 5 int b = a + 6; (gdb) disass Dump of assembler code for function main: 0x0000555555555129 <+0>: endbr64 0x000055555555512d <+4>: push %rbp 0x000055555555512e <+5>: mov %rsp,%rbp 0x0000555555555131 <+8>: movl $0x5,-0x8(%rbp) => 0x0000555555555138 <+15>: mov -0x8(%rbp),%eax 0x000055555555513b <+18>: add $0x6,%eax 0x000055555555513e <+21>: mov %eax,-0x4(%rbp) 0x0000555555555141 <+24>: mov $0x0,%eax 0x0000555555555146 <+29>: pop %rbp 0x0000555555555147 <+30>: retq End of assembler dump.

这里disassemble命令默认以AT&T语法输出汇编指令 AT&T 语法中的指令格式为mnemonic source, destination 立即数为$符号,寄存器为%符号。 %eax是累加器,return的值也会放在这里 %ecx是计数器 %ebx是基地址寄存器 %edx是数据寄存器 %rbp是基指针,指向当前基址指针 %rsp是栈指针,指向当前堆栈指针

push %rbp mov %rsp,%rbp

这里将旧的基址指针压入栈保存备用,并将堆栈指针复制到基址指针上,这样%rbp指向main函数的栈帧底部。

movl $0x5,-0x8(%rbp) mov -0x8(%rbp),%eax add $0x6,%eax mov %eax,-0x4(%rbp)

这里将立即数5存储到 %rbp-8的局部变量中,再将%rbp-8移动到累加器中,然后对%eax自加6,然后将%eax的值存放在%rbp-4的局部变量

mov $0x0,%eax pop %rbp retq

这里将立即数0复制给%eax用作return的返回,并通过pop把旧的基指针从堆栈中取出并存回%rbp中。retq跳转回返回地址 在gdb中打印值来看看。

(gdb) x $rbp - 8 0x7fffffffe4f8: 0x00000005 (gdb) x &a 0x7fffffffe4f8: 0x00000005 (gdb) x &b 0x7fffffffe4fc: 0x0000000b (gdb) x $rbp - 4 0x7fffffffe4fc: 0x0000000b (gdb) x $rbp 0x7fffffffe500: 0x00000000

参考链接

https://www.recurse.com/blog/7-understanding-c-by-learning-assembly?utm_source=wechat_session&utm_medium=social&utm_oi=801824054439985152

编辑
2024-01-14
工作知识
0

Sar命令使用简介

Sar命令是一个分析系统性能的工具,这里简单介绍以下sar命令如何使用

sar -u 1

23时03分27秒 CPU %user %nice %system %iowait %steal %idle 23时03分28秒 all 2.76 0.00 2.01 0.00 0.00 95.23 %user 在用户模式下的百分比 %nice 如果通过renice调整了nice值,那么调整过的程序cpu占用的百分比 %system 在内核运行的百分比 %iowait 在io上阻塞时间的百分比,如果明显高,说明io压力很大 %steal 虚拟cpu等待实际cpu的时间百分比。说明虚拟机性能有问题 %idle 空闲的cpu百分比

sar -B 1

23时15分26秒 pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s %vmeff 23时15分27秒 0.00 0.00 77.00 0.00 1126.00 0.00 0.00 0.00 0.00 pgpgin 页面换入计数 pgpgout 页面换出到磁盘的计数 fault 页面错误计数(major + minor) majflt major fault 的计数 pgfree 空闲链表的页面数 pgscank kswapd扫描的页数 pgscand 直接扫描的页数 pgsteal 扫描的页中每秒被回收的数 vmeff pgsteal / pgscan ,也就是回收效率,一直接近0%说明系统内存压力很大

sar -r 1

3时26分34秒 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty 23时26分35秒 10114900 12329400 2527920 15.80 115168 2967592 9403528 55.63 1030508 4108996 124 kbmemfree 剩余内存,meminfo 的 MemFree kbavail 可用内存,meminfo的MemAvailable kbmemused 已用内存,free命令里面的used %memused 物理内存百分比 kbbuffers buffer使用,meminfo的Buffers kbcached cached使用,meminfo的Cached kbcommit 保证当前系统所需要的内存 %commit kbcommit/MemTotal kbactive 活跃内存数,meminfo的Active kbinact 非活跃内存数,meminfo的Inactive kbdirty 脏页数,meminfo的Dirty

sar -d 1

平均时间: DEV tps rkB/s wkB/s dkB/s areq-sz aqu-sz await %util 平均时间: dev7-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 tps 从物理磁盘读取IO的次数 rkB/s 读扇区的次数 wkB/s 写扇区的次数 dkB/s 丢弃IO的次数 areq-sz I/O 请求的平均大小 aqu-sz I/O请求的平均队列长度 await 每次请求IO的消耗时间,平均的 %util IO请求占用的cpu百分比

sar -b 1

17时36分27秒 tps rtps wtps dtps bread/s bwrtn/s bdscd/s 17时36分28秒 0.00 0.00 0.00 0.00 0.00 0.00 0.00 tps 从物理磁盘读取IO的总次数 rtps 读IO请求的次数 wtps 写IO请求的次数 dtps 丢弃IO请求的次数 bread/s 读取的数量 bwrtn/s 写入的数量 bdscd/s 丢弃的数量

sar -q 1

17时39分50秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 17时39分51秒 0 697 0.10 0.18 0.10 0 runq-sz 等待运行队列长度 plist-sz 任务列表的任务数 ldavg-1 最近一分钟内的平均负载 ldavg-5 最近5分钟内的平均负载 ldavg-15 最近15分钟内的平均负载 blocked 因为IO原因在等待状态的任务数

sar -v 1

17时41分09秒 dentunusd file-nr inode-nr pty-nr 17时41分10秒 78017 10304 97509 2 dentunusd 目录缓存中的未使用的缓存数 file-nr 系统文件句柄使用数量 inode-nr 索引节点句柄的使用数量 pty-nr pty终端的使用数量

sar -w 1

17时41分39秒 proc/s cswch/s 17时41分40秒 0.00 431.00 proc/s 每秒创建的任务总数 cswch/s 每秒上下文切换的总数

sar -I 中断号 1

18时13分11秒 INTR intr/s 18时13分12秒 190 28.00 INTR 中断号 intr/s cpu对中断响应的时间

sar 电源统计

sar -m USB 1 总计: BUS idvendor idprod maxpower manufact product 总计: 3 24ae 4012 200 Rapoo V500RGB Gaming Keyboard BUS USB挂的总线号 idvendor USB的vendor ID idprod USB的product ID maxpower USB设置的最大电流值 manufact 制造商 product USB类型

sar -m CPU 1

18时26分54秒 CPU MHz 18时26分55秒 all 2223.78 CPU CPU号 MHz 频率

sar -m TEMP 1

平均时间: TEMP degC %temp DEVICE 平均时间: 1 29.00 29.00 coretemp-isa-0000 degC 当前摄氏度 %temp 相对设备温度,最大是temp_max

sar 网络监控

sar -n DEV 1

18时32分28秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil 18时32分29秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 IFACE 网卡接口 rxpck/s 接收包数量 txpck/s 发送包数量 rxkB/s 接收包数据 txkB/s 发送包数据 rxcmp/s 接收压缩包数量 txcmp/s 发送压缩包数量 rxmcst/s 接收多播包数量 %ifutil 网卡利用率

sar -n EDEV 1

平均时间: IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s 平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 rxerr/s 接收到的损坏包 txerr/s 发送包的损坏数 coll/s 当发送数据包时候,每秒钟发生的冲撞(collisions)数,这个是在半双工模式下才有 rxdrop/s 因为网络缓冲区满,接收时丢弃的包数量 txdrop/s 因为网络缓冲区满,发送时丢弃的包数量 txcarr/s carrier-errors发生的次数 rxfram/s 接收包时发生帧对齐错误的次数 rxfifo/s 接收包发生缓冲区溢出的次数 txfifo/s 发送包发生缓冲区溢出的次数

sar -n ICMP 1

18时46分51秒 imsg/s omsg/s iech/s iechr/s oech/s oechr/s itm/s itmr/s otm/s otmr/s iadrmk/s iadrmkr/s oadrmk/s oadrmkr/s 18时46分52秒 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 imsg/s 接收到的ICMP包数量 icmpInMsgs omsg/s 发送的ICMP包数量 icmpOutMsgs iech/s icmpInEchos的数量 iechr/s icmpInEchoReps的消息数 oech/s icmpOutEchos消息数 oechr/s icmpOutEchoReps消息数 itm/s icmpInTimestamps的数量 itmr/s icmpInTimestampReps的数量 otm/s icmpInTimestampReps的数量 otmr/s icmpOutTimestampReps的数量 iadrmk/s ICMP 地址掩码请求消息的数量 iadrmkr/s ICMP 地址掩码回复消息的数量 oadrmk/s ICMP 地址掩码请求消息的数量 oadrmkr/s 发送的 ICMP 地址掩码回复消息的数量

sar -n IP 1

19时11分13秒 irec/s fwddgm/s idel/s orq/s asmrq/s asmok/s fragok/s fragcrt/s irec/s 接收到的报文数 fwddgm/s 转发的报文数 idel/s 成功发送的报文数 orq/s 向IP层提供的报文数 asmrq/s 接收的IP分片数 asmok/s 成功重组的IP报文数 fragok/s 成功分片的报文数 fragcrt/s 产生的分片数

sar -n SOCK 1

19时12分15秒 totsck tcpsck udpsck rawsck ip-frag tcp-tw totsck 被使用的socket数 tcpsck TCP的socket数 udpsck UDP的socket数 rawsck RAW的socket数 if-frag IP分片的数 tcp-tw 处于TIME-WAIT状态的连接数量

sar -n SOFT 1

19时12分38秒 CPU total/s dropd/s squeezd/s rx_rps/s flw_lim/s total/s 网络帧数 dropd/s 溢出丢弃的网络帧数 squeezd/s 软中断的次数 rx_rps/s 唤醒cpu的次数 flw_lim/s 达到流量限制的次数

sar -n TCP 1

19时14分45秒 active/s passive/s iseg/s oseg/s active/s:主动连接数 passive/s:被动连接数 iseg/s:每秒接收的段总数 oseg/s:每秒发送的段总数

sar -n ETCP 1

19时20分22秒 atmptf/s estres/s retrans/s isegerr/s orsts/s atmptf/s 重试失败数 estres/s 断开连接数 retrans/s 重传数 isegerr/s 错误数 orsts/s 包含RST flag的tcp段数

sar -n UDP 1

19时16分14秒 idgm/s odgm/s noport/s idgmerr/s idgm/s 每次接收的 UDP 数据报总数 odgm/s 每秒发送的 UDP 数据报总数 noport/s 接收到但是却没有应用程序在指定目的端口的数据个数 idgmerr/s 本机接收到但却无法派发的数据个数

七七八八总算整理完了sar命令的这些用法,但实际上工作中用不到这么多。或者sar的一些监控命令也可以通过其他命令实现。 不过需要留一个印象的是,如果想监控内存,缓存,CPU,IO,网络,中断这些通常需要监控的信息,可以尝试一下sar命令。

参考链接

https://www.man7.org/linux/man-pages/man1/sar.1.html

编辑
2024-01-11
工作知识
0

git提交建议

git commit一直没有一个规范,但是经常翻阅大型仓库例如linux kernel的都能感觉到commit是有一定规范的。为了让自己提交代码更合规点,这里整理了规范和一些注意事项(不一定正确哦),如下分享

我的模板

Module: SubModule: Brief description of the patch ################################################################################# # Reference: https://www.kernel.org/doc/html/v5.4/process/submitting-patches.html # Notice: # 1. Only one problem was solved. # 2. Full description and justification # 3. Only one problem per patch # # Example 1: # Module: SubModule: Brief description of the patch # # Example 2: # Module: SubModule: Brief description of the patch # # Detailed description (if desired) # # Example 3: # [PATCH] Foo: Fix these things # or # [PATCH v2] Foo: Fix these things better # or # [PATCH v3 0/2] comedi: Fix these things # [PATCH v3 1/2] comedi: Fix the first thing # [PATCH v3 2/2] comedi: Fix the second thing #################################################################################

上述是.gitmessage文件,这个文件需要在自己的目录~/.gitmessage
为了使得这个模板生效,可以git config --global commit.template ~/.gitmessage
这样,以后提交就可以按照这个模板了。

介绍内核补丁提交

vim设置

vim ~/.vimrc

filetype plugin indent on syntax on set title set tabstop=8 set softtabstop=8 set shiftwidth=8 set noexpandtab

命令如下
:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
update-alternatives --config editor

mutt设置

apt install esmtp touch ~/.esmtprc chmod g-rwx ~/.esmtprc chmod o-rwx ~/.esmtprc vim ~/.esmtprc identity "tangfengweny@gmail.com" hostname smtp.gmail.com:587 username "tangfengweny@gmail.com" password "邮箱密码" starttls required set sendmail="/usr/bin/esmtp" set envelope_from=yes set from="tangfeng <tangfengweny@gmail.com>" set use_from=yes set edit_headers=yes

git设置

vim ~/.gitconfig [user] name = tangfeng email = tangfengweny@example.com

更新内核

git fetch origin git rebase origin/yourbranch

checkpatch

apt-get install codespell python-ply python-git vim .git/hooks/post-commit #!/bin/sh exec git show --format=email HEAD | ./scripts/checkpatch.pl --strict --codespell chmod a+x .git/hooks/post-commit

这样提交时就默认检查补丁规范了./scripts/checkpatch.pl --strict --codespell

提交

确保提交的commit信息用 git log --oneline 能够清晰了解补丁内容

发送

了解对应提交的maintainer
git show HEAD | perl scripts/get_maintainer.pl --separator , -- nokeywords --nogit --nogit-fallback --norolestats 如果是特定文件 perl scripts/get_maintainer.pl --separator , --nokeywords --nogit -- nogit-fallback --norolestats -f drivers/staging/vt6655/baseband.c
不要直接把补丁发送到邮件列表,要先制作一封特殊的邮件。如下 git format-patch -o /tmp/ HEAD^ 先发给自己 mutt -H /tmp/0001-*.patch 也可以git发送

vim .gitconfig [sendemail] smtpserver = /usr/bin/esmtp git send-email --annotate HEAD^

对补丁进行版本控制

git format-patch --subject-prefix="PATCH v2"
如果需要对补丁额外修改,应该在补丁下添加---,然后开始解释,git工具会忽略---下面的内容 然后在补充内容后面加剪刀符>8-----8<这样文本会更加清晰 如下:

Signed-off-by: Your Name <my.email@gmail.com> --- Changes since v2: * Made commit message more clear * Corrected grammer in code comment * Used new API instead of depreciated API >8------------------------------------------------------8< drivers/staging/csr/bh.c

这里---下面的是补充的内容

制作补丁集

补丁集也就是对所有提交补丁的汇总,如下
git format-patch -n --subject-prefix="PATCH vY" --cover-letter
最后发送补丁集
git send-email --to <发给谁> --cc <addresses from get_maintainer.pl output> /tmp/*.patch
可以先--dry-run在本地实验后在发送
git send-email --to <发给谁> --cc <addresses from get_maintainer.pl output> -dry-run /tmp/*.patch

参考链接

https://kernelnewbies.org/FirstKernelPatch
https://kernelnewbies.org/PatchPhilosophy

编辑
2024-01-09
工作知识
0

了解/proc/vmstat

nr_free_pages 2596184 # 系统可用的页数 对应MemFree nr_zone_inactive_anon 489528 # 未活跃的页数 对应Inactive(anon) nr_zone_active_anon 599 # 对应Active(anon) nr_zone_inactive_file 516396 # 对应 Inactive(file) nr_zone_active_file 235058 # Active(file) nr_zone_unevictable 71526 # Unevictable nr_zone_write_pending 149 # dirty+writeback+unstable pages nr_mlock 8 # Mlocked nr_bounce 0 # Bounce nr_zspages 0 # allocated in zsmalloc nr_free_cma 0 # cma numa_hit 4634064 # allocated in intended node numa_miss 0 # allocated in non intended node numa_foreign 0 # was intended here, hit elsewhere numa_interleave 2880 # interleaver preferred this zone numa_local 4634064 # allocation from local node numa_other 0 # allocation from other node nr_inactive_anon 489528 # nr_zone_inactive_anon nr_active_anon 599 # nr_zone_active_anon nr_inactive_file 516396 # nr_zone_inactive_file nr_active_file 235058 # nr_zone_active_file nr_unevictable 71526 # nr_zone_unevictable nr_slab_reclaimable 32813 # SReclaimable nr_slab_unreclaimable 26640 # SUnreclaim nr_isolated_anon 0 # Temporary isolated pages from anon lru nr_isolated_file 0 # Temporary isolated pages from file lru workingset_nodes 0 workingset_refault_anon 0 workingset_refault_file 0 workingset_activate_anon 0 workingset_activate_file 0 workingset_restore_anon 0 workingset_restore_file 0 workingset_nodereclaim 0 nr_anon_pages 470838 # AnonPages nr_mapped 196874 # Mapped nr_file_pages 842283 # 文件缓存页 nr_dirty 149 # 脏页数 nr_writeback 0 # 回写页数 nr_writeback_temp 0 # WritebackTmp 文件系统的临时回写 nr_shmem 92614 # Shmem nr_shmem_hugepages 0 # ShmemHugePages nr_shmem_pmdmapped 0 # ShmemPmdMapped nr_file_hugepages 0 # FileHugePages nr_file_pmdmapped 0 # FilePmdMapped nr_anon_transparent_hugepages 0 # AnonHugePages nr_vmscan_write 0 # LRU内存回收写入页数 nr_vmscan_immediate_reclaim 0 # 优先回收的页数 nr_dirtied 515721 # page dirtyings since bootup nr_written 346168 # page dirtyings since bootup nr_kernel_misc_reclaimable 0 # reclaimable non-slab kernel pages nr_foll_pin_acquired 0 # via: pin_user_page(), gup flag: FOLL_PIN nr_foll_pin_released 0 # pages returned via unpin_user_page() nr_kernel_stack 12992 # KernelStack,kb单位 nr_page_table_pages 6858 # PageTables nr_swapcached 0 # swap cached nr_dirty_threshold 660577 # 脏页触发系统回写的阈值 nr_dirty_background_threshold 329885 # 脏页触发后台回写的阈值 pgpgin 2541198 # 从启动到现在读入的内存页数 pgpgout 1421761 # 从启动到现在换出的内存页数 pswpin 0 # 从启动到现在读入的交换分区页数 pswpout 0 # 从启动到现在换出的交换分区页数 pgalloc_dma 512 # 从启动到现在DMA存储区分配的页数 pgalloc_dma32 513 # 从启动到现在DMA 32位的存储区分配的页数 pgalloc_normal 4756880 # 从启动到现在普通存储区分配的页数 pgalloc_movable 0 # 可移除内存区 allocstall_dma 0 allocstall_dma32 0 allocstall_normal 0 allocstall_movable 0 pgskip_dma 0 pgskip_dma32 0 pgskip_normal 0 pgskip_movable 0 pgfree 7356348 # 从启动到现在释放的页数 pgactivate 365485 # 从启动到现在激活的页数 pgdeactivate 0 # 从启动到现在去激活的页数 pglazyfree 2336 pgfault 2896643 # 从启动到现在二级页面错误数 pgmajfault 6079 # 从启动到现在一级页面错误数 pglazyfreed 0 pgrefill 0 pgreuse 429609 # 不太理解,这里解释https://lkml.kernel.org/lkml/CAHk-=wgchPHqevEZ1radW1vLHKGGSaq_SCVHKgxHmQt70OSSfg@mail.gmail.com/ pgsteal_kswapd 0 pgsteal_direct 0 pgscan_kswapd 0 pgscan_direct 0 pgscan_direct_throttle 0 pgscan_anon 0 pgscan_file 0 pgsteal_anon 0 pgsteal_file 0 zone_reclaim_failed 0 pginodesteal 0 slabs_scanned 0 kswapd_inodesteal 0 kswapd_low_wmark_hit_quickly 0 kswapd_high_wmark_hit_quickly 0 pageoutrun 0 pgrotated 2 # 从启动到现在轮换的页面数 drop_pagecache 0 drop_slab 0 oom_kill 0 numa_pte_updates 0 numa_huge_pte_updates 0 numa_hint_faults 0 numa_hint_faults_local 0 numa_pages_migrated 0 pgmigrate_success 0 pgmigrate_fail 0 thp_migration_success 0 thp_migration_fail 0 thp_migration_split 0 compact_migrate_scanned 0 compact_free_scanned 0 compact_isolated 0 compact_stall 0 compact_fail 0 compact_success 0 compact_daemon_wake 0 compact_daemon_migrate_scanned 0 compact_daemon_free_scanned 0 htlb_buddy_alloc_success 0 htlb_buddy_alloc_fail 0 unevictable_pgs_culled 538811 unevictable_pgs_scanned 423920 unevictable_pgs_rescued 424015 unevictable_pgs_mlocked 202 unevictable_pgs_munlocked 194 unevictable_pgs_cleared 0 unevictable_pgs_stranded 0 thp_fault_alloc 0 thp_fault_fallback 0 thp_fault_fallback_charge 0 thp_collapse_alloc 0 thp_collapse_alloc_failed 0 thp_file_alloc 0 thp_file_fallback 0 thp_file_fallback_charge 0 thp_file_mapped 0 thp_split_page 0 thp_split_page_failed 0 thp_deferred_split_page 0 thp_split_pmd 0 thp_split_pud 0 thp_zero_page_alloc 0 thp_zero_page_alloc_failed 0 thp_swpout 0 thp_swpout_fallback 0 balloon_inflate 0 balloon_deflate 0 balloon_migrate 0 swap_ra 0 swap_ra_hit 0 direct_map_level2_splits 113 direct_map_level3_splits 2 nr_unstable 0

可以发现vmstat里面包含了很多的内存名词和信息,这些都是平时完全不知道的,要把内存这款了解透,得慢慢接触这些代码,配置和慢慢实践。上面分析vmstat过程中,很多不知道的,就没有细究了。因为还没那个功底去细究

编辑
2024-01-09
工作知识
0

了解/proc/meminfo

MemTotal: 16002428 kB # 内核和系统可以使用的内存大小 MemFree: 12692524 kB # 系统尚未使用的内存 MemAvailable: 14358188 kB # free+可以被回收的内存大小 Buffers: 64908 kB # 块设备的缓存页 Cached: 1990844 kB # 磁盘或文件系统的内存缓存 SwapCached: 0 kB # 交换分区的内存缓存 Active: 955104 kB # 最近比较活跃的内存,可回收的 Inactive: 1851012 kB # 不活跃的内存 Active(anon): 2160 kB # cache里面的匿名的活跃内存 Inactive(anon): 928056 kB # cache里面的匿名的不活跃内存 Active(file): 952944 kB # cache里面的活跃内存 Inactive(file): 922956 kB # cache里面的不活跃内存 Unevictable: 188200 kB # 被内核认为无法回收的内存 Mlocked: 0 kB # mlock锁住的内存 SwapTotal: 902700 kB # swap的内存 SwapFree: 902700 kB # swap的可用内存 Dirty: 0 kB # 等待回写的脏页 Dirty+NFS_Unstable+Writeback=脏页 Writeback: 0 kB # 正在回写的脏页 AnonPages: 938576 kB # 匿名页 Mapped: 434276 kB # 被映射的页,例如库,二进制,mmap过的 Shmem: 191716 kB # 共享内存或tmpfs或devtmpfs KReclaimable: 100012 kB # 内核可被回收的内存 Slab: 202148 kB # SReclaimable+SUnreclaim SReclaimable: 100012 kB # slab中可以被回收的内存 SUnreclaim: 102136 kB # slab中不可以被回收的内存 KernelStack: 9904 kB # 给用户线程分配的内核栈消耗的页 PageTables: 16356 kB # 页表占用内存,内存占用越多使用的页表就越多 NFS_Unstable: 0 kB # 给nfs 服务的缓存 Bounce: 0 kB # 给块设备的bounce buffers WritebackTmp: 0 kB # 给用户文件系统FUSE的临时回写内存 CommitLimit: 8903912 kB # 提交虚拟内存的最大大小,也就是虚拟内存的最大申请内存值 Committed_AS: 4856984 kB # 当前系统的虚拟内存分配量 VmallocTotal: 34359738367 kB # 可用于vmalloc申请的内存大小 VmallocUsed: 33552 kB # 已用的虚拟内存大小 VmallocChunk: 0 kB # 虚拟内存最大的连续块 Percpu: 8896 kB # 给percpu机制申请器使用的内存 HardwareCorrupted: 0 kB # 内核察觉出内存出错的大小计数 AnonHugePages: 2048 kB # 给用户空间的匿名大页 ShmemHugePages: 0 kB # 给shmem和tmpfs的大页 ShmemPmdMapped: 0 kB # 已映射过的shmem大页 FileHugePages: 0 kB # 映射文件的大页 FilePmdMapped: 0 kB # 已映射过的文件的大页 HugePages_Total: 0 # 总共大页内存大小 HugePages_Free: 0 # 剩余的大页大小 HugePages_Rsvd: 0 # 预申请的大页,也就是申请了没有的 HugePages_Surp: 0 # 大页池的剩余 Hugepagesize: 2048 kB # 大页大小 Hugetlb: 0 kB # Hugetlbfs 的大页使用清除 DirectMap4k: 235016 kB # 可以映射4k页面的数量 DirectMap2M: 4624384 kB # 可以映射2M页面的数量 DirectMap1G: 11534336 kB # 可以映射1G页面的数量

参考链接

https://www.kernel.org/doc/Documentation/filesystems/proc.rst http://linuxperf.com/?p=142 http://www.javashuo.com/article/p-dgjqhxgd-nc.html