Page Size 【转】

来源:互联网 发布:内外网络切换器设置 编辑:程序博客网 时间:2024/06/07 01:53
原文地址: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;}

 

下面是运行程序的结果:

 

 

 

原创粉丝点击