致力于自动化测试技术,性能测试技术的研究,测试技术培训以及项目实施,做一个技术与实施的主导者。

[Linux系列] Memory Performance Statistics

上一篇 / 下一篇  2012-11-17 11:06:23 / 天气: 晴朗 / 心情: 平静 / 个人分类:Linux

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

内存性能统计,英文原版,原滋原味! ,原版的资料对于技术的细节描述,有时会更精确。

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

3.1. Memory Performance Statistics

Each system-wide Linux performance tool provides different ways to extract similar statistics. Although no tool displays all the statistics, some of the tools display the same statistics. The beginning of this chapter reviews the details of these statistics, and those descriptions are then referenced as the tools are described.51Testing软件测试网9@C(i4pH&n3Zp/kV

3.1.1. Memory Subsystem and Performance

In modernprocessors, saving information to and retrieving information from the memory subsystem usually takes longer than the CPU executing code and manipulating that information. The CPU usually spends a significant amount of time idle, waiting for instructions and data to be retrieved from memory before it can execute them or operate based on them. Processors have various levels of cache that compensate for the slow memory performance. Tools such asoprofilecan show where various processor cache misses can occur.

9R6VC'qp0

3.1.2. Memory Subsystem (Virtual Memory)

Any given Linuxsystem has a certain amount of RAM or physical memory. When addressing this physical memory, Linux breaks it up into chunks or "pages" of memory. When allocating or moving around memory, Linux operates on page-sized pieces rather than individual bytes. When reporting some memory statistics, the Linux kernel reports the number of pages per second, and this value can vary depending on the architecture it is running on.Listing 3.1creates a small application that displays the number of bytes per page for the current architecture.

a!pW koa0
Listing 3.1.
#include <unistd.h>

int main(int argc, char *argv[])

{

  printf("System page size: %d\n",getpagesize());

}
51Testing软件测试网6c ^px:{!I

On the IA32architecture, the page size is 4KB. In rare cases, these page-sized chunks of memory can cause too much overhead to track, so the kernel manipulates memory in much bigger chunks, known as HugePages. These are on the order of 2048KB rather than 4KB and greatly reduce the overhead for managing very large amounts of memory. Certain applications, such as Oracle, use these huge pages to load an enormous amount of data in memory while minimizing the overhead that the Linux kernel needs to manage it. If HugePages are not completely filled with data, these can waste a significant amount of memory. A half-filled normal page wastes 2KB of memory, whereas a half-filled HugePage can waste 1,024KB ofmemory.51Testing软件测试网qP?`-Es

The Linux kernel can take a scattered collection of these physical pages and present to applications a well laid-outvirtual memory space.51Testing软件测试网(hV$\%FY

3.1.2.1 Swap (Not Enough Physical Memory)

All systems have afixed amount of physical memory in the form. of RAM chips. The Linux kernel allows applications to run even if they require more memory than available with the physical memory. The Linux kernel uses the hard drive as a temporary memory. This hard drive space is called swap space.51Testing软件测试网~P f;w]#u&i)s

Although swap is an excellent way to allow processes to run, it is terribly slow. It can be up to 1,000 times slower for an application to use swap rather than physical memory. If a system is performing poorly, it usually proves helpful to determine how much swap the system isusing.51Testing软件测试网Ju%{k4_k

3.1.2.2 Buffers and Cache (Too Much Physical Memory)

Alternatively, if yoursystem has much more physical memory than required by your applications, Linux will cache recently used files in physical memory so that subsequent accesses to that file do not require an access to the hard drive. This can greatly speed up applications that access the hard drive frequently, which, obviously, can prove especially useful for frequently launched applications. The first time the application is launched, it needs to be read from the disk; if the application remains in the cache, however, it needs to be read from the much quicker physical memory. This disk cache differs from the processor cache mentioned in the previous chapter. Other thanoprofile,valgrind, andkcachegrind, most tools that report statistics about "cache" are actually referring to disk cache.51Testing软件测试网3?\1Iv| D8?!P6o

In addition to cache, Linux also uses extramemory as buffers. To further optimize applications, Linux sets aside memory to use for data that needs to be written to disk. These set-asides are called buffers. If an application has to write something to the disk, which would usually take a long time, Linux lets the application continue immediately but saves the file data into a memory buffer. At some point in the future, the buffer is flushed to disk, but the application can continue immediately.

D.S X%W:CUP0

It can be discouraging tosee very little free memory in a system because of the cache and buffer usage, but this is not necessarily a bad thing. By default, Linux tries to use as much of your memory as possible. This is good. If Linux detects any free memory, it caches applications and data in the free memory to speed up future accesses. Because it is usually a few orders of magnitude faster to access things from memory rather than disk, this can dramatically improve overall performance. When the system needs the cache memory for more important things, the cache memory is erased and given to the system. Subsequent access to the object thatwas previously cached has to go out to disk to be filled.

L)j[W-ES kx0
3.1.2.3 Active Versus Inactive Memory

Active memory iscurrently being used by a process. Inactive memory is memory that is allocated but has not been used for a while. Nothing is essentially different between the two types of memory. When required, the Linux kernel takes a process's least recently used memory pages and moves them from the active to the inactive list. When choosing which memory will be swapped to disk, the kernel chooses from the inactive memory list.

s k3g_,F U0
3.1.2.4 High Versus Low Memory

For 32-bitprocessors (for example, IA32) with 1GB or more of physical of memory, Linux must manage the physical memory as high and low memory. The high memory is not directly accessible by the Linux kernel and must be mapped into the low-memory range before it can be used. This is not a problem with 64-bit processors (such as AMD64/ EM6T, Alpha, or Itanium) because they can directly address additional memory that is available in current systems.51Testing软件测试网j*I/`cfE#jmn1n

3.1.2.5 Kernel Usage of Memory (Slabs)

In addition tothe memory that applications allocate, the Linux kernel consumes a certain amount for bookkeeping purposes. This bookkeeping includes, for example, keeping track of data arriving from network and disk I/O devices, as well as keeping track of which processes are running and which are sleeping. To manage this bookkeeping, the kernel has a series of caches that contains one or more slabs of memory. Each slab consists of a set of one or more objects. The amount of slab memory consumed by the kernel depends on which parts of the Linux kernel are being used, and can change as the type of load on the machine changes.

)b+{o:qu+m W:v oF0

TAG:

 

评分:0

我来说两句

vprince

vprince

6年软件测试经验,TIB自动化测试工作室核心成员,ATF框架核心设计和开发人员,熟悉软件自动化测试、性能测试,多年从事软件项目的自动化测试和性能测试,对自动化测试的框架设计开发、框架搭建以及实施有较为丰富的实战经验。 目前关注开源自动化测试领域、 基于Selenium构建Web自动化测试框架,为多家企业进行自动化测试培训、实施自动化测试项目。

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 67403
  • 日志数: 49
  • 建立时间: 2009-09-09
  • 更新时间: 2012-12-14

RSS订阅

Open Toolbar