歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

《linux性能及調優指南》3.3內存瓶頸

3.3 內存瓶頸
On a Linux system, many programs run at the same time.
These programs support multiple users, and some processes are more used than others.
Some of these programs use a portion of memory while the rest are “sleeping.”
When an application accesses cache, the performance increases because an in-memory access retrieves data,
thereby eliminating the need to access slower disks.
在linux系統中,在同一時間有支持多個用戶的多個程序在運行,它們對內存使用有多有少;
應該程序訪問內存數據的效率要比磁盤高;


The OS uses an algorithm to control which programs will use physical memory and which are paged out.
This is transparent to user programs. Page space is a file created by the OS on a disk partition
to store user programs that are not currently in use. Typically, page sizes are 4 KB or 8 KB.
In Linux, the page size is defined by using the variable EXEC_PAGESIZE in the include/asm-<architecture>/param.h
kernel header file. The process used to page a process out to disk is called pageout.
操作系統使用一定的策略來決定哪些程序將使用物理內存,哪些程序將被從內存頁面中替出;
這些操作對用戶程序來說是透明的;
頁面空間是由操作系統在磁盤劃分上創建的文件,用來存儲當前未在使用的用戶程序;
通常,頁面大小為 4KB 或 8KB;
在Linux系統中,頁面大小由內核的頭文件:
include/asm-<architecture>/param.h
中的宏 EXEC_PAGESIZE 來定義;
進程使用的頁面被替換到磁盤稱為換頁 或 頁面溢出;


3.3.1 Finding memory bottlenecks
尋找內存瓶頸
文章的這部分使用了KDE的一個工具KDE System Guard來做內存檢測;

KDE,K桌面環境(Kool Desktop Environment)的縮寫。
一種著名的運行於 Linux、Unix 以及FreeBSD 等操作系統上面自由圖形工作環境,
整個系統采用的都是 TrollTech 公司所開發的Qt程序庫(現在屬於Digia公司)。
KDE 和 Gnome 都是 Linux 操作系統上最流行的桌面環境系統。

Start your analysis by listing the applications that are running on the server.
Determine how much physical memory and swap each application needs to run.
Figure 3-1 on page 83 shows KDE System Guard monitoring memory usage.

?\
圖 3.1 KDE System Guard內存監測

?The indicators in Table 3-1 can also help you define a problem with memory.
\
表3-1

Paging and swapping indicators
換頁和交換的意義
In Linux, as with all UNIX-based operating systems, there are differences between paging and swapping.
Paging moves individual pages to swap space on the disk;
swapping is a bigger operation that moves the entire address space of a process to swap space in one operation.
在Linux系統中,分布和交換是不同的;
換頁是將獨立的頁面移到磁盤的交換空間;
交換是更大的操作,它將整個進程的地址空間一次性移到磁盤的交換空間;


Swapping can have one of two causes:
導致交換的原因有兩個
. A process enters sleep mode.
進程進入 sleep 模式
This usually happens because the process depends on interactive action and editors, shells,
and data entry applications spend most of their time waiting for user input. During this time,
they are inactive.
這種情況通常是因為進程需要和編輯器,shell等交互,以及應用程序需要等待用戶的數據輸入;
在這是,它是非活動的;


. A process behaves poorly.
進程的異常行為
Paging can be a serious performance problem when the amount of free memory pages falls
below the minimum amount specified, because the paging mechanism is not able to handle
the requests for physical memory pages and the swap mechanism is called to free more pages.
This significantly increases I/O to disk and will quickly degrade a server’s performance.
當空閒內存頁面過小時,換頁會導致嚴重的性能問題,
因為換頁機制不能處理物理內存頁面的請求,而交換機制將會調用更多的空閒內存頁面。
這會急劇增加磁盤的I/O, 並快速地拉低服務器的性能

If your server is always paging to disk (a high page-out rate), consider adding more memory.
However, for systems with a low page-out rate, it might not affect performance.
如果服務器總是在換頁(一個很高的換頁率),就需要考慮增加內存;
當然,系統換頁率低時,它不會影響性能;

3.3.2 Performance tuning options
性能調整選項
It you believe there is a memory bottleneck,
consider performing one or more of these actions:
如果你確認是內存的瓶頸,可以考慮用下面的辦法來解決
. Tune the swap space using bigpages, hugetlb, shared memory.
調整交換空間,使用大頁面,大塊內存,共享內存

. Increase or decrease the size of pages.
增加或降低頁面的大小;
?
. Improve the handling of active and inactive memory.
改進對活動和非活動內存的處理;

. Adjust the page-out rate.
調整換頁率;
?
. Limit the resources used for each user on the server.
限制服務器上每個用戶的可用資源;

. Stop the services that are not needed, as discussed in “Daemons” on page 97.
停掉不需要的服務

. Add memory.
增加內存;
Copyright © Linux教程網 All Rights Reserved