AIX 性能调优

更新时间:2024-05-07 01:57:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

AIX 性能调优 内存篇之一 概念

序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-16 本章介绍和AIX内存相关的一些基本概念.

物理内存

物理存在的内存,查看命令: # prtconf |grep Memory Memory Size: 15936 MB Good Memory Size: 15936 MB

物理内存的分类

(1) persistent(长久型)和work(工作型)内存

Persistent型是指读入到内存的内容本身在文件系统是存在的,例如包含数据的文件,可执行文件; 工作型是指进程中的Stack,变量, 共享内存段等(working segments, as are the kernel text segment, the kernel-extension text segments, as well as the shared-library text and data segments. ),是进程中途产生的。Persistent型内存被page out的时候回写到文件系统中,work型内存被page out的时候回写到paging space中. 通过svmon可以看到这两种内存的类型. # svmon -G

size inuse free pin virtual

memory 4079616 3477314 602302 535874 894316 pg space 7995392 2915 work pers clnt

pin 535874 0 0 in use 894316 0 2582998 (2) Computational(计算型)和File(文件型)

Computational型内存包含working-storage segments or program text (executable files) segments. 也就是包括work(工作型)再加上persistent(长久型)中的可执行文件的部分. File(文件型)是除去计算型的所有内存. Computational型可以理解为读入可执行文件的地方,文件型可以理解为读入文件中的data部分. 可以通过topas看到这两种内存的类型. MEMORY

Real,MB 15936 % Comp 22.8 % Noncomp 63.3 % Client 63.8 (3) Client类型

Persistent类型的内存进一步被分类,其中client类型的内存被用于map remote files(例如通过NFS访问的文件). Enhanced JFS file system使用clients page来缓存cache,所以在上面的svmon的结果中看到实际没有persistent的值,而都是clnt的值, 因为用的都是Enhanced JFS 文件系统.

work pers clnt pin 535874 0 0 in use 894316 0 2582998

虚拟内存

虚拟内存是物理内存和Paging Space组合形成的虚拟内存空间,通过虚拟的地址空间映射到物理内存或者Paging Space.

Paging space

Paging space是系统的一个物理存储空间, 占用一定的磁盘空间, 可以是logical volume或者文件的形式. AIX内核需要利用 Paging Space 来管理虚拟内存。和内存页面一样,AIX的 Paging Space也是以4KB为单位,当实际内存数的空闲值低于一定数量以后,系统需要把实际内存中的某些计算页面(Computation Page)写回到Paging Space中(page out),以便释放出实际内存页面用于其他程序。查看当前paging space的命令: # lsps -a

Page Space Physical Volume Volume Group Size %Used Active Auto Type

hd6 hdisk1 rootvg 31232MB 1 yes yes lv

Page Fault

If the access is going to a page of virtual memory that is stored over to disk, or has not been brought in yet, a page fault occurs, and the execution of the program is suspended until the page has been read from disk. 查看page fault的命令: # sar -r 5

System configuration: lcpu=8 mem=15936MB 10:28:12 slots cycle/s fault/s odio/s 10:28:17 7992467 0.00 3.39 0.20

pi(Page In)

The number of pages paged in from paging space. 从paging space page到内存中的page数目, 这些页必定以前被page out到page space中的. 通过vmstat查看 # vmstat

System configuration: lcpu=8 mem=15936MB

kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------- r b avm fre re pi po fr sr cy in sy cs us sy id wa

1 1 894750 601858 0 0 0 2 3 0 15 861 286 0 0 99 1

po(Page Out)

The number (rate) of pages paged out to paging space. 如果持续看到po但是没有看到pi的增长,并不一定代表出现了Thrashing, 比如 系统正在读取大量的persistent pages会导致看到大量的page out, 这时候需要查看一下应用的类型. 被page out出去的数据,如果有进程需要再次reference的时候,将产生page fault,然后通过page in再次写入到内存. 通过vmstat查看

Thrashing

表示系统连续地paging in和out, 经常是系统缺乏内存的现象.

Repage

Page fault可以是一个新的page fault,也可以是一个repage fault. A new page fault occurs when there is no record of the page having been referenced recently. A repage fault occurs when a page that is known to have been referenced recently is referenced again, and is not found in memory because the page has been replaced (and perhaps written to disk) since it was last accessed. 发生一次page fault是正常机制,但应该避免发生多次的page fault,AIX在这里是做了一种统计,分别统计计算型和非计算型内存发生repage的count,我们可以用vmtune去调整这两种内存的page的机制(vmtune -p -P). AIX 性能调优 内存篇之二 Paging Space 序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-17 本章介绍和AIX Paging Space相关的知识

部分内容来源:

http://www-900.ibm.com/cn/support/nav/200234/p58.shtml

http://www.ibm.com/developerworks/cn/aix/library/au-cn-pagingspace/index.html

Paging Space的管理机制

在AIX 4.3.2及以后版本中,操作系统提供了3种 Paging Space的管理机制:

? ? ?

Deferred Page Space Allocation (DPSA) Late Page Space Allocation (LPSA) Early Page Space Allocation (EPSA)

(1) Deferred Page Space Allocation (DPSA)

在AIX4.3.2之后,DPSA是系统默认的Paging Space的管理机制。在这种机制下,系统不会为进程保留任何的 page 页面,直到系统确认确实需要将内存中的页面 page out 到Paging Space中,才会把Paging Space的页面分配给该进程。

DPSA是AIX 4.3.2及以后版本中所使用的默认机制,它通常适用于配有很大容量RAM 的系统,因为它可以减少很多Paging Space资源的浪费。 这也是为什么当前的系统看不到大量paging space分配的原因. (2) Late Page Space Allocation (LPSA)

在AIX 4.2.1之后, 4.3.2之前,操作系统默认使用 LPSA 机制。这种机制是指当进程启动后,系统并不在Paging Space中为该进程保留相应的页面。只有当该进程的实际内存页面被修改过后,才会在Paging Space中为这些被修改过的页面申请空间。其中” 内存页面被修改”的含义:例如通过bzero()函数修改分配的内存的时候,或者调用calloc(),或者内存被初始化某些值的时候, 系统会为这些working page在paging space中保留相应的页面. 这种机制在一定程度上减少了Paging Space的空间浪费,但是对系统也存在一定的风险。比如,当一些后起的进程用了几乎全部的Paging Space后,由于先起的进程并没有保留足够的Paging Space空间用于进程的page out操作,会导致该进程被杀掉。 (3) Early Page Space Allocation (EPSA)

在AIX系统中,当Paging Space的使用率达到一定百分比时,系统就无法将需要 page out的页面写到Paging Space中,这时候,该进程就很可能被杀掉。为了避免这种情况的发生,EPSA机制会保证当进程被启动时,在Paging Space中先申请一块页面空间,该空间大小与该进程所需要占用的实际内存的大小一致 (将环境变量 PSALLOC设为early,

也就是“export PSALLOC=early”)。这样就保证当进程使 用malloc()调用的同时,在Paging Space中有相应的空间保留给该进程,从而保 证该进程的page out 操作。

这种机制虽然可以保证现有的进程安全,但由于很多被保留的页面空间并没有被用到,造成了非常大的空间浪费。同时,也需要Paging Space的大小比实际内存值要大很多。 EPSA在以前版本操作系统中使用比较多,主要的原因当时的系统物理内存比较少,一般都少于512M,在少内存的情况下EPSA会使系统进程的调度更加安全. (4) 相关命令

?

查看当前系统采用的paging space的机制

# vmo -a |grep defps defps = 1

defps=1表示采用的是DPSA,如果defps=0表示采用的是LPSA.

?

修改paging space的机制,采用LPSA

# vmo -o defps=0

?

查看defps属性

当前值是1,缺省值是1,启动时的值是1, 取值范围是0-1,类型是动态可以修改的. # vmo -L defps

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

-------------------------------------------------------------------------------- defps 1 1 1 0 1 boolean D

--------------------------------------------------------------------------------

?

vmo Tips

VMO Man page -L [ Tunable ]

Lists the characteristics of one or all tunables, one per line, using the following format:

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES -------------------------------------------------------------------------------- memory_frames 128K 128K 4KB pages S --------------------------------------------------------------------------------

maxfree 1088 1088 130 16 200K 4KB pages D minfree memory_frames

--------------------------------------------------------------------------------

minfree 960 960 122 8 200K 4KB pages D maxfree memory_frames -------------------------------------------------------------------------------- ... where:

CUR = current value DEF = default value BOOT = reboot value MIN = minimal value MAX = maximum value UNIT = tunable unit of measure

TYPE = parameter type: D (for Dynamic), S (for Static), R for Reboot), B (for Bosboot), M (for Mount), I (for Incremental), C (for Connect), and d (for Deprecated) DEPENDENCIES = list of dependent tunable parameters, one per line

Paging-space thresholds tuning

如果paging space少到一定的空间,操作系统将会通过先告警进程释放paging space,最后可能会kill进程.相关的两个参数npswarn和npskill: # vmo -a |grep npswarn npswarn = 249856 # vmo -h npswarn

Help for tunable npswarn:

Specifies the number of free paging-space pages at which the operating system begins sending the SIGDANGER signal to processes. Default: MAX (512,4*npskill). 大于0小于系统paging space的数目. Increase the value if you experience processes being killed because of low paging space.

# vmo -a |grep npskill npskill = 62464 # vmo -h npskill Help for tunable npskill:

Specifies the number of free paging-space pages at which the operating system begins killing processes. Default: MAX (64, number_of_paging_space_pages/128). 大于0小于系统paging space的数目.

Paging space garbage collection

AIX 5.3之后可以利用paging space garbage collection机制来free up paging space. 只作用于deferred page space allocation policy.

?

方法一: re-pagein 后的垃圾收集

The method of freeing a paging-space disk block after a page has been read back into memory from paging space is employed by default. 相关参数: npsrpgmin: 停止re-pagein垃圾收集的free paging space blocks数目 npsrpgax: 开始re-pagein垃圾收集的free paging space blocks数目

?

方法二: scrubbing memory

Another method of paging space garbage collection is by scrubbing memory, which is implemented with the psgc kernel process. The psgc kernel process frees up paging space disk blocks for modified memory pages that have not yet been paged out again or for unmodified pages for which a paging space disk block exists. 相关的参数: npsscrubmin 停止scrubbing内存的free paging space blocks数目

npsscrubmax: 开始scrubbing内存的free paging space blocks数目 # vmo -a |grep nps npskill = 62464 npsrpgmax = 499712 npsrpgmin = 374784 npsscrubmax = 499712 npsscrubmin = 374784 npswarn = 249856

Paging Space的创建原则

AIX中Paging Space大小确定的指导原则如下(理论上):

? ? ? ?

系统实际内存小于64MB, paging space= 2 * RAM ;

系统实际内存在 64MB to 256MB 之间, Page Space = RAM size + 16MB ; 系统实际内存大于 256MB , Page Space = 512 + ( RAM - 256 ) * 1.25 ; 当内存超过4GB时,则需要根据实际情况来定,一般可初始3GB, 然后观察paging space的使用情况,如果使用率超过70%, 则需要增加paging space 。

此外在创建Paging Space时还应遵循以下原则以提高性能:

? ? ?

创建的数量应尽可能的多;

每个Paging Space的大小应该相同;

每个Paging Space应尽可能的分配在不同的硬盘上。

工程和维护建议(目前内存和硬盘都比较大,相对比较实用些):

如果硬盘空间不是问题的话,建议可以是内存的两倍.如果内存大于8G或者16G,可以考虑先和内存空间相同. 同时用两块不同的内置盘各分配一半的paging space空间. 对于做了根盘镜像的系统,建议可以不镜像paging space(维护时注意这些特点). 大的swap空间可以避免DPSA可能产生的风险,对于运维来说可能可以减少相关的维护分析工作.

Paging Space命令

AIX中可以通过命令lsps -s查看Paging Space的使用情况。列Total Paging Space给出的是系统总的Paging Space空间大小,Percent Used则表示已被占用的Paging Space的百分比。

# lsps -a

Page Space Physical Volume Volume Group Size %Used Active Auto Type hd6 hdisk1 rootvg 31232MB 1 yes yes lv AIX 性能调优 内存篇之三 内存工作机制 序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-18 本章介绍和AIX内存工作机制 部分内容来源:

http://www-900.ibm.com/cn/support/viewdoc/detail?DocId=2611084C28000

AIX 5L v 5.3 Performance management官方文档

虚拟内存管理器(VMM)

VMM services all memory requests from the system. 当内存被申请的时候(Working类型),对于early allocation of paging space policy情况下,在RAM被访问的时候,不管是否还有多少物理剩余空间,都会有paging space被分配,在这种情况下VMM起到了关键的作用.(不过目前系统缺省的paging space的分配原则是DPSA).

虚拟地址空间划分成段。每段的大小是 256 MB,它是虚拟内存地址空间中一个邻接的部分,数据对象可映射到该空间。虚拟内存段划分成固定大小的单元叫做页。缺省页面大小是 4096 字节。段中的每页在需要之前可位于实际内存(RAM)中,或存储在磁盘上。同样,实际内存也可以划分成 4096 字节的page frame。

VMM 的角色是管理分配实际内存页面帧并且解析程序对虚拟内存页面的引用,这些虚拟内存页面当前不在实际内存中或还不存在(例如,当进程第一次引用其数据段的某一页时)。

因为在任何给定时刻使用的虚拟内存数量可能比实际内存大,所以 VMM 必须将余量存储在磁盘上。VMM的两个目标:

? ?

最小化使用虚拟内存的总处理器时间和磁盘带宽代价 最小化page fault的响应时间代价

VMM 维护一个页面帧的空闲列表,它可用于补偿page fault。VMM 使用了一个页面替换算法来确定当前处于内存中的哪些虚拟内存页要将它们的page frmaes重新指定到空闲列表中。页面替换算法使用了几个机制:

? ? ? ? ? ?

虚拟内存段分成持久段persistent或工作work段。

虚拟内存段分成包含计算computational内存或文件file内存。 跟踪在访问时引起page fault的虚拟内存页。 page fault分成new page fault或repage faults。 在每个虚拟内存段中维护一个repage faults率的统计信息。 用户可调阈值影响页面替换算法的结果。

Free List

VMM 维护一个空闲页面帧的逻辑列表,它用于解决缺页故障。在绝大多数环境中,VMM 偶尔必须通过reasign由运行进程占有的一些页面帧来添加到空闲列表中。需要reasign页面帧的虚拟内存页由 VMM 的页面替换算法进行选择。VMM 阈值决定了重新指定的帧的数量。

查看Free list的方法: # vmstat

System configuration: lcpu=8 mem=15936MB

kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------- r b avm fre re pi po fr sr cy in sy cs us sy id wa

1 1 894790 601757 0 0 0 2 3 0 15 861 286 0 0 99 1

# svmon -G

size inuse free pin virtual

memory 4079616 3477911 601705 535886 894842 pg space 7995392 2916 work pers clnt pin 535886 0 0 in use 894842 0 2583069

PageSize PoolSize inuse pgsp pin virtual s 4 KB - 3399607 2916 484734 816538 m 64 KB - 4894 0 3197 4894

页面替换Page replacement

当空闲列表中可用的实际内存帧数量减少时就会调用一个页面替换器(stealer)。页面替换器在整个页面帧表(PFT)中移动,寻找可替换(steal)的页面。

PFT 中包含一些标志用来表示哪些页已经被引用,哪些页已经被修改。如果页面替换器遇到一个已经引用的页,它不会替换这个页而是为该页重新设置引用标志。在下一次钟针(页面替换器)经过该页且引用位仍未启用时,它便被替换。初次通过时未被引用的页面会立即得到替换。修改标志表示该页进入内存后上面的数据已经改变。当页面要被替换时,如果设置了修改标志,那么在替换该页之前进行页面调出调用。属于工作段的页面写入调页空间;而持久段中的页面写到磁盘上。

上图中: 第一个表是具有四列的页面帧表,它包含实际地址、段类型、引用标志和修改标志。第二个表叫做空闲列表,它包含所有空闲页的地址。最后一个表代表除去所有空闲地址后最终得到的页面帧表。

除了页面替换以外,算法还可通过使用一个包含最近缺页故障标识的历史缓冲区来跟踪新页故障(第一次引用)和重新调页故障(引用已经调出的页)。然后它可以尽量平衡文件(持久数据)页面的调出和计算(工作存储器或程序文本)页面的调出。

当进程退出时,它的工作存储器立刻释放并且它的关联内存帧也放回到空闲列表中。然而由该进程打开的任何文件可保留在内存中。

如果线程在单处理器上运行,那么页面替换可直接在线程作用域中进行。在多处理器系统中,页面替换通过内核进程 lrud 进行,在达到阈值 minfree 时,该进程被分派到 CPU 中。从 AIX 4.3.3 开始,内核进程 lrud 是多线程的,每个存储池中一个线程。根据 CPU 数量和 RAM 大小将实际内存划分成平均大小的存储池。系统中存储池的数量可通过运行命令 vmo -a 来确定。

数值 minfree 和 maxfree 在命令 vmo 的输出中,它们是每个存储池的 minfree 和 maxfree 的总和。

# vmo -a |grep mempools mempools = 2

重新调页(Repaging)

Page faults要么是new page fault要么是repage fault。如果没有最近引用页面的记录的话,会出现一个new page fault。而出现repage faults是指一个知道其最近已经引用的页再次被引用,但由于该页在上次访问后已经被替换(可能写到磁盘上)而在内存中找不到它。

理想的页面替换策略通过总是替换那些不会再次引用的页面帧而完全减少repage faults(假设有足够的实际内存)。因而repage faults数是页面替换算法有效性的一个相反评测标准,算法将频繁被重用的页面保存在内存中,从而降低了总体 I/O 需求并潜在地改善了系统性能。

为了分清一个缺页故障是新页故障还是重新调页故障,VMM 维护一个重新调页历史记录缓冲区,它包含 N 个最近缺页故障的页面标识,其中 N 是内存可保留的帧数。例如,512 MB 内存需要一个 128 KB 的repage faults历史记录缓冲区。在页面调进时,如果它的标识可在重新调页历史记录缓冲区中找到,则将它计为一个重新调页。VMM 还可以分别评估计算内存重新调页率和文件内存重新调页率,只需为每种类型的内存维护repage faults计数即可。每次页面替换算法运行时都将重新调页率乘以 0.9,这样可比历史重新调页活动更有力地反映最近的重新调页活动。

AIX 性能调优 内存篇之四 调优参数

序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-20 本章介绍和AIX内存调优相关的参数 minfree和maxfree (1) minfree

空闲列表中可接受的实际内存页面帧的最小数量。当空闲列表的大小低于这个数时,VMM 开始替换页面。它将一直替换页面直到空闲列表的大小达到 maxfree。

# vmo -a |grep minfree minfree = 960 (2) maxfree

当free list的大小超过maxfree的时候, VMM的page stealing将停止. 当进程终止并释放它们的工作段页面或删除其页面在内存中的文件时,结果是空闲列表的大小可能会超过这个数。

# vmo -a |grep maxfree maxfree = 1088

从AIX 5.3开始, minfree parameter的缺省值 is increased to 960 per memory pool and maxfree parameter的缺省值 is increased to 1088 per memory pool.

minperm%, maxperm%和maxclient% (1) minperm%

如果由文件页面占有的实际内存的百分比低于这个级别,则页面替换算法既替换文件页面也替换计算页面,而不管repage rate。 # vmo -a |grep minperm% minperm% = 20

(2) maxperm%

如果由文件页面占有的实际内存的百分比高于这个级别,则页面替换算法仅替换文件页面。 # vmo -a |grep maxperm% maxperm% = 80

(3) maxclient%

如果由文件页面占有的实际内存的百分比高于这个级别,则页面替换算法仅替换客户机页面。 # vmo -a |grep maxclient% maxclient% = 80

当由文件页面占有的实际内存的百分比处于 minperm 和 maxperm 之间时,VMM 通常只替换文件页面,但是如果文件页面的重新调页(repaging)率高于计算页面的重新调页率的话,计算页面也被替换。页面替换算法的主要意图是确保计算页面得到合理的待遇。例如,对于可能会很快再次使用的程序文本页,顺序读取长的数据文件到内存中应该不会使它们丢失。对阈值和重新调页率使用页面替换算法可确保合理地对待这两种类型的页面,但仍稍微偏向有利于计算页面的一方。

通过vmstat -v可以看到当前persistent或者client page的数目和百分比,可以作为系统调优的依据. # vmstat -v

4079616 memory pages 3870685 lruable pages 601736 free pages 2 memory pools 535883 pinned pages 80.0 maxpin percentage 20.0 minperm percentage 80.0 maxperm percentage 66.2 numperm percentage 2565739 file pages

0.0 compressed percentage 0 compressed pages 66.7 numclient percentage 80.0 maxclient percentage 2583086 client pages

0 remote pageouts scheduled

28222 pending disk I/Os blocked with no pbuf 0 paging space I/Os blocked with no psbuf

2740 filesystem I/Os blocked with no fsbuf 0 client filesystem I/Os blocked with no fsbuf

106338 external pager filesystem I/Os blocked with no fsbuf

List-based LRU (page_steal_method)

在AIX 5.3, LRU算法可以用lists或者page frame table,在AIX 5.3之前,只有page frame table的算法, The list-based algorithm provides a list of pages to scan for each type of segment. 下面是段类型的列表:

? ? ? ?

Working Persistent Client Compressed

# vmo -a |grep page_steal_method page_steal_method = 0

如果page_steal_method = 1, 将采用list-based LRU算法, 如果

page_steal_method parameter 为 0, 将采用physical-address-based scanning的方式. page_steal_method参数值只有在bosboot and reboot后生效. # vmo -L page_steal_method

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

------------------------------------------------------------------------------- page_steal_method 0 0 0 0 1 boolean B -------------------------------------------------------------------------------

strict_maxperm

缺省为0. 当strict_maxperm 设置成 1, places a hard limit on how much memory is used for a persistent file cache by making the maxperm value be the upper limit for this file cache. 当达到上线的时候least recently used (LRU)将执行在persistent pages上.

# vmo -a |grep strict_maxperm strict_maxperm = 0

Enhanced JFS file system cache 相关的参数: maxclient, strict_maxclient和lru_file_repage

Enhanced JFS file system cache使用client page来作为buffer cache,通过maxclient%来控制page stealing. 如果strict_maxlient设置为0, maxclient%将用来作为一个soft limit. 也就是说client pages可以超过maxclient参数,如果超过这个值,只有client file page被stolen.

当lru_file_repage设置为1的时候,如果client pages的数目介于minperm和maxclient之间, LRU算法将参考repage的计数. 最近没有被referenced的page将被stolen. If the value of the file repage counter is higher than the value of the computational repage counter, computational pages, which are the working storage, are selected for replacement. If the value of the computational repage counter exceeds the value of the file repage counter, file pages are selected for replacement.

当lru_file_repage设置为0的时候, 如果client pages的数目大于minperm,将选择file pages被替换.如果小于minperm,任何没有被referenced的page将被替换. 注意:maxclient同样影响NFS client和compressed pages. # vmo -a |grep lru_file_repage lru_file_repage = 1 # vmo -a |grep strict_maxclient strict_maxclient = 1 工程经验

内存调优主要集中在几个关键参数中,往往这几个关键参数就能很大地提高系统的内存使用性能. 这几个参数是minperm%, maxperm%, maxclient%和lru_file_repage. 原则:首先了解你的应用类型,是文件读写型还是数据库类型. 尽量保证你的应用运行所需要的数据充分地利用物理内存. 具体的工程Tips例子请参见内存调优的工程经验篇.

AIX 性能调优 内存篇之五 常用命令一 序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-20 本章介绍和AIX内存调优用到的常用命令.

vmstat

# vmstat

System configuration: lcpu=8 mem=15936MB

kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------- r b avm fre re pi po fr sr cy in sy cs us sy id wa 1 1 894941 601322 0 0 0 2 3 0 15 862 286 0 0 99 1 avm Active virtual pages

avm定义为the number of virtual-memory working segment pages that have actually been touched. 此值可能会比实际物理内存的frame要大,因为一些active virtual memory可能会被写入到paging space中. 表示的是当前进程使用的stack,变量,共享内存段等类型的内存,但是不包括进程可能打开的文件所占用的内存. fre Size of the free list

fre物理内存实际剩余的page数目 pi Pages paged in from paging space po Pages paged out to paging space 正常情况下pi和po不应该持续为非0值; fr Pages freed (page replacement).

sr Pages scanned by page-replacement algorithm 正常情况下fr和sr基本一致;

r Average number of runnable kernel threads over the sampling interval. Runnable refers to threads that are ready but waiting to run and to those threads already running. 正常情况下一般r<5

b Average number of kernel threads placed in the VMM wait queue (awaiting resource, awaiting input/output) over the sampling interval.

wa CPU idle time during which the system had outstanding disk/NFS I/O request(s). See detailed description above.

b和wa正常的情况下都不大,高的wa(I/O wait)和高的b(在队列中等待的线程数目)有可能是paging in和out导致的. 工程经验

?

avm可以作为长期监控系统内存使用率的趋势分析,如果你有监控软件, 长时间监控avm可以给你很好的内存使用的趋势. 虽然它不代表实际系统用了多少内存,但是作为趋势判断还是非常有效的.

? 判断内存是否缺少内存的一个工程依据: fre少于minfree并且有持续的page in和page out出现.

其它的值:fr,sr,r,b,wa可以作为一些参考的值.

?

# vmstat -s

531921073 total address trans. faults 298718704 page ins 66764084 page outs

0 paging space page ins 0 paging space page outs 0 total reclaims

207574145 zero filled pages faults 32015 executable filled pages faults 53623328 pages examined by clock

28 revolutions of the clock hand 33577399 pages freed by the clock 11549684 backtracks 5631 free frame waits 0 extend XPT waits 5033034 pending I/O waits 365484303 start I/Os 10744732 iodones

4779271208 cpu context switches 249867457 device interrupts 870241057 software interrupts 3789663540 decrementer interrupts 990224 mpc-sent interrupts 990224 mpc-receive interrupts 2787163 phantom interrupts 0 traps

14370171283 syscalls page ins

Incremented for each page read in by the virtual memory manager. The count is incremented for page ins from page space and file space. Along with the page out statistic, this represents the total amount of real I/O initiated by the virtual memory manager. page outs

Incremented for each page written out by the virtual memory manager. The count is incremented for page outs to page space and for page outs to file space. Along with the page in statistic, this represents the total amount of real I/O initiated by the virtual memory manager. paging space page ins

Incremented for VMM initiated page ins from paging space only. paging space page outs

Incremented for VMM initiated page outs to paging space only. 工程经验

作为page ins, page outs, paging space page ins和paging space page outs,应该不会有大量的增长.

# vmstat -v

4079616 memory pages 3870685 lruable pages 600851 free pages 2 memory pools 536705 pinned pages 80.0 maxpin percentage 20.0 minperm percentage 80.0 maxperm percentage 66.2 numperm percentage 2566023 file pages

0.0 compressed percentage 0 compressed pages 66.7 numclient percentage 80.0 maxclient percentage 2583370 client pages

0 remote pageouts scheduled

28819 pending disk I/Os blocked with no pbuf 0 paging space I/Os blocked with no psbuf 2740 filesystem I/Os blocked with no fsbuf

0 client filesystem I/Os blocked with no fsbuf

109158 external pager filesystem I/Os blocked with no fsbuf 工程经验

numperm 和numclient是一个比较好的系统信息,表示的是当前内存中基于文件的page占的百分比. 从中可以判断当前可能的page replacement的机制. 如果numperm和numclient在minperm和maxperm/maxclient之间, 参考lru_file_repage, 如果lru_file_repage=0, 将先replace文件类型的page, 如果lru_file_repage=1, 系统会平衡计算型和文件型page的repage情况来决定

svmon

# svmon -G

size inuse free pin virtual

memory 4079616 3478350 601266 536696 894957 pg space 7995392 2909

work pers clnt pin 536696 0 0 in use 894957 0 2583393

PageSize PoolSize inuse pgsp pin virtual s 4 KB - 3400046 2909 485544 816653 m 64 KB - 4894 0 3197 4894 上面的数值以page为单位(4K) 其中:

Memory size: 表示物理内存的大小; Memory inuse表示当前使用了内存的大小,包括所有work和persistent类型的内存; Memory Free表示剩余的物理内存,这个值和vmstat的free list是一致的; Memory pin表示被使用的内存有多少是不能被page out(一般是系统预留的内存); Memory Virtual表示的active virtual memory,和vmstat中的avm一致.

In use work表示的是正在使用的work类型的内存; in use pers表示的是正在使用的persistent类型的内存(JFS类型); in use clnt表示的正在使用的client类型的内存(包括remote文件系统和Enhanced JFS类型)

# svmon -P

Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd 16MB 254008 java 191578 7530 5135 194273 N Y N

PageSize Inuse Pin Pgsp Virtual s 4 KB 191204 7530 5120 193861 m 64 KB 374 0 15 412

Vsid Esid Type Description PSize Inuse Pin Pgsp Virtual 344e9 3 work working storage s 65503 0 636 65525 244ed 4 work working storage s 65001 0 768 65536 204ec 5 work working storage s 48632 0 3646 50930 0 0 work kernel s 11399 7468 19 11417 330ad d work shared library text m 374 0 15 412 457f8 - clnt /dev/hd10opt:40966 s 256 0 - - 284ee f work working storage s 192 0 9 213 3c4eb - work s 171 59 39 205 384ea 2 work process private s 32 3 3 35 3c4 1 clnt code,/dev/hd10opt:47099 s 18 0 - - 6863e - clnt /dev/hd10opt:52836 s 0 0 - - 30628 - clnt /dev/hd10opt:50981 s 0 0 - - …… Vsid

Indicates the virtual segment ID. Identifies a unique segment in the VMM Esid

Indicates the effective segment ID. The Esid is only valid when the segment belongs to the address space of the process. 列出内存占用率排名前15名的进程和相关信息.

# svmon -Pt15 | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}'

------------------------------------------------------------------------------- Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd 16MB 254008 java 191539 7530 12956 194382 N Y N 319610 dsmc 48382 7476 7361 28925 N Y N 258184 dsmserv 31846 7526 8294 34638 Y Y N 336062 kulagent 14134 7490 1882 15755 Y Y N 217194 hostmibd64 14115 7471 1884 15590 Y N N 344078 kuma610 14024 7499 3360 17020 Y Y N 286776 kuxagent 13986 7488 2536 16296 Y Y N 155768 IBM.CSMAgentR 13445 7487 675 13843 N Y N 184420 snmpmibd64 13224 7471 1929 14749 Y N N 458810 stat_daemon 12921 7471 1922 14618 Y N N 417992 svmon_back.64 12746 7471 1813 14341 Y N N 352382 kux_vmstat 12724 7471 1913 14428 Y N N 340132 ifstat 12724 7471 1876 14393 Y N N 127050 shlap64 12706 7471 1880 14367 Y N N 413938 nfs_stat 12698 7471 1844 14332 Y N N -t Count

Displays memory usage statistics for the top Count object to be printed 64-bit

Indicates if the process is a 64 bit process (Y) or a 32 bit process (N) Mthrd

Indicates if the process is multi-threaded (Y) or not (N). 16MB

Indicates the 16MB page status of the process. \\means that the process does not use 16MB pages. 工程经验

svmon –P是一个很好的监控单独进程内存利用率的命令. 它也可以用来作为检查程序是否有内存泄漏的一个重要工具.

ps

#ps v 254008

PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND

254008 - A 193:26 50425 729316 717376 32768 39 72 0.0 29.0 /opt/IBM SIZE(单位1KB)

(v flag) The virtual size of the data section of the process (in 1KB units). 被分配的working segment pages, size大小的计算公式:

729316=(65536+65525+51020+213+35)*4, 后者是svmon输出的结果(Virtual),包括物理内存和paging space. RSS

(v flag) The real-memory (resident set) size of the process (in 1KB units).包括所有在内存中的的working segment和code segment. Rss大小的计算公式: 717376=(65111+65001+48991+191+32+18)*4, 后者是svmon输出中inuse对应的值. TRS

(v flag) The size of resident-set (real memory) of text. TRS的计算公式: 72=18*4,表示的是程序段在内存中的大小

计算公式

SIZE = 4 * Virtual of (work lib data + work private)

RSS = 4 * Inuse of (work lib data + work private + pers code) TRS = 4 * Inuse of (pers code) # svmon -P 254008|more

------------------------------------------------------------------------------- Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd 16MB 254008 java 191539 7530 12956 194382 N Y N

PageSize Inuse Pin Pgsp Virtual s 4 KB 191145 7530 12941 193951 m 64 KB 394 0 15 431

Vsid Esid Type Description PSize Inuse Pin Pgsp Virtual 244ed 4 work working storage s 65111 0 697 65536 344e9 3 work working storage s 65001 0 5434 65525 204ec 5 work working storage s 48991 0 6719 51020 0 0 work kernel s 11397 7468 21 11417 330ad d work unused segment m 394 0 15 431 114ed - clnt /dev/hd10opt:40960 s 238 0 - - 284ee f work working storage s 191 0 12 213 3c4eb - work s 162 59 55 205 384ea 2 work process private s 32 3 3 35 3c4 1 clnt code,/dev/hd10opt:47099 s 18 0 - - 4725 - clnt /dev/hd10opt:53347 s 2 0 - -

AIX 性能调优 内存篇之五 常用命令二 序号 版本号 更改人 日期 备注 1 1.0版 bldmickey 2007-06-20 本章介绍和AIX内存调优用到的常用命令,继续内存篇常用命令一

Topas

# topas MEMORY Real,MB 3920 % Comp 44.6 % Noncomp 5.6 % Client 6.9

计算型的和非计算型的,剩余的就是free的内存. PAGING SPACE Size,MB 8192 % Used 1.0 % Free 98.9

查看所有进程的信息. # topas -D

Topas Monitor for host: XXX Interval: 2 Fri Jun 22 15:42:12 2007 DATA TEXT PAGE PGFAULTS

USER PID PPID PRI NI RES RES SPACE TIME CPU% I/O OTH COMMAND

root 254008 1 60 20 179326 18 182329 193:28 0.1 0 0 java root 344078 1 60 20 1173 243 2758 5:49 0.0 0 108 kuma610

root 397376 225504 58 41 298 102 298 0:00 0.0 0 0 topas root 352382 458810 60 20 162 15 270 14:43 0.0 0 110 kux_vmst

root 69666 0 37 41 192 0 240 44:10 0.0 0 0 gil root 266386 1 60 20 21 17 101 27:48 0.0 0 0 getty root 336062 1 60 20 1436 96 1531 1:23 0.0 0 0 kulagent

root 12294 0 17 41 96 0 112 0:38 0.0 0 0 sched root 188538 135356 48 8 76 64 102 4:51 0.0 0 0 xntpd

root 65568 0 36 41 96 0 112 0:46 0.0 0 0 netm root 319610 430160 60 20 9791 1639 17063 173:53 0.0 0 0 dsmc

root 258184 270468 60 20 14451 4657 20262 158:41 0.0 0 0 dsmserv

root 94312 1 60 20 121 2 128 149:23 0.0 0 0 syncd root 16392 0 16 41 64 0 128 6:38 0.0 0 0 lrud root 155768 135356 60 20 1278 275 1934 5:13 0.0 0 0 IBM.CSMA

root 286776 1 60 20 1244 146 2077 3:28 0.0 0 0 kuxagent

root 413938 458810 60 20 139 12 174 3:23 0.0 0 0 nfs_stat

root 458810 286776 60 20 334 40 460 1:14 0.0 0 0 stat_dae

root 49176 0 60 41 96 0 112 1:04 0.0 0 0 xmgc root 1 0 60 20 70 10 187 0:57 0.0 0 0 init

vmo

查看内核的参数 # vmo -a

cpu_scale_memp = 8 data_stagger_interval = 161 defps = 1 force_relalias_lite = 0 framesets = 2 htabscale = n/a kernel_heap_psize = 4096 large_page_heap_size = 0 lgpg_regions = 0 lgpg_size = 0 low_ps_handling = 1 lru_file_repage = 1 lru_poll_interval = 10 lrubucket = 131072 maxclient% = 80 maxfree = 1088 maxperm = 768483 maxperm% = 80 maxpin = 810654 maxpin% = 80

mbuf_heap_psize = 65536 memory_affinity = 1

memory_frames = 1003520 memplace_data = 2 memplace_mapped_file = 2 memplace_shm_anonymous = 2 memplace_shm_named = 2 memplace_stack = 2 memplace_text = 2 memplace_unmapped_file = 2 mempools = 1 minfree = 960 minperm = 192120 minperm% = 20 nokilluid = 0 npskill = 16384 npsrpgmax = 131072 npsrpgmin = 98304 npsscrubmax = 131072 npsscrubmin = 98304 npswarn = 65536 num_spec_dataseg = 0 numpsblks = 2097152 page_steal_method = 0 pagecoloring = n/a pinnable_frames = 838649

pta_balance_threshold = n/a relalias_percentage = 0 rpgclean = 0 rpgcontrol = 2 scrub = 0 scrubclean = 0 soft_min_lgpgs_vmpool = 0 spec_dataseg_int = 512 strict_maxclient = 1 strict_maxperm = 0 v_pinshm = 0 vm_modlist_threshold = -1 vmm_fork_policy = 1 vmm_mpsize_support =

查看内核参数的含义 -L [ Tunable ]

Lists the characteristics of one or all tunables, one per line, using the following format:

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

-------------------------------------------------------------------------------- memory_frames 128K 128K 4KB pages S

-------------------------------------------------------------------------------- maxfree 1088 1088 130 16 200K 4KB pages D minfree memory_frames

-------------------------------------------------------------------------------- minfree 960 960 122 8 200K 4KB pages D maxfree memory_frames

-------------------------------------------------------------------------------- ... where:

CUR = current value DEF = default value BOOT = reboot value MIN = minimal value MAX = maximum value

UNIT = tunable unit of measure

TYPE = parameter type: D (for Dynamic), S (for Static), R for Reboot), B (for Bosboot), M (for Mount), I (for Incremental), C (for Connect), and d (for Deprecated)

DEPENDENCIES = list of dependent tunable parameters, one per line

# vmo -L minperm%

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

minperm% 20 20 20 1 100 % memory D maxperm% maxclient%

# vmo -L maxperm%

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

maxperm% 80 80 80 1 100 % memory D minperm% maxclient%

# vmo -L maxclient%

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

maxclient% 80 80 80 1 100 % memory D maxperm% minperm%

# vmo -L lru_file_repage

NAME CUR DEF BOOT MIN MAX UNIT TYPE DEPENDENCIES

lru_file_repage 1 1 1 0 1 boolean D

AIX 下磁盘 I/O 性能分析

磁盘 I/O 的概念

I/O 的概念,从字义来理解就是输入输出。操作系统从上层到底层,各个层次之间均存在 I/O。比如,CPU 有 I/O,内存有 I/O, VMM 有 I/O, 底层磁盘上也有 I/O,这是广义上的 I/O. 通常来讲,一个上层的 I/O 可能会产生针对磁盘的多个 I/O,也就是说,上层的 I/O 是稀疏的,下层的 I/O 是密集的。

磁盘的 I/O,顾名思义就是磁盘的输入输出。输入指的是对磁盘写入数据,输出指的是从磁盘读出数据。

回页首

衡量磁盘 I/O 性能的指标

图 1. 物理磁盘的架构以及常见磁盘类型

我们常见的磁盘类型有 ATA、SATA、FC、SCSI、SAS。这几种磁盘中,服务器常用的是 SAS 和 FC 磁盘,一些高端存储也使用 SSD 盘。每一种磁盘的性能是不一样的。

我们在测试工作中,衡量磁盘 I/O 性能主要参考 IOPS 和吞吐量两个参数。下面,将介绍一下这两个参数的含义。

IOPS 与吞吐量的概念

磁盘的 IOPS,也就是在一秒内,磁盘进行多少次 I/O 读写。

磁盘的吞吐量,也就是每秒磁盘 I/O 的流量,即磁盘写入加上读出的数据的大小。

IOPS 与吞吐量的关系

每秒 I/O 吞吐量= IOPS* 平均 I/O SIZE。从公式可以看出: I/O SIZE 越大,IOPS 越高,那么每秒 I/O 的吞吐量就越高。因此,我们会认为 IOPS 和吞吐量的数值越高越好。实际上,对于一个磁盘来讲,这两个参数均有其最大值,而且这两个参数也存在着一定的关系。 下图为各种磁盘的 IOPS 极限值。

表 1. 常见磁盘类型及其 IOPS

注:上表源自维基百科 http://en.wikipedia.org/wiki/IOPS

在 AIX 中,对于同一个磁盘(或者 LUN),随着每次 I/O 读写数据的大小不通,IOPS 的数值也不是固定不变的。例如,每次 I/O 写入或者读出的都是连续的大数据块,此时 IOPS 相对会低一些;在不频繁换道的情况下,每次写入或者读出的数据块小,相对来讲 IOPS 就会高一些。

回页首

I/O 读写的类型

大体上讲,I/O 的类型可以分为:读 / 写 I/O、大 / 小块 I/O、连续 / 随机 I/O, 顺序 / 并发 I/O。在这几种类型中,我们主要讨论一下:大 / 小块 I/O、连续 / 随机 I/O, 顺序 / 并发 I/O。

大 / 小块 I/O

这个数值指的是控制器指令中给出的连续读出扇区数目的多少。如果数目较多,如 64,128 等,我们可以认为是大块 I/O;反之,如果很小,比如 4,8,我们就会认为是小块 I/O,实际上,在大块和小块 I/O 之间,没有明确的界限。

连续 / 随机 I/O

连续 I/O 指的是本次 I/O 给出的初始扇区地址和上一次 I/O 的结束扇区地址是完全连续或者相隔不多的。反之,如果相差很大,则算作一次随机 I/O

连续 I/O 比随机 I/O 效率高的原因是:在做连续 I/O 的时候,磁头几乎不用换道,或者换道的时间很短;而对于随机 I/O,如果这个 I/O 很多的话,会导致磁头不停地换道,造成效率的极大降低。

顺序 / 并发 I/O

从概念上讲,并发 I/O 就是指向一块磁盘发出一条 I/O 指令后,不必等待它回应,接着向另外一块磁盘发 I/O 指令。对于具有条带性的 RAID(LUN),对其进行的 I/O 操作是并发的,例如:raid 0+1(1+0),raid5 等。反之则为顺序 I/O。

回页首

磁盘 I/O 性能的监控

监控磁盘的 I/O 性能,我们可以使用 AIX 的系统命令,例如:sar -d, iostat, topas, nmon 等。下面,我将以 nmon 和 topas 为例,讲述在系统中如何观察磁盘 I/O 的性能。

topas

登录 AIX 操作系统,输入 topas,然后按 D,会出现如下界面:

在上图中,TPS 即为磁盘的 IOPS,KBPS 即为磁盘每秒的吞吐量。由于服务器处于空闲的状态,我们可以看到 IOPS,KBPS 的数据都非常低。

我们使用 dd if 命令向磁盘 hdisk2 发读 I/O,block 大小为 1MB:

利用 topas 进行监控:

此时,hdisk2 的吞吐量为 163.9M,IOPS 为 655。

我们再启动一个 dd if,使 hdisk 的 busy 数值达到 100%:

从上图可以看出,在磁盘 busy 达到 100% 的时候,其吞吐量为 304.1M,IOPS 为 1200。 hdisk2 是本地集成的 SAS 盘,我们可以查出本地集成 SAS 通道的带宽为 3Gb:

对于 3Gb 的 SAS 通道,304.1M 的磁盘吞吐量已经接近其 I/O 带宽的峰值了。

需要指出的是,使用 dd if 测量磁盘的带宽是可行的,但是由此来确定业务 I/O 的 IOPS 和吞吐量是不科学的。因为,dd if 所发起的读写仅为顺序 I/O 读写,在 OLTP 的业务中,这种读写是不常见的,而是随机小 I/O 比较多,因此,测量业务的磁盘 I/O 性能,需要在运行业务的时候进行监控。

nmon

在系统中输入 nmon,按 d,可以得到如下界面 :

可以得到此时磁盘 hdisk2 吞吐量为 318M。

使用 nmon 收集一个时间段的数据,然后使用 nmon analyzer 进行分析,可以得出更为直接的图表:

将收集好的 nmon 文件使用 nmon analyzer 进行分析,得出如下报表:

图 2.nmon 图表显示磁盘性能

回页首

磁盘 I/O 性能调优

确认磁盘 I/O 存在性能问题

对于随机负载,当遇到余下情况时,我们那通常认为存在 I/O 性能问题:

1. 平均读时间大于 15ms

2. 在具有写 cache 的条件下,平均写时间大于 2.5ms

对于顺序负载,当遇到余下情况时,我们那通常认为存在 I/O 性能问题:

1. 在一个磁盘上有两个连续的 I/O 流 2. 吞吐量不足(即远远小于磁盘 I/O 带宽)

对于一块磁盘来讲,随着 IOPS 数量的增加,I/O service 也会增加,并且会有一个饱和点,即 IOPS 达到某个点以后,IOPS 再增加将会引起 I/O service time 的显著增加。

图 3. 磁盘 IOPS 与 IO service time 关系图

从经验上讲,我们在测试工作中,我们主要关注 IOPS 和吞吐量以及磁盘的 busy% 这三个数值。如果 IOPS 和吞吐量均很低,磁盘的 busy% 也很低,我们会认为磁盘压力过小,造成吞吐量和 IOPS 过低;只有在 IOPS 和吞吐量均很低,磁盘的 busy% 很高(接近 100%)的时候,我们才会从磁盘 I/O 方面分析 I/O 性能。

通过调整 AIX 参数改善磁盘 I/O 性能

在 AIX 系统中,有关磁盘 I/O 性能相关的参数我们主要调整的参数如下图:

图 4.AIX 常见的磁盘 I/O 性能参数

需要注意的是,下面几个参数的调整值,只是经验数值;对于不同的应用,不同的场景,应具体情况具体分析。 调整I/O 队列长度

queue_depth 是 AIX 一次可以传送到磁盘设备的命令的数量,把命令放在队列中再传送给磁盘可以提高 I/O 性能。AIX 中定义的每个磁盘在 ODM 库中都有 queue_depth 属性。这个属性限制了 AIX 可以传送到设备的最大命令的数量。 queue_depth 默认数值为 4

本文来源:https://www.bwwdw.com/article/v45g.html

Top