2023年12月20日发(作者:)

AIX性能调优

系统资源(物理资源,逻辑资源)

系统瓶颈

性能概念

一个程序执行步骤

性能调整流程

Instructor GuideProgram Execution HierarchyHardwareProcessor pipeline(Level 0 registers)Cache(s):L1 / L2 / L3

TLBReal memoryHard disk(Paging /dev/hd6)Operating SystemCurrent instruction(s)(One thread at a time)Current dispatched threadDispatchable threads(Run queue)Waiting threads/

Interrupt handlersExecutable programs(Priority assigned by the

scheduler)©Copyright IBM Corporation 2006Figure 1-6. Program Execution HierarchyAU187.0Notes:IntroductionIn the graphic above, the left side represents hardware entities that are loosely matched

to the appropriate operating system entity on the right side. A program must go from the

lowest level of being stored on disk, to the highest level being the processor running

program instructions.

Hardware hierarchy overviewWhen a program runs, it makes its way up the hardware and operating system

hierarchies, more or less in parallel. Each level on the hardware side is scarcer and

more expensive than the one below it. There is contention for resources among

programs and time spent in transitional from one level to the next. Usually, the time

required to move from one hardware level to another consists primarily of the latency of

the lower level, that is, the time from the issuing of a request to the receipt of the first

data.

1-18 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideDisks are the slowest hardware operationBy far the slowest operation that a running program does (other than waiting on a

human keystroke) is to obtain code or data from a disk. Disk operations are necessary

for read or write requests for programs. System tuning activities frequently turn out to be

hunts for unnecessary disk I/O or searching for disk bottlenecks since disk operations

are the slowest operations. For example, can the system be tuned to reduce paging? Is

one disk too busy causing higher seek times because it has multiple filesystems which

have a lot of activity?Real memoryRandom Access Memory (RAM) access is fast compared to disk, but much more

expensive per byte. Operating systems try to keep program code and data that are in

use in RAM. When the operating system begins to run out of free RAM, it needs to

make decisions about what types of pages to write out to disk. Virtual memory is the

ability of a system to use disk space as an extension of RAM to allow for more efficient

use of and page faultsIf the operating system needs to bring a page into RAM that has been written 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 in from disk. Paging is a normal part of the

operation of a multi-processing system. Paging becomes a performance issue when

free RAM is short and pages which are in memory are paged-out and then paged back

in again causing process threads to wait for slower disk operations. How virtual memory

works will be covered in another unit of this course.

Translation Lookaside Buffers (TLBs)One of the ways that programmers are insulated from the physical limitations of the

system is the implementation of virtual memory. The programmer designs and codes

the program as though the memory were very large, and the system takes responsibility

for translating the program's virtual addresses for instructions and data into real

addresses that are needed to get the instructions and data from RAM. Since this

address-translation process is time-consuming, the system keeps the real addresses of

recently accessed virtual memory pages in a cache called the Translation Lookaside

Buffer (TLB).As long as the running program continues to access a small set of program and data

pages, the full virtual-to-real page-address translation does not need to be redone for

each RAM access. When the program tries to access a virtual-memory page that does

not have a TLB entry, called a TLB miss, dozens of processor cycles, called the

TLB-miss latency are required to perform the address translation.© Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-19Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideCachesTo minimize the number of times the program has to experience the RAM latency,

systems incorporate caches for instructions and data. If the required instruction or data

is already in the cache (a cache hit), it is available to the processor on the next cycle

(that is, no delay occurs); otherwise, a cache miss occurs. If a given access is both a

TLB miss and a cache miss, both delays occur ing on the hardware architecture, there are two or three levels of cache, usually

called L1, L2, and L3. If a particular storage reference results in an L1 miss, then L2 is

checked. If L2 generates a miss, then the reference goes to the next level, either L3, if it

is present, or ne and registersA pipelined, superscalar architecture allows for the simultaneous processing of multiple

instructions, under certain circumstances. Large sets of general-purpose registers and

floating-point registers make it possible to keep considerable amounts of the program's

data in registers, rather than continually storing and reloading the ing system hierarchy overviewThe operating system works on a thread level. When a user requests the execution of a

program, AIX performs a number of operations to transform the executable program on

disk to a running program. First, the directories in the user's current PATH must be

scanned to find the correct copy of the program. Then the system loader (not to be

confused with ld, the binder) must resolve any external references from the program to

shared libraries. Finally, the system branches to the entry point of the program and the

resulting page fault causes the program page that contains the entry point to be brought

into RAM.

Interrupt handlersThe mechanism for notifying the operating system that an external event has taken

place is to interrupt the currently running thread and transfer control to an interrupt

handler (FLIH or SLIH). Before the interrupt handler can run, enough of the

general-purpose registers must be saved to ensure that the system can restore the

context of the running thread after interrupt handling is s A thread is the current execution state of a single instance of a program. In AIX, access

to the processor and other resources is allocated on a thread basis, rather than a

process basis. Multiple threads can be created within a process by the application

program. Those threads share the resources owned by the process within which they

are running.1-20 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideWaiting threadsWhenever an executing thread makes a request that cannot be satisfied immediately,

such as an I/O operation (either explicit or as the result of a page fault) or the granting of

a lock, it is put in a Wait state until that request is complete. Normally, this results in

another set of TLB and cache latencies, in addition to the time required for the request

itself. However, it also allows other threads which are ready to run to gain access to the

CPU.

When a thread is replaced by another thread on a CPU, this is a context switch. A

context switch can also occur when a thread finishes its timeslice or, as stated above, it

must wait for a resource. Whenever a context switch occurs, there may be additional

latencies due to cache misses. Context switches are a normal function of a

multi-processing system, but an abnormally high rate of context switches could be a

symptom of a performance chable threadsWhen a thread is dispatchable, but not actually running, it is put in a run queue to run on

an available CPU. If a CPU is available, it will run right away, otherwise it must wait.

Currently dispatched threadThe scheduler chooses the thread that has the strongest claim to use the processor.

When the thread is dispatched, the logical state of the processor is restored to what

was in effect when the thread was last of the use of cache, RAM, and paging space on program

performanceAccess time for the various components increase exponentially as you move away from

the processor. For example, a one second access time for a 1 GHz CPU would be the

equivalent of 100 seconds for a L3 cache access, 6 minutes for a RAM access, and 115

days for a local disk access! As you can see, the closer you are to the core, the faster

the access is. Understanding how to reduce more expensive (performance-wise)

bottlenecks is key to performance management.© Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-21Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuidePerformance Analysis FlowchartYesIs there aperformanceproblem?ActionsYesActionsCPU Bound?NoMemory Bound?NoYesNoI/O Bound?YesNormal OperationsMonitor system performance

and check against requirementsActionsNoNetwork Bound?YesActionsNoAdditional testsActionsNoDoes performancemeet stated

goals?Yes©Copyright IBM Corporation 2006Figure 1-8. Performance Analysis FlowchartAU187.0Notes:Tuning is a processThe flowchart in the visual above can be used for performance analysis and it illustrates

that tuning is an iterative process. We will be following this flowchart throughout our

starting point for this flowchart is the Normal Operations box. The first piece of data

you need is a performance goal. Only by having a goal, or a set of goals, can you tell if

there is a performance problem. The goals may be something like a specific response

time for an interactive application or a specific length of time in which a batch job needs

to complete. Tuning without a specific goal could in fact lead to the degradation of

system you decide there is a performance problem and you analyze and tune the system,

you must then go back to the performance goals to evaluate whether more tuning

needs to occur.© Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-27Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideAdditional testsThe additional tests that you perform at the bottom right of the flowchart relate to the

four previous categories of resource contention. If the specific bottleneck is well hidden,

or you missed something, then you must keep testing to figure out what is wrong. Even

when you think you’ve found a bottleneck, it’s a good idea to do additional tests to

identify more detail or to make sure one bottleneck is not masquerading as another. For

example, you may find a disk bottleneck, but in reality it’s a memory bottleneck causing

excessive paging.

1-28 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuidePerformance Analysis ToolsCPUvmstat, iostatpssartprof, gprof,

proftime, timexnetpmonlocktraceemstat, alstattopas,

performance

toolboxtrace, trcrpt,

curt, splat,

trusscpupstat,

lparstat,

mpstat, smtctltopas,

performance

toolboxtrace, trcrpt,

trussprocmon, lparstat©Copyright IBM Corporation 2006Memory SystemvmstatlspssvmonfilemonI/O Subsystemiostatvmstat

lspslsattrlsdevlspv, lslv, lsvgfileplacefilemonlvmstattopas,

performance

toolboxtrace, trcrpt,

trussNetwork

Subsystemlsattrnetstat, entstatnfsstatnetpmonifconfigiptrace, ipreporttcpdumptopas,

performance

toolboxtrace, trcrpt,

trussnfs4clFigure 1-9. Performance Analysis ToolsAU187.0Notes:CPU analysis toolsCPU metrics analysis tools include: -vmstat, iostat, sar, lparstat and mpstat which are packaged with -ps which is in l

-cpupstat which is part of ds -gprof and prof which are in -time (built into the various shells) or timex which is part of -emstat and alstat are emulation and alignment tools from -netpmon, tprof, locktrace, curt, splat, and topas are in -trace and trcrpt which are part of -truss is in _aids1-30 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor Guide -smtctl is in s -Performance toolbox tools such as xmperf, 3dmon which are part of perfmgrMemory subsystem analysis toolsSome of the memory metric analysis tools are: -vmstat which is packaged with -lsps which is part of -topas, svmon and filemon are part of -Performance toolbox tools such as xmperf, 3dmon which are part of perfmgr -trace and trcrpt which are part of -lparstat is part of /O subsystem analysis toolsI/O metric analysis tools include: -iostat and vmstat are packaged with -lsps, lspv, lsvg, lslv and lvmstat are in -lsattr and lsdev are in s -topas, filemon, and fileplace are in

-Performance toolbox tools such as xmperf, 3dmon which are part of perfmgr -trace and trcrpt which are part of etwork subsystem analysis toolsNetwork metric analysis tools include: -lsattr and netstat which are part of -nfsstat and nfs4cl as part of -topas and netpmon are part of -ifconfig as part of -iptrace and ipreport are part of -tcpdump which is part of -Performance toolbox tools such as xmperf, 3dmon which are part of perfmgr -trace and trcrpt which are part of © Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-31Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideAIX 5L V5.3 enhancements to analysis toolsSeveral changes were made in AIX 5L V5.3 to the analysis tools. Changes were made

at different maintenance levels for tprof command has new -E option to enable event based profiling and the new -f

option allows you to set the sampling frequency for event-based profiling. There were

updates to PMAPI including updates to pmlist and there are two new commands for

hardware analysis: hpmcount and hpmstat. These are not covered in this topas command has a new -D panel for disk are new commands for obtaining statistics specific to a logical partition. These

give statistics for POWER Hypervisor activity or for tracking real CPU utilization in a

simultaneous multi-threading or shared processor (Micro-Partition) environment. A new

register was added called the Processor Utilization Resource Register (PURR) to track

logical and virtual processor activity. Commands such as sar and topas will

automatically use the new PURR statistics when in a simultaneous multi-threading or

shared processor (Micro-Partition) environment and you will see new columns reporting

partition statistics in those environments. Trace-based commands now have new hooks

for viewing PURR data. Some commands such as lparstat, mpstat, and smtctl are

new for AIX 5L V5.3 and work in a partitioned AIX 5L Virtualization Performance Management course covers all differences in

performance analysis and tuning in a partitioned environment.

1-32 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuidePerformance Tuning and prioritize specific goal or set of goals

r system and determine if goals are being metIf goals are not being met:

fy performance bottlenecks

fy the required resources (logical or physical)

or other action to takeTuningProject resources are constrained:ze resource requirements••Use the appropriate resourcesStructure for parallel resource usage

StartPlan l the allocation of resources

additional resources as

back to Step 2Gather DataDevelop and PresentRecommendationsTo ClientAnalyze Data©Copyright IBM Corporation 2006Figure 1-10. Performance Tuning ProcessAU187.0Notes:OverviewPerformance tuning is one aspect of performance management. The definition of

performance tuning sounds simple and straight forward, but it’s actually a complex

process.

Performance tuning involves managing your resources. Resources could be logical

(queues, buffers, etc.) or physical (real memory, disks, CPUs, network adapters, etc.).

Resource management involves the various tasks listed here. We will examine each of

these tasks always must be done based on performance analysis. While there are

recommendations as to where to look for performance problems, what tools to use, and

what parameters to change, what works on one system may not work on another. So

there is no cookbook approach available for performance tuning that will work for all

systems.1-34 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideThe wheel graphic in the visual above represents the phases of a more formal tuning

project. Experiences with tuning may range from the informal to the very formal where

reports and reviews are done prior to changes being made. Even for informal tuning

actions, it is essential to plan, gather data, develop a recommendation, implement, and

document.© Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-35Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuidePerformance Tuning ToolsCPUnicereniceschedo*schedtune**bindprocessorchdevsetpribindintcpuprocmonMemory SystemI/O Subsystemvmo*vmtune**ioo*vmtune**chpsmkpsfdprchdevvmo*vmtune**ioo, lvmo*vmtune **chdevmigratepvchlvreorgvgNetwork

Subsystemnonfsochdevifconfig* AIX 5L V5.2 and later

** Prior to AIX 5L V5.2©Copyright IBM Corporation 2006Figure 1-11. Performance Tuning ToolsAU187.0Notes:CPU tuning toolsCPU tuning tools include: -nice, renice, and setpri modify and renice are in the l is a command available with the perfpmr package. -schedo (schedtune in AIX 5L V5.1) modifies scheduler algorithms (in the

fileset). -bindprocessor binds processes to CPUs (in the fileset). -chdev modifies certain system tunables (in the s fileset). -bindintcpu can bind an adapter interrupt to a specific CPU (in the

fileset). -procmon is in .© Copyright IBM Corp. 2000, 2006Unit 1. Performance Analysis and Tuning Overview1-37Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

Instructor GuideMemory tuning toolsMemory tuning tools include: -vmo and ioo (vmtune in AIX 5L V5.1) for various VMM, file system, and LVM

parameters (in fileset) -chps and mkps modify paging space attributes (in fileset) -fdpr rearranges basic blocks in an executable so that memory footprints become

smaller and cache misses are reduced (in fileset) -chdev modifies certain system tunables (in s fileset)I/O tuning toolsI/O tuning tools include: -vmo and ioo modify certain file system and LVM parameters (in

fileset) (Use vmtune prior to AIX 5L V5.2.) -chdev modifies system tunables such as disk and disk adapter attributes (in

s fileset) -migratepv moves logical volumes from one disk to another (in fileset) -lvmo displays or sets pbuf tuning parameters (in fileset) -chlv modifies logical volume attributes (in fileset) -reorgvg moves logical volumes around on a disk (in fileset)Network tuning toolsNetwork tuning tools include: -no modifies network options (in fileset) -nfso modifies NFS options (in fileset) -chdev modifies network adapter attributes (in s fileset) -ifconfig modifies network interface attributes (in fileset)1-38 AIX 5L System Administration III© Copyright IBM Corp. 2000, 2006Course materials may not be reproduced in whole or in part

without the prior written permission of IBM.

CPU

在定位CPU性能问题时,从监视 CPU 使用率的统计数据入手。持续观察系统的性能非常重要,这是因为需要对过载的系统数据与正常使用的数据(作为基准)进行比较。因为 CPU 是系统中最快的组件,因此如果 CPU 使用率使

CPU 保持 100% 忙碌,那么也会影响系统范围的性能。如果发现系统使

CPU 保持 100% 忙碌,则需要调查导致这种情况发生的进程。AIX 提供了许多分别针对系统和进程的跟踪和分析工具。在 CPU 受限的系统中,所有处理器都是 100% 忙碌的,并且一些作业可能正处在运行队列中等待 CPU 时间。通常来说,如果某个系统的 CPU 是 100% 忙碌,并且相对于 CPU 的数目来说拥有大规模的运行队列,以及具有更为频繁的上下文切换,那么该系统很有可能成为 CPU 受限系统。

识别瓶颈

如果系统实际上是 CPU 受限的,就可以运行其他工具(如 trace、curt、splat、tprof 和 ps)来进一步确定导致瓶颈的实际进程。还有可能您的系统实际上是内存或 I/O 受限,而非 CPU 受限。修复某个瓶颈可能会导致 CPU

瓶颈,这是因为系统现在允许 CPU 以最佳化性能运行,而 CPU 本身可能没有能力处理额外增加的资源量。这种情况可能经常在客户那里出现,这不一定是一件坏事。恰恰相反,它最终可以帮助您隔离所有的瓶颈。您会发现监视和优化系统是一个极具变化的过程,且并非总是可以预测的。

优化瓶颈

在您最终确定瓶颈之后,就到了对瓶颈进行调整的时候了。对于 CPU 瓶颈,通常有四种解决方案可供选择:

平衡系统负载——在不同的期间运行进程,从而更有效地利用每天的 24

小时。

使用 nice 或 renice 优化调度程序——可帮助您为运行进程分配不同的优先级,以避免占用大量 CPU 资源。

使用 schedo 调整调度程序算法,从而优化优先级公式——可以使用

schedo 调整 AIX 中的各种参数。例如,schedo 命令可用于更改操作系统在调用调度程序以选择运行其他进程之前允许给定进程运行的时间(时间片)。此时间间隔的默认值为单个指令周期(10 毫秒)。时间片调整参数允许用户指定时间片长度增加的时钟计时数。

时间片调整参数

# schedo -a | grep timeslice

timeslice = 1

增加资源

其他一些 CPU 调整命令包括 smtctl和 indprocessor。

查看处理器

//To view all processors (logical and physical):

# bindprocessor -q

The available processors are: 0 1 2 3

//To view the physical processors

# bindprocessor -s 0

The available processors are: 0 2

//To view the SMT enables processors.

# bindprocessor -s 1

The available processors are: 1 3

UNIX 通用 CPU 监视工具

我们首先讨论 vmstat。vmstat 报告关于进程、内存、分页、被阻塞的 I/O

及总体 CPU 活动的信息。虽然这个工具与虚拟内存相关(vmstat 中的

vm),但是在主机上运行 vmstat 可以让我快速而准确地确定 AIX 服务器上发生的情况。

使用 vmstat

vmstat 是开始进行此工作的最好工具。有关运行 vmstat 的示例:

运行 vmstat

# vmstat 1

System configuration: lcpu=2 mem=3920MB

kthr memory page faults cpu

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

r b avm fre re pi po fr sr cy in sy cs us sy id wa

0 0 229367 332745 0 0 0 0 0 0 3 198 69 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 3 33 66 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 2 33 68 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 80 306 100 0 1 97 1

0 0 229367 332745 0 0 0 0 0 0 1 20 68 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 2 36 64 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 2 33 66 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 2 21 66 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 1 237 64 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 2 19 66 0 0 99 0

0 0 229367 332745 0 0 0 0 0 0 6 37 76 0 0 99 0

对上面的命令解释如下:

Kthr段显示内容

♦ r列表示可运行的内核线程平均数目,包括正在运行的线程和等待

CPU 的线程。如果这个数字大于 CPU 的数目,则表明有线程需要等待CPU。

♦ b列表示处在非中断睡眠状态的进程数。包括正在等待文件系统

I/O 的线程,或由于内存装入控制而被挂起的线程。

Memory段显示内容

♦ avm列表示活动虚拟内存的页面数,每页一般4KB

♦ fre空闲的页面数,每页一般4KB

Page段显示内容

♦ re –该列无效

♦ pi 从磁盘交换到内存的交换页(调页空间)数量,4KB/页。调页空间是驻留在硬盘上的虚拟内存的一部分。当内存使用过量时,会将溢出的工作组页面存储到调页空间中(窃取页)。当进程访问一个窃取页时,就产生了一个缺页故障,而这一页页必须从调页空间中读入到内存中。

♦ po 从内存交换到磁盘的交换页数量,4KB/页。如果窃取的工作也在调页空间中不存在或者已经作了修改,则写入调页空间中。如果不被再次访问,它会留在调度空间中直到进程终止或者放弃空间。

♦ fr 根据页面替换算法每秒释放的页数。当VMM页面替换例程扫描页面帧表(Page Frame Table,PFT)时,它会根据一些条件选取需要窃取的页面以补充空闲列表。该条件中包含工作页面和计算页面,释放的页面中,计算页面不产生I/O,工作页面如果数据没有发生修改,也不需要写回磁盘,也不会产生I/O。

♦ sr 根据页面替换算法每秒所检查的页数。sr值比fr值高的越多,说明替换算法要查找可以替换的页面就越困难。

♦ cy 每秒页面替换代码扫描了PFT多少次。因为增加空闲列表达到maxfree值,不一定需要完全扫描PFT表,而所有vmstat输出都为整数,所以通常cy列值为0。

Faults段显示内容(其实这段内容不需太多关注)

♦ in 在该时间间隔中观测到的每秒设备中断数。

♦ sy 在该时间间隔中观测到的每秒系统调用次数。

♦ cs 在该时间间隔中观测到的每秒钟上下文切换次数。

Cpu段显示内容

♦ us 列显示了用户模式所消耗的 CPU 时间。

♦ sy 列详细显示了 CPU 在系统模式所消耗的 CPU 时间。

♦ id 列显示了没有未决本地磁盘 I/O 时 CPU 空闲或等待时间的百分比。

♦ wa 列详细显示了有未决本地磁盘 I/O 时 CPU 空闲的时间百分比。wa 的值如果超过 25%,就表明磁盘子系统可能没有被正确平衡,

或者这也可能是磁盘工作负荷很重的结果。

如果在一个单用户系统中,us + sy时间不超过 90%,我们就不认为系统的CPU是有瓶颈的

如果在一个多用户系统中,us + sy时间超过 80%, 我们就认为系统的CPU是有瓶颈的。其中的进程将要花时间在运行队列中等待。响应时间和吞吐量会受损害。

检查cpu,我们主要关注报告中的4个cpu列和2个kthr(内核线程)列。

在上面的示例中,我们可以观察到以下几个主要的信息:

CPU IDLE比较高,比较空闲;r列为0,表明线程不存在等待;

WA值不高,说明I/O压力不大;

free值比较大,pi,po为0,表明内存非常富裕。空闲较多。

虽然 vmstat 命令更多地与内存相关,但我发现可通过该命令最快而且最准确地确定瓶颈所在。

使用 sar

下一个命令 sar 是 UNIX System Activity Reporting 工具(属于

文件集)。此命令实际上就是将选择作为其标志的积累活动的内容写入到标准输出。例如,以下命令使用 -u 标志报告 CPU 统计数据。我在没有用户的情况下在系统上运行此命令。除非有批处理作业在运行,否则就不会看到大量的活动。

在没有用户的情况下运行 sar

# sar -u 1 5 (or sar 1 5)

AIX test01 3 5 03/18/07

System configuration: lcpu=2

17:36:53 %usr %sys %wio %idle physc

17:36:54 0 0 0 100 2.00

17:36:55 1 0 0 99 2.00

17:36:56 0 0 0 100 2.00

17:36:57 0 0 0 100 2.00

17:36:58 0 0 0 100 2.00

Average 0 0 0 100 2.00

显然,此系统也没有 CPU 瓶颈。

当我们有多个cpu的时候,而程序采用的是单线程,有时候会出现一种情

况,我们检查发现,cpu总体的使用率不高,但是程序响应却比较慢。这里有可能就是单线程只使用了一个cpu,导致这个cpu100%占用,处理不过来,而其他的cpu却闲置。这时可以对cpu分开查询,统计每个cpu的使用情况。

#sar -P ALL 1 2

AIX jsdxh_db02 3 5 00C2C1EB4C00 10/24/07

System configuration: lcpu=16

18:03:30 cpu %usr %sys %wio %idle physc

18:03:31 0 0 69 0 31 0.00

1 50 50 0 0 1.00

2 0 0 0 100 0.52

3 0 0 0 100 0.48

4 0 1 0 99 0.54

5 0 0 0 100 0.46

6 0 0 0 100 0.53

7 0 0 0 100 0.47

8 0 0 0 100 0.53

9 0 0 0 100 0.47

10 0 2 0 98 0.54

11 0 0 0 100 0.46

12 11 58 0 31 0.00

13 100 0 0 0 1.00

14 0 0 0 100 0.53

15 0 0 0 100 0.47

- 19 7 0 75 8.01

上面所使用的列与 vmstat 条目输出类似。下表将 sar 与 vmstat 描述内容进行关联。

表 1. sar 输出字段和对应的 vmstat 字段

sar vmstat

%usr

%sys

%wio

us

sy

wa

%idle id

相比较vmstat和sar,vmstat更好,它可提供 CPU 使用率信息,并能提供有关内存和 I/O 的总体监视信息。对于 sar,您需要运行独立的命令才能提取信息。sar 的一个优势是,它允许捕获日常信息和运行关于此信息的报告(不用自己撰写脚本来进行此工作)。它通过使用名为 System Activity

Data Collector 的进程实现此工作,此进程实际是 sar 命令的一个后端进

程。在已启用的情况下,它通常通过 cron(在缺省 AIX 分区上,通常会发现将其注释掉了)以二进制格式定期收集数据。Sar还有其他一些比较特殊的使用方法,比如:如果希望多个采样和多个报告,可为 sar 命令指定一个输出文件,这样就方便多了。将 sar 命令的标准输出数据定向到 /dev/null,并将 sar 命令作为后台进程运行。具体的命令格式为:

sar -A -o /temp/sar_ 5 300 > /dev/null &

AIX 特定的 CPU 监视工具(特定分区环境)

接下来我们讨论特定于 AIX 的命令。编写这些命令的目的是为了让管理员在分区环境中监视系统。这些命令在使用 Advanced POWER

Virtualization 功能(如共享处理器和微分区)时尤为有用。

使用 lparstat

当用户首次报告系统运行缓慢时,启动 lparstat。lparstat 命令用于报告逻辑分区(Logical Partition,LPAR)信息和相关统计数据。在 AIX 5L

V5.3 中,lparstat 命令将显示关于很多 POWER Hypervisor 调用的

Hypervisor 统计数据。lparstat 命令是一个相对较新的命令,通常用于在共享处理器分区环境中提供帮助。

如果希望看到 POWER Hypervisor 统计数据,因此使用了 -h 标志。

lparstat 命令的 -h 标志

# lparstat -h 1 5

System configuration: type=Dedicated mode=Capped smt=On

lcpu=4 mem=3920

%user %sys %wait %idle %hypv hcalls

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

0.0 0.7 0.0 99.3 44.4 5933918

0.4 0.3 0.0 99.3 44.9 5898086

0.0 0.1 0.0 99.9 45.1 5930473

0.0 0.1 0.0 99.9 44.6 5931287

0.0 0.1 0.0 99.9 44.6 5931274

正如您看到的,从某种程度而言,上面所生成的输出与 sar 命令相似。

mpstat

还有一个经常使用的另一个命令是 mpstat 命令,该命令属于 文件集。这是专门为 AIX 5.3 创建的工具(与 lparstat 不同),用于显示分区系统上所有逻辑 CPU 的总体性能值。运行 mpstat 命令时,将显示两个部分的统计数据。第一部分显示系统配置,在该命令开始执行以及对系统配置进行了修改时,将显示这部分信息。第二部分显示使用率统计数据,此数据将以用户指定的时间为间隔显示。

运行 mpstat

# mpstat 1 1

System configuration: lcpu=2 ent=2.0

cpu min maj mpc int cs ics rq mig lpa sysc us sy wa id pc %ec lcs

0 0 0 0 164 83 40 0 1 100 17 0 0 0 100 0.17 8.3 113

1 0 0 0 102 1 1 1 0 100 3830453 66 34 0 0 0 100 .83 41.6

mpstat命令以非常清晰的格式报告所收集的分区上的每个逻辑 CPU 的信息。通过使用 -s 选项,甚至还能够看到同步多线程(Simultaneous

MultiThreading,SMT)线程使用率。lparstat 和 mpstat 命令的缺点在于,二者都需要编写脚本和其他工具来处理数据格式和图形输出。实际上,您需要编写自己的 shell 脚本。尽管大部分管理员喜欢使用脚本,但他们却不愿意做重复工作。如果已经有了相应的工具来帮助您分析历史数据,编写自己的实用工具就不太明智了。

图形化工具

接下来我们将了解一些实用工具,通过这些工具能以图形查看分析,还能对历史数据进行分析。尽管完全了解这些工具需要一定的时间,但这些工具比我们已经了解的命令行工具要更为灵活。

procmon(不太常用,了解)

接下来我们讨论 procmon。此实用工具(在 AIX 5.3 中发布)不仅提供总体性能统计数据,还允许对实际运行的处理器进行操作。它允许管理员动态地结束进程或恢复进程。还可以将 procmon 数据导出到文件中,这就使其成为了一个不错的数据收集工具。procmon 实际上作为性能基准的插件运行,此基准可通过使用 perfwb(位于 /usr/bin 中)命令(属于

文件集)启动。

图 1. procmon 输出

procmon工具的一个好处是因为它允许对进程进行操作,而这可以提高系统的性能。

topas

应该注意的另一个工具是 topas。topas 的外观与 top 和 monitor(在其他 UNIX 变体中使用)非常相似。topas 是在屏幕上以基于文本的 GUI 格式显示所有信息的一款实用工具。采用其缺省模式时,会显示主机名、刷新间隔和 CPU、内存及 I/O 信息的综合情况。

图 2. topas 显示

topas命令有些新功能还包括允许在虚拟 I/O 服务器(Virtual I/O

Server,VIO Server)上运行 topas。为此,请使用以下命令:

# topas -cecdisp

在 LPAR 上,要运行:

topas -C

考虑到在 5.3 ML 4 中引入了性能监视功能,topas 使用了从 inittab 自动启动的守护进程 xmwlm。在 AIX 5.3 的 ML_5 中,缺省会保留七天的数据,并会记录几乎所有的 topas 数据,除进程和工作负载管理器(Workload Manager,WLM)信息外,其中的其他数据会以交互方式显示。它使用 topasout 命令来生成基于文本的报告。topas 在处理其不足方面进行了大量的工作,但大多数管理员可能希望使用其他实用工具——如

nmon。

nmon

所有性能工具中,我最喜欢 nmon。从 nmon 收集的数据可从屏幕查看,也可以通过通常从 cron 运行的报告查看。

图 3. nmon 示例输出

务必注意。事实上,运行 nmon 会话一段时间之后,可以实际看到以 Excel

电子表格形式良好呈现的表格,可以将此表格提交给高层管理人员或其他技术团队以进行分析。

接下来让我们看一个简单的任务。首先让我们告知 nmon 创建文件,对运行进行命名,并在 180 个时间间隔内每 30 秒进行一次数据收集(共计 1.5 个小时):

# nmon -f -t -r test2 -s 30 -c 180

完成此工作,对文件进行排序。

对文件进行排序

# sort -A testsystem_yymmd_ >

testsystem_

完成后,将 .csv 文件通过 FTP 上传到工作站,启动 nmon 分析器电子表格(确保启用了宏),然后单击 analyze nmon data。

图 4. nmon 分析器输出

nmon 分析器是一个非常不错的工具,是由 Stephen Atkins 编写的,能从 Excel 电子表格以图形表示数据(CPU、内存、网络或 I/O)。或许使其不能成为企业类型的工具的唯一缺陷就是,它缺乏同时在大量 LPAR 上收集统计数据的能力,因为它不是数据库(其设计也没有考虑成为数据库)。

ps命令 这个命令使用本身也比较复杂,在这里只介绍如何查看cpu占用最高的进程。使用举例如下:

#ps aux | head -25

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME

COMMAND

root 17214 3.1 0.0 40 40 - A Jul 04 25578:42 wait

root 16946 3.1 0.0 40 40 - A Jul 04 25415:54 wait

oracle 344612 0.3 0.0 56372 33852 - A Jul 04 2707:30

ora_j000_ora92

oracle 430408 0.3 0.0 55916 33396 - A Jul 04 2266:20

ora_j001_ora92

oracle 365092 0.2 0.0 56184 33664 - A Jul 04 1765:58

ora_j002_ora92

oracle 442430 0.2 0.0 56092 33572 - A Jul 04 1426:40

ora_j003_ora92

oracle 385606 0.1 0.0 55984 33464 - A Jul 05 1159:17

ora_j004_ora92

oracle 413856 0.1 0.0 50520 28000 - A Jul 23 543:31

oracleora92 (LOC

oracle 143668 0.1 0.0 50528 28008 - A Jul 13 833:21

oracleora92 (LOC

oracle 369230 0.1 0.0 56600 34080 - A Jul 05 806:36

ora_j005_ora92

在这个输出结果中,排在前面的是16个root用户的wait进程,这其实是CPU空闲的时候运行的空闲进程,之前已作说明。

所以CPU最高的几个进程其实是下面的ORACLE用户的ora_j00*进程,这是ORACLE的job进程。在这里,这些进程的开销很小。如果ORACLE的进程开销比较大,我们可以用如下的方法来查询具体的进程在干什么事情,例如我们要查询进程ora_j000_ora92,PID=344612,可以使用下面的方法:

$su – oracle

SQL>sqlplus “/as sysdba”

SQL>oradebug setospid 344612

SQL>oradebug event 10046 trace name context forever, level 8

SQL>oradebug tracefile_name –这个命令我们获得输出文件的绝对路径和文件名

SQL>oradebug event 10046 trace name context off

$tkprof

/opt/oracle/app/oracle/admin/ora92/bdump/ora92_j000_

$more

在中,我们就可以看到这个进程中具体运行的语句、过程等,以及所有的SQL的cpu消耗、物理读、逻辑读、执行计划等信息。

另外,我们也可以执行下面的语句查看进程具体运行的SQL语句的文本:

SELECT /*+ ORDERED */ sql_text FROM v$sqltext a

WHERE (_value, s) IN (

SELECT DECODE (sql_hash_value,0,

prev_hash_value,sql_hash_value),

DECODE (sql_hash_value,0, prev_sql_addr, sql_address)

FROM v$session b

WHERE = (SELECT addr

FROM v$process c

WHERE = '&pid'))

ORDER BY piece ASC

线程监视

Procmon 可以显示进程的列表(当您的系统变化时,该列表也将动态地变化),通过这个列表,您可以收集有关系统中正在运行的进程的信息。与其他监视工具相比,其独特之处在于,它允许您运行各种命令以简化进程和线程的管理。它能够收集的、与性能优化相关的一些关键信息包括:

某个进程实际使用的 CPU 时间

某个进程的内存和 I/O 用量

进程的 nice(优先级调整参数)值及其优先级

您甚至可以 kill 任务(终止任务),并且动态地 renice 它们(调整其优先级)。给出了关于整体性能的图形表示。要启动 Performance

Workbench Platform,可以使用: # perfwb。

图 1. Procmon partition performance 选项卡

其中还包括一个进程表视图,用于在经过排序的表格中显示线程列表。您只需选择 Show threads metrics 即可。

图 2. Procmon processes 选项卡

其他的一些菜单允许您 kill 进程(终止进程)或者 renice 它们(重新调整进程的优先级),。

图 3. renice 命令对话框

那么,nice 究竟是什么呢?您可以使用 nice 命令调整给定进程的优先级。所有进程的缺省值都为 20。使用 renice 命令(通过 Procmon 或者命令

行)可以使得系统为给定的进程分配一个更高的或者更低的优先级。在进行该操作时,您实际上通过更改进程的 nice 值,从而更改了线程优先级的值(缺省值为 40)。

如果您在运行 ps 命令时使用了 -l 标志,那么您将看到具体的 nice 信息。

nice 信息

# ps -l

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD

200001 A 0 12972 45770 0 60 20 dea6 764 pts/1 0:00 ksh

200001 A 0 33816 12972 3 61 20 36168 440 pts/1 0:00 ps

240001 A 207 45770 40374 0 60 20 258ec 744 pts/1 0:00 ksh

让我们通过 nice 启动一个新的 ksh,更改进程的优先级:# nice --10 ksh

当您再次使用 ps 查看进程表时,您将看到,对于这个进程以及它通过 fork 系统调用创建的子进程,它们的优先级都不再是缺省值。

使用 nice 命令得到的新的 ksh

# ps -l

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD

200001 A 0 12972 45770 0 60 20 dea6 764 pts/1 0:00 ksh

200001 A 0 17246 12972 0 50 10 68a1f 748 pts/1 0:00 ksh

200001 A 0 18450 17246 1 50 10 51bb1 380 pts/1 0:00 ps

240001 A 207 45770 40374 0 60 20 258ec 744 pts/1 0:00 ksh

您还可以使用 renice 命令(前面在介绍 Procmon 的中对该命令进行了说明),以便动态地为一个运行的进程重新分配优先级。

让我们回到 ps。如果您希望更详细地查看相关的线程,那么您可以使用 -mo

标志。

使用 -mo 标志以便更详细地查看您的线程

# ps -mo THREAD

USER PID PPID TID ST CP PRI SC WCHAN F TT BND COMMAND

root 12800 45770 - A 0 60 1 - 200001 pts/1 - -ksh

- - - 56759 S 0 60 1 - 10400 - - -

root 44648 12800 - A 1 60 1 - 200001 pts/1 - ps -mo THREAD

- - - 64905 R 1 60 1 - 0 - - -

kmilberg 45770 40374 - A 0 60 1 - 240001 pts/1 - -ksh

- - - 54005 S 0 60 1 - 10400 - - -

尽管大多数管理员通常仅在进行 ps -ef 操作时使用 ps,但是如果您更仔细地研究它的特性,那么您将会了解到更多关于 ps 的内容。

更改线程的优先级

您已经了解了如何更改进程的优先级,那么对于线程又该如何操作呢?这部分内容介绍了如何更改用于计算每个线程优先级值的 CPU 调度参数。您可以使用 schedo(在 AIX Version 5.2 及更早的版本中是 schedune)来完成这项工作。

首先,您需要确保拥有下面的文件集。

检查文件集

# lslpp -lI

Fileset Level State Description

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

Path: /usr/lib/objrepos

5.2.0.10 COMMITTED Performance Tuning Support

Path: /etc/objrepos

5.2.0.10 COMMITTED Performance Tuning Support

现在,让我们报告所有的 CPU 参数。

报告所有的 CPU 参数

# schedo -a

%usDelta = 100

affinity_lim = 7

big_tick_size = 1

fixed_pri_global = 0

force_grq = 0

idle_migration_barrier = 4

maxspin = 16384

pacefork = 10

sched_D = 16

sched_R = 16

timeslice = 1

v_exempt_secs = 2

v_min_process = 2

v_repage_hi = 0

v_repage_proc = 4

v_sec_wait = 1

首先从 fixed_pri_global 开始进行分析。它的缺省设置为 0。当 CPU 准备分派线程时,它会先检查全局运行队列,然后再检查其他队列。当线程在 CPU

上的时间片结束之后,它将被重新放回到这个队列中。这可以帮助维护处理器的关联性。要提高整体的线程性能,您可以将名为 RT_GRQ 的环境变量设置为 ON。这样一来,就会自动地将线程放入到全局运行队列中。如果您将缺省值从 0 更改为 1,那么所有固定优先级的线程都将放入到这个运行队列中。您可以执行下面的命令将缺省值从 0 更改为 1: #schedo -o

fix_pri_global=1。

用户进程的实际优先级会随着时间发生变化,这取决于该进程最近所使用的

CPU 时间。您需要查看的参数包括 sched_R 和 sched_D。这两个参数值的单位都是 1/32 秒,并且它们的缺省值都为 16。而且,对于刚创建的线程,其 CPU 值为 0。随着线程在 CPU 上执行时间的增加,其 CPU 使用时间将会递增。实际上,调度程序使用下面的公式来计算 CPU 使用时间: CPU

usage = CPU usage*(D/32)。

在这个示例中,如果 D 参数设置为 32,那么线程的 CPU 使用时间将不会衰减,而该参数的缺省值为 16,这样就允许 CPU 使用时间随着时间的推移而衰减,从而使其获得更多的在 CPU 上执行的时间。

每个 CPU 都有一个专门的运行队列。运行队列是由运行线程所组成的列表,按照线程优先级的值进行排序。一共有 256 种线程优先级(从 0 到 255)。还有一个附加的全局运行队列,其中放的是新的线程。

Schedo 通常用于更改调度程序时间片的长度。要更改时间片,可以使用

schedo -o timeslice=value 选项。增加时间片的长度可以提高系统吞吐量,因为减少了上下文的切换。在进行这种更改之前,请确保反复地运行

vmstat 以确定系统中确实正在进行大量的上下文切换工作。

CPU 绑定

AIX允许进程在特定的处理器上运行。这个术语本身可称为处理器关联。处理器关联有许多用途,其中一些甚至可以在调试的过程中使用。例如,您可以将线程绑定到给定的处理器,以找出导致某个挂起程序的根源。通常,在尝试将程序分散到多处理机系统(例如 SMP 系统)中时,会使用到处理器关联。您所使用的命令是 bindprocessor 命令。假定启用了同步多线程 (SMT),这是缺省的行为,那么在运行 bindprocessor 命令时,会将物理处理器的每个硬件线程作为单独的处理器列举出来。在 POWER5 芯片中,每个处理器中有

两个硬件线程。对于共享的处理器逻辑分区 (LPAR),使用这个命令可以绑定到虚拟 CPU,所以您必须非常小心,因为它可能会导致预先安排运行于特定

CPU 的应用程序出现问题。让我们首先检查一下是否启用了 SMT。

检查是否启用了 SMT

# smtctl

SMT is currently enabled.

显示了一个启用了 SMT 的双向系统的输出。

一个启用了 SMT 的双向系统的输出

# bindprocessor -q

The available processors are: 0 1 2 3

如果您希望将一个进程绑定到某个特定的 CPU,非常简单,执行下面的命令:

# bindprocessor 12741 2

有时候,会很自然地出现处理器关联的情况。当某个线程在一个 CPU 上运行并发生了中断,通常会将它放回到相同的 CPU 上运行,因为这个处理器的缓存中仍然保存了属于该线程的相关信息。如果将其分派到另一个 CPU,它可能不得不从 RAM 中获取相关信息,而这将极大地降低处理的速度。

编程中使用的另一个重要线程命令是 gprof。gprof 命令为您所编译的程序(可能是用 C、Pascal、FORTRAN、或者甚至是 COBOL 编写的程序)产生一个执行概要。gprof 可以报告您的程序中所有子例程的流程控制,并为您提供每个子例程所使用的 CPU 时间。在对进程如何使用 CPU 资源进行故障诊断时,这是非常有用的。相关的数据来自于概要文件 ()。您可以使用 gprof 对您的程序进行概要分析,并确定哪些函数正在使用 CPU。概要数据来自于调用关系图概要文件(缺省情况下是 )。

使用tprof命令用于统计每个进程的CPU使用情况

# tprof -x sleep 30

该命令的输出结果可查看 __文件。

此命令运行30秒钟,在当前目录下创建一个名为_ 的文件。30秒钟内, CPU被调度次数约为3000次。__ 文件中的字段Total 为此进程调度到的CPU次数。如果进程所对应的 Total字 段的值为1500,即表示该进程在3000次 CPU调度中占用了1500次,或理解为使用了一半的CPU时间。tprof的输出准确地显示出哪个进程在使用CPU 时间。

在我下面的这一份示例中,可以看到,大部分的cpu时间都是被wait所占用的。这里的wait实际上是idle进程,可以表明这个系统是一个完全空闲的系统。

$ more __

Process PID TID Total Kernel User Shared Other

======= === === ===== ====== ====

====== =====

wait 40970 40971 2998 2998 0 0 0

wait 32776 32777 2994 2994 0 0 0

wait 24582 24583 2985 2985 0 0 0

wait 16388 16389 2980 2980 0 0 0

syncd 221254 155707 31 31 0 0 0

caiUxOs 524540 2294015 3 0 0 3 0

netm 73746 73747 1 1 0 0 0

hats_nim 1671242 1220665 1 0 0 1 0

snmpd64 598258 1245291 1 1 0 0 0

639212 1728679 1 1 0 0 0

tprof 704622 2277437 1 0 0 1 0

trclogio 360524 2408625 1 1 0 0 0

trace 1523820 2523145 1 0 0 1 0

clinfo 1958102 2760945 1 1 0 0 0

sh 1572938 2285709 1 1 0 0 0

在这里,对wait进程作一点补充说明。

在AIX 5L下,你用ps aux会发现有一些root的wait进程

#ps aux |head -20

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME

COMMAND

oracle 266354 5.7 0.0 50136 27524 - A 15:40:35 0:32

oracleora92 (LOC

root 17214 3.1 0.0 40 40 - A Jul 04 24793:53 wait

root 16946 3.1 0.0 40 40 - A Jul 04 24633:59 wait

root 49176 2.7 0.0 40 40 - A Jul 04 21423:47 wait

oracle 344612 0.3 0.0 57588 34976 - A Jul 04 2663:08

ora_j000_ora92

oracle 430408 0.3 0.0 55908 33296 - A Jul 04 2220:57

ora_j001_ora92

wait就是CPU空闲的时候运行的空闲进程,AIX4上叫kproc。所以这个进程占用越大,表示机器越空闲。Wait进程的数量是由机器上的逻辑CPU的个数决定的,有几个逻辑CPU,就有几个wait进程。

CPU和Oracle数据库:

数据库什么操作会造成CPU负载高:

1, 大的查询,报表输出

2, 复杂的SQL语句,嵌套循环连接

3, 分组,排序

4, 连接

5, 统计信息更新

6, 恶劣的SQL语句

7, 错误的执行计划

内存

VMM概述

首先,还是简单讲解一下内存以及的VMM的一点工作原理。

内存和交换空间一般都是用页面来进行分配和管理的。在内存中存在两种类型的页面:计算内存(一般为可执行文件段中的页面)和文件内存(存储的数据文件的页面)。当我们执行程序或者读入数据的时候,内存中的页面就逐渐被占用。当空闲的内存只剩minfree的时候,vmm的调页进程就被唤醒,通过调页算法,将内存中的页面转移到交换空间中。一直到空闲内存达到maxfree,才停止调页。

计算内存

当您的进程对计算信息进行处理时,将使用到计算内存。这些工作段是临时的(暂时的),并且当进程终止或者页面被替换时,这些工作段将不复存在。它们没有对应的持久磁盘存储位置。在许多情况下,当一个进程终止时,将释放其物理和分页空间。当可用页面出现较大的峰值时,您可以在监视系统的过程中发现这种情况。在 VMM 中,当空闲物理内存较少时,可以将最近没有使用的程序从 RAM 移出到分页空间,以帮助释放物理内存,从而完成更多的实际工作。

文件内存

与计算内存不同,文件内存使用了持久段,并在磁盘上具有持久存储位置。数据文件或者可执行程序通常都映射为持久段,而不是工作段。数据文件可能与文件系统相关,如 JFS、JFS2 或 NFS。它们一直都位于内存中,直到文件被卸载、页面被替换、或者取消了到文件的链接。在将数据文件复制到 RAM 中之后,VMM 控制何时对这些页面进行覆盖或者将其用于存储其他数据。在可以选择的情况下,大多数人更希望将文件内存调出到磁盘,而不是计算内存。

当进程引用磁盘上的某个页面时,必须将其调入,而这可能会导致再次将其他的页面调出。VMM 常驻内存并在后台运行,尝试替换最近没有使用的页帧,其中使用到页面置换算法。它还可以帮助检测系统颠簸,当可用内存量很低并且不断地调入和调出页面以支持任务的处理时,可能会出现系统颠簸。实际上,VMM 中提供了一种内存负载控制算法,它可以检测系统是否出现颠簸,并尝试去解决这种情况。如果不加以处理,系统颠簸可能会导致系统停滞,因为内核此刻过分地关注于为页面腾出空间,而不是完成任何有实际意义的工作。

在上面的例子中,我们还涉及到两个参数:

1) Minfree:最小空闲页链表尺寸。一旦低于该值,系统偷页以填充页链

表,保证有足够的内存页面。偷页就是将不常用的页面替换出去。

2) Maxfree:最大空闲页链表尺寸。一旦高于该值,系统停止偷页。

如果发现空闲列表不足,可以用下面的方法增加minfree参数

#vmo -o minfree=1000 -o maxfree=1008

Setting maxfree to 1008

Setting minfree to 1000

#vmo –o minfree=1000 –o maxfree=1008 –P # -P参数使修改永久生效

一般情况下,minfree和maxfree通过下面的公式得到:

maxfree=cpu*128 ,minfree=maxfree-8

注意:在AIX 5.2之前的版本请使用/usr/samples/kernel/vmtune命令。

#/usr/samples/kernel/vmtune –f 1000 –F 1008

另外,关于内存的使用,我们还有两个经常碰到的参数需要关注:

Minperm:用户I/O文件访问的最小缓冲区页数

Maxperm:用户I/O文件访问的最大缓冲区页数

Minperm和maxperm这两个参数的默认值分别为20%和80%。在这里主要与性能相关的是maxperm参数。maxperm参数指定了文件页面可以占用内存的上限,因为文件页面不主动释放,所以很容易造成内存的文件页面过高的占用,导致其他的应用内存使用紧张。调整参数值的方法如下:

#vmo -o maxperm%=80 -o minperm%=20

Setting minperm% to 20

Setting maxperm% to 80

在AIX 5.2之前的版本请使用/usr/samples/kernel/vmtune命令。

#/usr/samples/kernel/vmtune -p 20–P 80 将min和max的值分别设置为20%和80%。

查看当前的参数设置方法如下:

1)vmo –a 显示当前所有的参数设置

在AIX 5.2之前的版本请使用 # /usr/samples/kernel/vmtune 显示当前所有的参数设置

#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 = 4587812 maxperm% = 80 maxpin = 4881650 maxpin% = 80 mbuf_heap_psize = 4096 memory_affinity = 1 memory_frames = 6029312 memplace_data = 2 memplace_mapped_file = 2memplace_shm_anonymous = 2 memplace_shm_named = 2 memplace_stack = 2 memplace_text = 2memplace_unmapped_file = 2 mempools = 4 minfree = 960 minperm = 1146952 minperm% = 20 nokilluid = 0 npskill = 49152 npsrpgmax = 393216 npsrpgmin = 294912 npsscrubmax = 393216 npsscrubmin = 294912 npswarn = 196608 num_spec_dataseg = 0 numpsblks = 6291456 page_steal_method = 0 pagecoloring = n/a pinnable_frames = 5601758 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 = 1显示minperm和maxperm和numperm的值。numperm值给出的是内存中文件页数。 系统调页的规则: 1) 如果numperm>maxperm,则只调出文件页面。 2) 如果numperm

3) 如果minperm

如果系统在向调页空间调出页面,可能使因为内存中的文件页数低于maxperm,从而也调出了部分的计算页面以达到maxfree的要求。在这种情况下,可以考虑把maxperm降低到低于numperm的某个值,从而阻止计算页面的调出。maxclient通常应该设置为一个小于或者等于maxperm的值。

增强JFS文件系统为它的缓冲区高速缓存使用客户机文件,这不受maxperm和minperm的影响。为了在限制增强JFS文件系统使用高速缓存,可以指定maxclient的值,避免在它进行页面替换的时候,替换其他类型的页。

上述讲解的大部分是基于AIX5.2版本的。

如何优化

在 AIX 5L之前,您可能曾经使用过 vmtune 命令对您的 VMM 系统进行优化。尽管在 AIX Version 5.2 中提供了 vmo 命令,但 vmtune 命令也可以使用,直到 AIX Version 5.3。在 AIX Version 5.3 中,您不能够再使用 vmtune 这一命令了,大多数实际参数都是相同的。

让我们来介绍一下 AIX 5L 中页帧方面一项重要的变化。从 POWER4 处理器开始,AIX 可以支持最大 16MB 的页面大小。实际上,POWER5 芯片支持四种虚拟内存页面的大小:4KB、64KB、16MB 和 16GB。通过下面一项简单的 vmo 更改,您就可以对系统进行优化以提供大型的页面,从而对于消耗大量内存的应用程序极大地提高系统性能。性能之所以得到了改进,是因为提高了 Translation Lookaside Buffer (TLB) 的命中率,这是因为

TLB 可以映射到更大的虚拟内存范围。例如 Oracle 数据库,无论是联机事务处理 (OLTP) 或者数据仓库应用程序,都可以从大型页面的使用中获益。这是因为 Oracle 使用了大量的虚拟内存,特别是对于其系统全局区 (SGA)。

这里使用的示例是一个运行 AIX Version 5.3 的 p550 LPAR 上的

Oracle 数据库服务器。该系统可用于 OLTP 和数据仓库。

最重要的vmo设置是 minperm 和 maxperm。将这些参数设置为适合您的系统的值,以确保对计算内存或者文件内存进行优化。在大多数情况下,您并不希望调出工作段,因为这样做会导致系统进行没有必要的页面调出,并且会降低性能。以前,它的工作方式非常简单:如果您的文件页面 (numperm%) 大于

maxperm%,那么页面置换算法将仅替换文件页面。当它小于 minperm 时,可以替换文件页面和计算页面。如果它的值位于两者之间,那么将仅替换文件页面,除非重分页的文件页面的数目大于计算页面。还有另一种方法,如果您的

numperm 大于 maxperm,您可以开始替换持久的存储。基于这种方法学,早期的方法是调整您的 minperm 和 maxperm 参数,将 maxperm 设置得比较低(例如,<20),而将 minperm 设置为 <=10。您可以使用这种方法来优化您的数据库服务器。

所有的这些方法都发生了变化。新的方法将 maxperm 设置为一个比较高的值(例如,>80),并且确保将 lru_file_repage 参数设置为 0。lru_file_repage 是在带 ML4 的 AIX Version 5.2 和 AIX Version

5.3 的 ML1 中首次引入的。这个参数说明了是否应该考虑 VMM 重分页计数,以及它应该替换何种类型的内存。其缺省设置为 1,所以您需要对它进行更改。当您将这个参数设置为 0 时,它将告诉 VMM,您希望它仅替换文件页面,而不是计算页面。如果您的 numperm 小于 minperm 或者大于

maxperm,这种情况会发生变化,这正是您希望将 maxperm 设置得较高而将

minperm 设置得较低的原因。我们不应该忘记一个事实,对这个值进行优化的主要原因是因为您希望保护计算内存。回到前面的示例,Oracle 使用它自己的缓存,同时使用 AIX 文件缓存,但是却产生了混淆,所以您希望停止它。在这个场景中,如果您打算降低 maxperm,那么您将会停止正在运行的应用程序缓存程序。

设置了这些关键的优化参数。

设置优化参数

vmo -p -o minperm%=5

vmo -p -o maxperm%=90

vmo -p -o maxclient%=90

尽管您已经习惯于对这些参数进行更改,但是现在,您只需保持

strict_maxperm 和 strict_maxclient 的缺省数值即可。如果将

strict_maxperm 更改为 1,那么它将会对可用于持久文件缓存的内存量设置一个硬限制。通过将 maxperm 值作为缓存的上限,可以实现这一点。现在,没有必要这样做,因为更改 lru_file_repage 参数是一种更加有效的优化方法,而您并不希望使用 AIX 文件缓存。

还有两个其他的重要参数需要说明,它们是 minfree 和 maxfree。如果空闲列表中的页面数降低到低于 minfree 参数,那么 VMM 开始替换页面(只需添加到空闲列表),这样做并不是很合适。它将继续进行这项操作,直到空闲列表至少包含 maxfree 参数中指定的页面数。

在较早版本的 AIX 中,当缺省 minfree 设置为 120 时,通常您将会看到空闲列表为 120 或者更低,而这将导致进行没有必要的分页,更糟糕的是,会阻塞那些需要空闲帧的线程,因为这个值设置得过低。要解决这个问题,在

AIX Version 5.3 中,将 minfree 和 maxfree 的缺省值分别提高到

960 和 1088。如果您正在运行 AIX Version 5.2 或者更早的版本,我建议进行下面的设置,您可以使用的命令,手动地进行更改。

手动地设置 minfree 和 maxfree 参数

vmo -p -o minfree=960

vmo -p -o maxfree=1088

AIX Version 5.3 内存方面的变化和改进

让我们先研究一下 AIX Version 5.3 中与内存有关的一些最新的变化。适当地使用 AIX Version 5.3 中的内存管理增强功能,可以帮助您高效地对系统进行优化。有关其他的方面,让我们介绍一下页面空间清理、动态的 xmalloc、内存关联和 Watson malloc。

页面空间清理:在某些情况下,这种特性允许系统释放分页空间磁盘块,这样一来,您就不需要为给定的工作负载配置相应的分页空间。仅在使用延迟页面空间分配策略时,才能使用这种特性。

动态的 xmalloc 调试 (xmdbg):这种特性通过改进内存分配的整体诊断功能,提高了系统的可靠性。。它允许客户改变收集的诊断内存量,而无需重新启动。

Watson malloc:与内存碎片的缺省实现相比,这种新的 malloc 子系统能够快速处理一些小的请求。与缺省实现 Yorktown 相比,它所消耗的内存非常少。为了方便调试,还添加了一些新的特性,以帮助您修复各种内存分配问题。

改进的多种页面大小支持:正如前面在优化部分中所介绍的,现在有四种不同的页面大小可供使用。这些大小分别为:

o

4KB

o

64KB

o

16MB

o

16GB

VMM 监视工具:一些监视工具,如 vmstat 和 svmon

内存关联:对于 AIX Version 5.3,您无法禁用内存关联,在 AIX

Version 5.2 中也同样如此。这样做的目的是,在内存模块中为处理器上产生缺页的进程提供内存分配的功能。在完成了内存分配之后,处理器可以首先访问附加到其自身模块的内存,然后查找其他的模块,这样可以提高性能。要禁用 AIX Version 5.2 上的内存关联支持,您可以•

使用下面的 vmo 命令: vmo -o memory_affinity=0

您还应该注意,不再需要在 中保存任何可调整的设置。现在,新的方法使用 /etc/tunables,这无疑是一项改进。尽管这个特性是在 AIX

Version 5.2 而不是 Version 5.3 中引入的,但是仍然值得在这里进行说明。

UNIX 通用的内存监视

在这个部分中,我为在所有 UNIX 分发版都可以使用的一些通用 UNIX 工具提供了概述,包括 ps、sar 和 vmstat。其中的大多数工具都允许您快速地对性能问题进行故障排除,但是它们并不适合用于进行历史趋势研究和分析。

大多数管理员都不善于使用 ps 命令对可能的内存瓶颈进行故障排除。事实上,许多 UNIX 管理员甚至不知道可以使用 ps 帮助确定内存问题的原因。ps 最常用的功能是查看系统中运行的进程。

使用 ps 查看系统中运行的进程

运行下列命令,显示内存占用前10位的进程。

# ps gv |sort +6b -nr |head -10

2490538 - A 191:56 0 11840 32748 xx 45762 20924 0.1 0.0

ora_j00

2039970 - A 592:59 11 11728 32648 xx 45762 20924 0.3 0.0

ora_j00

2588922 - A 1118:31 22 11712 32632 xx 45762 20924 0.6 0.0

ora_j0

2523168 - A 305:01 1 11688 32608 xx 45762 20924 0.2 0.0

ora_j00

2474214 - A 0:01 0 11588 32512 xx 45762 20924 0.1 0.0

ora_j00

2007282 - A 0:01 0 10384 31308 xx 45762 20924 0.0 0.0

ora_j00

508120 - A 32:58 662 9344 27164 xx 45762 20924 0.0 0.0

ora_dbw

1351908 - A 0:02 1 5668 26560 xx 45762 20924 0.0 0.0

oracleo

3801250 - A 203:22 0 5648 26556 xx 45762 20924 0.1 0.0

oracleo

正如您所看到的,上面的示例中并没有提供很详细的信息来帮助您确定内存瓶颈。上面命令向您显示了系统中每个活动进程的内存使用情况,并以一种恰当的方式进行了排序。其中按照旧式 Berkeley Software Distribution

(BSD) 的方式使用了 ps,不包含短横线

每个活动进程的内存使用情况

# ps gv | head -n 1; ps gv | egrep -v "RSS" | sort +6b -7 -n -r

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

15256 - A 64:15 755 2572 2888 xx 2356 316 0.9 0.0 /usr/lpp/

22752 - A 0:08 261 1960 1980 32768 465 20 0.0 0.0 dtwm

14654 - A 0:00 324 1932 1932 xx 198 0 0.0 0.0 /usr/sbin

20700 - A 0:07 271 1868 1896 32768 95 28 0.0 0.0 /usr/dt/b

20444 - A 0:03 203 1736 1824 32768 551 88 0.0 0.0 dtfile

17602 - A 0:00 274 948 1644 32768 817 696 0.0 0.0 sendmail:

13218 - A 0:00 74 1620 1620 xx 116 0 0.0 0.0 /usr/sbin

让我们先来看看这些信息所表示的含义。

RSS——每个进程的文本和数据段的 RAM 使用量。PID 为 15256

的进程使用了 2888k。

%MEM——RSS / Total RAM 的实际用量。监视 %MEM 使用达到百分之四十到七十的进程。

TRS——文本段的 RAM 使用量,单位为 KB。

SIZE——为这个进程(文本和数据)分配的分页空间的实际大小。

vmstat 可以报告许多信息,包括内核线程、CPU 活动、虚拟内存、分页、阻塞的 I/O 磁盘、以及相关信息。对我来说,要了解系统的运行情况,这是最快捷且最原始的方法。

使用 vmstat 以确定瓶颈的原因

# vmstat 1 4

System Configuration: lcpu=4 mem=4096MB

kthr memory page faults cpu

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

r b avm fre re pi po fr sr cy in sy cs us sy id wa

1 2 136583 127 0 4 57 44 92 0 345 2223 605 30 40 29 1

2 7 136587 118 0 2 230 0 245 0 329 3451 526 20 37 10 33

1 6 136587 157 0 3 67 0 678 0 334 3304 536 25 32 20 23

3 8 136587 111 0 5 61 0 693 0 329 3341 511 19 26 35 20

让我们首先来说明这些列所表示的含义:

内存数据:

avm——您所使用的活动虚拟内存量(单位为 4k 大小的页面),不包括文件页面。

fre——内存空闲列表的大小。在大多数情况下,我并不担心这个值什么时候变得很小,因为 AIX 总是会充分地使用内存,并且不会像您希望•

的那样尽早地释放内存。这个设置由 vmo 命令的 minfree 参数来确定。归根结底,分页的信息更加重要。

pi——从分页空间调入的页面。

po——调出到分页空间的页面。

CPU 和 I/O:

r——在您指定的时间间隔内,可运行内核线程的平均数量。

b——在您指定的时间间隔内,位于虚拟内存等待队列中的内核线程的平均数量。如果 r 不大于 b,通常是 CPU 问题的症状,这可能是由于

I/O 或者内存瓶颈造成的。

us——用户时间。

sy——系统时间。

id——空闲时间。

wa——等待 I/O。

自从有了 UNIX,就有了 sar 命令,并且每个人都曾经用过这个命令。使用 -r

标志可以提供一些 VMM 信息。

使用带 -r 标志的 sar 以获得 VMM 的信息

# sar -r 1 5

System Configuration: lcpu=4 mem=4096MB

06:18:05 slots cycle/s fault/s odio/s

06:18:06 1048052 0.00 387.25 0.00

06:18:07 1048052 0.00 112.97 0.00

06:18:08 1048052 0.00 45.00 79.21

06:18:09 1048052 0.00 216.00 0.00

06:18:10 1048052 0.00 8.00 0.00

Average 1048052 0 79 16

那么,这个结果究竟意味着什么呢?

cycle/s——报告每秒的页面置换周期数。

fault/s——提供每秒的缺页次数。

Slots——提供分页空间中空闲页面的数目。

odio/s——提供每秒的非分页磁盘 I/O 次数。

在这个示例中,您可以看到每秒钟有许多次的缺页,但是其他的值并不大。您还可以看到,分页空间中有 1048052 个 4k 的页面可用,总计约 4GB。下面,让我们再来深入地研究特定 AIX 工具的使用。

特定的 AIX 内存监视

在这个部分中,我提供了关于可用的特定 AIX 工具的概述,包括 svmon、procmon、topas 和 nmon。其中的大多数工具都允许您快速地进行故障排除,并获取相关的数据以便进行历史趋势研究和分析。

svmon 是一种分析实用工具。它专门针对于 VMM。它可以提供许多信息,包括所使用的实际、虚拟和分页空间内存。-G 标志可以为主机中的内存使用情况提供全局的视图。

使用带 -G 标志的 svmon

# svmon -G

size inuse free pin virtual

memory 1048576 1048416 160 79327 137750

pg space 1048576 524

work pers clnt lpage

pin 79327 0 0 0

in use 137764 910652 0 0

其中的 size 列报告了 RAM 的大小,单位是大小为 4k 的页面。其中的

inuse 列报告了进程所使用的 RAM 中的页面数,加上属于一个已终止的进程但仍位于 RAM 中的持久页面的数目。其中的 free 列报告了空闲列表中页面的数目。其中的 pin 列报告了物理内存 (RAM) 中固定的页面数。固定的页面不能被调出。

paging space 列报告了分页空间的实际使用情况(单位是大小为 4k 的页面)。重要的是,应该清楚这个结果与 vmstat 所报告的结果之间的区别。vmstat 中的 avm 列显示了访问的所有虚拟内存,即使它没有被调出。我还习惯查看工作和持久页面的数目。这些参数显示了 RAM 中工作和持久页面的数目。这个内容为什么非常重要呢?当您的进程对计算信息进行处理时,将使用到计算内存。它们使用工作段,而这些工作段是临时的(暂时的),并且当进程终止或者页面被替换时,这些工作段将不复存在。文件内存使用持久段,并在磁盘上具有持久的存储位置。数据文件或者可执行程序通常都映射为持久段,而不是工作段。在可以选择的情况下,您更希望将文件内存调出到磁盘,而不是计算内存。在这种情况下,与文件内存相比,计算内存更有可能被调出。也许,对 vmo 参数稍作优化就可以极大提高系统的性能。svmon 的另一个有价值的特性是,您可以显示给定进程的内存统计信息。下面提供了一个示例。

使用 svmon 显示给定进程的内存统计信息

# svmon -P | grep -p 15256

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

Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd LPage

15256 X 12102 3221 0 12022 N N N

从这个示例中,您可以确定该进程并没有使用分页空间。使用前面介绍过的 ps

命令,再加上 svmon,您就可以找出大量消耗内存资源的位置。

topas

图 1. topas 工具

正如您所看到的,运行 topas 将为您提供一个有关进程信息、CPU、I/O 和

VMM 活动的列表。从这个列表中,您可以看到该系统仅使用了很少的分页空间。我常常使用这个命令快速地进行故障排除,特别是当我希望在屏幕上显示比 vmstat 更详细的内容时。我将 topas 看作是 vmstat 的图形化版本。在经过改进之后,现在它可以捕获数据以进行历史分析。

procmon 命令又如何呢?它在 AIX Version 5.3 中首次引入,不仅可以提供整体 CPU 性能统计,还允许您对实际运行的进程进行相应的操作。您可能已经了解,可以动态地对一个进程使用 kill 或者 renice 命令,但我敢打赌,您肯定不清楚如何深入地研究有关内存的内容。

尽管我认为人们通常使用这个工具进行 CPU 分析,但是它也为 svmon 提供了很好的挂钩,以便在紧要关头为您提供帮助。这个视图可以为从 procmon 中

使用 svmon 实用工具设置相关的选项,它允许您以一种更合适的格式提取信息。

图 2. 为从 procmon 中使用 svmon 实用工具设置选项

您还可以将 procmon 数据导出到一个文件,这使得它成为一种优秀的数据收集工具。

nmon

图 3. nmon 分析输出

在使用这个工具的过程中,您将看到 nmon 所提供的许多不同类型的视图,这些视图可以提供所有关于 CPU、I/O 和内存的使用信息。

交换空间

什么是交换(分页)空间?它是与 VMM 有关的。VMM 使用交换(分页)空间存储没有使用活动 RAM 的进程。正是因为这个目的,交换空间是系统整体性能的关键组件。作为一名管理员,您需要了解如何监视和优化您的分页参数。分页空间本身是一个特殊的逻辑卷,它存储了当前不访问的信息。您必须确保您的系统拥有足够的分页空间。如果分页空间过小,整个进程可能会丢失,并且当所有的空间都占满后,系统可能会崩溃。尽管值得再次说明,分页空间是

VMM 中的一部分,但是更重要的是真正地理解内核如何将进程调入到 RAM

中,过多的分页肯定会对性能造成影响。AIX 通过将内核与 VMM 紧密集成在一起,实现了一种称为请求分页的方法。事实上,内核本身的大部分都驻留在虚拟内存中,这样可以帮助释放它的片段空间以用于其他进程。例如,对于使用 Oracle 联机事务处理 (OLTP) 类型数据库的系统,在配置多大的交换空间以及如何优化分页参数方面,通常有一些特定的推荐方案。如果不能真正地了解系统的运行状况,您就无法对分页设置进行真正地优化。您需要了解所使用的工具、如何最好地分析将要捕获的数据,并熟悉实现分页空间的最佳实践。根据经验,导致系统崩溃的首要原因就是耗尽了分页空间。

请求分页

大多数管理员都认为分页是一件很麻烦的事情。实际上,分页是 AIX 所完成的任务中非常必要的一部分,这是由于 AIX 内核与 VMM 及其请求分页的实现进行了紧密的集成。请求分页的工作原理是,内核一次仅加载部分页面到实际内存中。当 CPU 需要另一个页面时,它会到 RAM 中查找。如果无法在

RAM 中找到这个页面,则出现一次缺页,然后向内核发出信号以便从磁盘中加载更多的页面到 RAM。请求分页的一个优点是,分页空间不需要非常大,因为数据总是在分页空间和 RAM 之间不断地交换。在较早的 UNIX系统中,将分页预先分配到磁盘,无论使用还是不使用它们。这使得所分配的磁盘空间

可能永远不会被使用。从本质上说,请求分页可以避免盲目地分配磁盘空间。应该使得进程的交换最少,因为许多任务可能存储在 RAM 中。的确如此,因为进程(页面)只有一部分存储在 RAM 中。

交换指的是什么呢?尽管分页和交换通常可以互换使用,但它们之间存在细微的区别。如前所述,在进行分页时,进程的部分内容将在磁盘和 RAM 之间来回移动。当发生交换时,会将整个进程来回移动。为了支持这种情况,在将进程移动到分页空间之前,AIX 会挂起整个进程。只有在将进程交换回 RAM 之后,才能够继续执行它。出现这样的情况并不是很好,您应该尽量防止交换的发生,交换可能会导致另一种称为颠簸的情况(稍后将介绍这个内容)发生。

作为一名 UNIX 管理员,您可能对分页和交换的一些概念已经非常熟悉。AIX

提供了三种不同模式的分页空间分配策略:延迟的页面空间分配(deferred

page space allocation)、晚页面空间分配(late page space

allocation)、早页面空间分配(early page space allocation)。AIX

的缺省策略是延迟的页面空间分配。这样可以确保将分页空间的分配延迟到必须调出页面的时候进行,从而确保不会浪费分页空间。事实上,当您拥有很大的 RAM 时,您甚至不需要使用任何分页空间。

确保没有浪费的分页空间

# lsps -a

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

hd6 hdisk0 rootvg 4096MB 1 yes yes lv

上例中仅使用了百分之一的分页空间。

让我们来看看 AIX 是如何处理分页空间分配的。

检查 AIX 如何处理分页空间分配

# vmo -a | grep def

defps = 1

说明使用了这种缺省的方法(延迟的页面空间分配)。要禁用这个策略,您需要将参数设置为 0。这将使得系统使用晚分页空间分配策略。晚分页空间分配策略会在 RAM 中相应的页面被修改时才分配分页磁盘块。这种方法通常用于那些性能比可靠性更加重要的环境。那么早页面空间分配又如何呢?如果您希望确保进程不会因为较低的分页情况而终止,通常可以使用这种策略。早页面空间分配策略可以预先分配分页空间。这是与晚分页空间分配策略截然相反的。对于可靠性要求很高的环境,可以使用这种策略。启用这种策略的方法是将

PSALLOC 环境变量设置为 early (PSALLOC=early)。

您还应该了解在 AIX Version 5.3 中首次引入的垃圾回收特性。这个特性允许您释放分页空间磁盘块,从而允许您配置比通常所需要的更少的分页空间。这种特性只能用于缺省的延迟页面空间分配策略。

监视和配置分页空间

在这个部分中,我将向您介绍如何监视系统中的分页空间。我还将介绍用于配置分页空间的各种命令,以及帮助系统管理员使用分页空间的其他工具。

要确定系统中分页空间的使用量,最简单的方法是运行 lsps 命令。

3. 运行 lsps 命令

# lsps -s

Total Paging Space Percent Used

4096MB 1%

您已经在前面看到了 -a 标志。使用 -s 标志,因为 -a 标志仅仅显示所使用的分页空间,而 -s 标志则可以提供所有分配的分页空间的汇总信息,包括使用早页面空间分配策略分配的空间。当然,这个标志仅适用于禁用了分页分配缺省方法的情况。

vmstat使用 vmstat

# vmstat 1 5

System Configuration: lcpu=2 mem=4096MB

kthr memory page faults cpu

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

r b avm fre re pi po fr sr cy in sy cs us sy id wa

1 0 166512 627 0 0 1 0 92 0 277 3260 278 3 1 96 0

1 0 166512 623 0 0 1 0 40 0 253 2260 108 2 1 96 1

1 0 166512 627 0 0 0 0 0 0 248 3343 91 0 1 96 2

1 0 166512 627 0 0 0 0 2 0 247 3164 84 0 1 99 0

1 0 166512 627 0 1 0 0 0 0 277 3260 83 2 1 97 0

其中,最重要的列包括:

avm——这一列表示您所使用的活动虚拟内存量(单位为 4k 大小的页面),不包括文件页面。

fre ——这一列表示内存空闲列表的大小。在大多数情况下,我并不担心这个值什么时候变得很小,因为 AIX 总是会充分地使用内存,并且不•

会像您希望的那样尽早地释放内存。这个设置由 vmo 命令的 minfree

参数来确定。归根结底,分页的信息更加重要。

pi——这一列表示从分页空间调入的页面数。

po——这一列表示调出到分页空间的页面数。