Page Size 【轉】

原文地址:http://blog.csdn.net/tttt418/article/details/6113860

看好多論文和源碼中都有Page Size的概念,我卻一直比較模糊,今天特地仔細查了一下。

 

基本概念

In the context of computer virtual memory, a page, memory page, or virtual page is a fixed-length block of main memory  that is contiguous in both physical memory addressing and virtual memory addressing. A page is usually the smallest unit of data for the following:

  • memory alloction performed by the operating system for a program; and
  • transfer between main memory and any other auxiliary store, such as hard disk drive.

 

在計算機虛擬內存的概念中,頁、內存頁或者虛擬頁是指內存中的一段固定長度的快,這個內存塊在物理地址和虛擬內存地址上都是連續的。一個頁通常是以下操作的最小單元:

  • 操作系統爲程序分配空間
  • 內存和外存傳輸,比如說硬盤。

下圖可以幫助我們更好的理解頁的概念:

 

 

 

 Traditionally, pages in a system had uniform size, for example 4096 bytes.

 

一般來說,系統中頁的大小是規定好的,比如說4096B,也即4KB

 

頁的內部分段

Rarely do processes require the use of an exact number of pages. As a result, the last page will likely only be partially full, wasting some amount of memory. Larger page sizes clearly increase the potential for wasted memory this way, as more potentially unused portions of memory are loaded into main memory. Smaller page sizes ensure a closer match to the actual amount of memory required in an allocation.

As an example, assume the page size is 1024KB. If a process allocates 1025KB, two pages must be used, resulting in 1023KB of unused space (where one page fully consumes 1024KB and the other only 1KB).

 

處理器在很少的情況下會用到需要正好幾個頁。因此,最後一個頁通常是半滿的,浪費掉一定數量的內存。很明顯越大的頁就更有可能浪費更多的空間,內存中就更有可能加載了更多未使用的內存。較小的頁能夠確保內存中開闢的大小與實際需要的大小更加一致。

比如說,假設頁大小爲1024KB(很大了)。如果處理器分配了1025KB的內存,那麼必須使用兩個頁,總成1023KB的未使用空間(一個頁被完全使用了1024KB,另一個只使用了1KB)。

 

 頁大小和硬盤讀取 

 

When transferring from disk, much of the delay is caused by seek time, the time it takes to correctly position the read/write heads above the disk platters. Because of this, large sequential transfers are more efficient than several smaller transfers. Transferring the same amount of data from disk to memory often requires less time with larger pages than with smaller pages.

 

當與硬盤進行交互時,大多數的延遲時間都是由於尋找位置的時間引起的,也就是花費在磁頭定位到正確的磁盤片上的時間。正是由於這個原因,大塊連續數據的讀寫要比不連續的幾個小塊更有效率。從磁盤讀取相同大小的數據到內存,使用大的頁大小比使用小的頁大小花費的時間更少。

 

確定在程序中使用多大的Page Size

 

Win32-based operating systems, such as Windows 9x, and NT may use the system function GetSystemInfo() from kernel32.dll.

 

Win32爲基礎的操作系統,比如說Win 9x 和 NT 可以使用kernel32.dll動態庫中的系統函數GetSystemInfo() 

 

#include <stdio.h>
#include <windows.h>
 
int main(void) {
	SYSTEM_INFO si;
	GetSystemInfo(&si);
 
	printf("The page size for this system is %u bytes./n", si.dwPageSize);
 
	return 0;
}

 

下面是運行程序的結果:

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章