⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib0023.html

📁 Memory Management—Algorithms and implementation in C/C++ Introduction Chapter 1 - Memory Manag
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">20-32MB</p>
</td><td class="td" align="left">
<p class="table-para">30 pages</p>
</td><td class="td" align="left">
<p class="table-para">145 pages</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">More than 32MB</p>
</td><td class="td" align="left">
<p class="table-para">50 pages</p>
</td><td class="td" align="left">
<p class="table-para">345 pages</p>
</td>
</tr>
</tbody>
</table>
<p class="para">The default maximum values can be transgressed if enough free page frames are available. This can be initiated by a user application through a call to the <span class="fixed">SetProcessWorkingSetSize ()</span> function. The only catch is that the application making the call will pass its process handle to the function, and <span class="fixed">SetProcessWorkingSetSize()</span> will verify that the invoking application has the necessary <span class="fixed">PROCESS_SET_QUOTA</span> privileges. If you merely want to determine the size of a working set, you can use the <span class="fixed">GetProcessWorkingSetSize()</span> Win32 function.</p>
<p class="para">In addition to managing working sets, Windows also maintains data on all the pages that are located in physical memory as a whole. Windows uses what is known as the <i class="emphasis">Page Frame Number database</i> (PFN) to track information regarding pages in DRAM. The PFN database is an array of data structures. Each page in physical memory has an entry. You can use the kernel debugger to get a status report from the PFN database:</p>
<div class="informalexample">
<pre class="literallayout">
kd&gt; !memusage
!memusage
loading PFN database
loading (99% complete)
             Zeroed:    1550 (  6200 kb)
               Free:       1 (     4 kb)
            Standby:   11424 ( 45696 kb)
           Modified:     683 (  2732 kb)<a name="253"></a><a name="IDX-108"></a>
    ModifiedNoWrite:       0 (     0 kb)
       Active/Valid:   19109 ( 76436 kb)
         Transition:       0 (     0 kb)
            Unknown:       0 (     0 kb)
              TOTAL:   32767 (131068 kb)
</pre>
</div>
<p class="para">As you can see, there are eight different types of page states. These types are enumerated and explained in <a class="internaljump" href="#ch02table07">Table 2.7</a>.</p>
<a name="254"></a><a name="ch02table07"></a>
<table class="table" border="1">
<caption class="table-title">
<span class="table-title"><span class="table-titlelabel">Table 2.7</span></span>
</caption>
<thead>
<tr valign="top">
<th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Page Frame Type</b>
</p>
</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Meaning</b>
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Zeroed</p>
</td><td class="td" align="left">
<p class="table-para">Page is free and initialized with zero values</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Free</p>
</td><td class="td" align="left">
<p class="table-para">Page is free but is uninitialized (stores garbage bytes)</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Standby</p>
</td><td class="td" align="left">
<p class="table-para">Recently removed from a working set, and was not modified while in the set</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Modified</p>
</td><td class="td" align="left">
<p class="table-para">Recently removed from a working set, and was modified while in the set</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">ModifiedNowrite</p>
</td><td class="td" align="left">
<p class="table-para">Like a "modified" page but will not be written to disk</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Active/Valid</p>
</td><td class="td" align="left">
<p class="table-para">Page is part of a current working set</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Transition</p>
</td><td class="td" align="left">
<p class="table-para">Page is in digital purgatory between the disk and physical memory</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Unknown</p>
</td><td class="td" align="left">
<p class="table-para">Danger! danger!, bad page frame, has caused hardware errors</p>
</td>
</tr>
</tbody>
</table>
<a></a>
</div>
<div class="section">
<h4 class="sect4-title">Memory Protection</h4>
<p class="first-para">Given Windows' rather minimal use of segmentation, I suspect that page faults provide the core memory protection mechanism. Remember that Windows has only two rings of privilege (kernel mode and user mode). This fits perfectly with the Supervisor/User privilege scheme that Intel paging supports. As with Linux and MMURTL, when a user program attempts to access memory belonging to the kernel, a page fault is generated and passed on to Windows to do what it sees fit. Typically, this means halting the program that caused the page fault.</p>
<p class="para">The nature of the page directory and page table bookkeeping also serves to keep one process from accessing physical memory being used by another process. Each process in Windows is supplied with its own page directory. This ensures that the linear address space used by the process will map to a unique physical address space. This is particularly important because Windows places each process in an identical linear address space.</p>
<p class="para">The additional protection supplied by the page table entry read/write flag, discussed in <a href="LiB0012.html#49" target="_parent" class="chapterjump">Chapter 1</a>, is reflected in the Win32 API. Take a look at the call to <span class="fixed">VirtualAlloc()</span> that was made in a previous example:</p>
<a name="255"></a><a name="IDX-109"></a>
<div class="informalexample">
<pre class="literallayout">
ptr = VirtualAlloc(NULL,nbytes,MEM_RESERVE,
      PAGE_READWRITE);
</pre>
</div>
<p class="para">The last argument is a memory access specifier. This specifier can be one of the eight macros enumerated in <a class="internaljump" href="#ch02table08">Table 2.8</a>.</p>
<a name="256"></a><a name="ch02table08"></a>
<table class="table" border="1">
<caption class="table-title">
<span class="table-title"><span class="table-titlelabel">Table 2.8</span></span>
</caption>
<thead>
<tr valign="top">
<th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Macro</b>
</p>
</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Meaning</b>
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">PAGE_READONLY</p>
</td><td class="td" align="left">
<p class="table-para">Page region can only be read</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">PAGE_READWRITE</p>
</td><td class="td" align="left">
<p class="table-para">Page region can be read and written to</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">PAGE_EXECUTE</p>
</td><td class="td" align="left">
<p class="table-para">Page region can be executed</p>
</td>
</tr>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -