FreeBSD下大内存的支持问题

发表于:2007-06-09来源:作者:点击数: 标签:
这几天看到有人问关于FreeBSD下大内存的问题,查了查相关资料,汇总如下: 1:解决方法-内核中加入optionsPAE 2:为什么出现这个问题 3:AMD的说明 剑心通明 回复于:2005-08-28 10:34:36 [color=red:93b728cf31]1:解决方法-内核中加入optionsPAE[/color:93b7

这几天看到有人问关于FreeBSD下大内存的问题,查了查相关资料,汇总如下:
1:解决方法-内核中加入options PAE
2:为什么出现这个问题
3:AMD的说明

 剑心通明 回复于:2005-08-28 10:34:36
[color=red:93b728cf31]1:解决方法-内核中加入options PAE [/color:93b728cf31]
[color=red:93b728cf31]下面内容摘自:http://journal.cnfug.org/issue8/000045.html[/color:93b728cf31]
[quote:93b728cf31]
大内存的机器是特指内存数超过4G(被用户和内核逻辑地址总和所限)的机器。为
解决这个问题,Intel在 Pentium Pro及其之后的CPU中加入了36位物理地址空间寻址能力。

加入了PAE功能的Intel Pentium Pro及其后的cpu允许内存最大可配置到64G。FreeBSD
(4。x系列从4。 9RELEASE开始,5.X系列从5.1-RELEASE开始)通过内核配置参数PAE
提供这种容量扩展支持。由于年存储体系 结构的局限性,多于和少于4g没多少差别; 
超过4g的那部分内存只是添加到可用内存池里。

要加入PAE支持,只要在内核配置文件中加入如下一行即可:

options PAE

注意: FreeBSD 中的PAE支持只对Intel IA-32 处理器有效。另外,FreeBSD中的PAE
支持还没有经过广泛 的测试, 应该和其它stable版的特性一样看做是beta级别的。

FreeBSD中的PAE支持有以下一些局限:

* 进程没办法访问超过4g的内存。

* 由于构建模块和内核的框架(framework)的不同,KLD不能在使用了PAE的内核中使用。

* 不使用bus_dma接口设备驱动,在使用了PAE支持的内核上,可能引起data corruption,
并且不被推荐 使用此类驱动。因此,在支持PAE的5。x中,内核将拒绝所有对PAE而言
无法识别的驱动。

* 有些系统参数能依据总的可用内存调节系统内存资源的使用。 这些微调不需要依据PAE
系统的内存大 小来分配。举一个kern.maxvnodes sysctl的例子,它控制了内核最大允许的
vnodes数。 调整它以及其它类似 参数需要慎重考虑,以设置为一个合理的数值。

* 也许应该增大内核虚拟地址空间或者说是减少所有对内核资源的严重消耗,以避免KVM不
够用。内核参 数KVA_PAGES 能用来增加KVA空间的大小.

对于所关心的性能及稳定性的问题,可以查看tuning的man手册。pae的man手册有FreeBSD的
PAE支持最新信息 。
[/quote:93b728cf31]
[color=red:93b728cf31]handbook中相关说明如下:[/color:93b728cf31]
[quote:93b728cf31]
8.4.1 大内存支持(PAE)
大内存配置的机器需要超过4GB的虚拟地址。 因为4GB的限制,Intel在Pentium&及后续的CPUs上增加了36位物理地址的支持。

Intel& Pentium Pro和后续的CPUs允许内存地址扩展到64GB.(PAE) FreeBSD通过PAE选项来支持这个能力。 在FreeBSD 4.X系列里面,4.9-RELEASE开始支持,FreeBSD 5.X系列里面,从5.1-RELEASE开始支持。 in the 4.X series of FreeBSD beginning with 4.9-RELEASE and in the 5.X series of FreeBSD beginning with 5.1-RELEASE。因为Intel架构的限制,高于或低于4GB都没有什么区别,内存分配到大于4GB仅仅是增加了可利用的内存池。

为了让内核支持PAE,只要增加下面这一行到配置文件:

options            PAE
注意: PAE在FreeBSD里面现在只能支持 Intel IA-32处理器。 同时,还应该注意,FreeBSD的PAE支持没有经过广泛的测试,和其他稳定的特性相比只能当作是beta版。

PAE在FreeBSD下有如下的一些限制:

进程不能接触大于4GB的VM空间。

KLD 模块不能加载到一个打开了PAE支持的内核里面,这是因为内核模块和内核的建立框架不一样。

没有使用bus_dma(9)界面的设备驱动程序在打开了PAE支持的内核里面会导致数据腐化(corruption)。因为这个原因,FreeBSD 5.X的PAE内核配置文件 把所有在打开了PAE的内核上不能工作的驱动程序排除在外。

一些系统打开了探测系统内存资源使用能力的功能,因为打开了 PAE支持,这些功能可能会被覆盖掉。 其中一个例子就是内核参数kern.maxvnodes,它是控制内核能使用的最大vnodes数目的,建议重新调整它及其他类似参数到合适的值。

为了避免KVA的消耗,很有必要增加系统的内核虚拟地址,或者减少很耗系统资源的内核选项的总量(看上面)。KVA_PAGES选项可以用来增加KVA空间。

为了稳定和高性能,建议查看tuning(7)手册页。pae(4)手册页包含 FreeBSD'sPAE支持的最新信息。[/quote:93b728cf31]

 剑心通明 回复于:2005-08-28 10:36:15
[color=red:4893648025]2:为什么出现这个问题[/color:4893648025]
在lists.freebsd.org上找到的,偶的英文很烂,哪位大哥给翻译翻译吧:)
[quote:4893648025]
First thing to keep in mind is that I'm talking about physical
addresses, not OS-specific virtual addresses.  Second thing to keep in
mind is that I'm talking about *address space*, not *RAM*.  There is a
big different here.  An address represents a location where data can be
stored or retrieved.  That location does _not_ have to be RAM.  It could
be a register on a APIC chip, or a memory array on a PCI card, or a
location in a local RAM chip.

PCI (AGP is really just like PCI from this perspective) specifically
allows the CPU to aclearcase/" target="_blank" >ccess registers and memory arrays on the cards as if
they were local addresses, that's the point of the MEMIO registers and
Base Address Registers.  When the CPU does a load or store of an address
that falls into these address ranges, the request doesn't go to RAM, it
goes to the PCI bus and is serviced by the appropriate card there.
Local RAM doesn't get involved at all.

PCI doesn't actually care much which addresses are used, but by
convention the PC platform puts them at the top of the 32-bit address
space.  But, what happens when you have so much RAM that the RAM could
service those very high addresses?  For many years that wasn't an issue
because it wasn't possible or practical to put that much RAM into a PC.
But now it is, so it's up to the memory controller and host bridge to
figure out what to do.  Many systems cause that high RAM to simply be
ignored, resulting in the loss of effective RAM (as you saw in your
case).  More complex systems will take the RAM that would occupy that
3.5-4GB address space and re-map it into the 4.0-4.5 address space.  The
RAM doesn't care because it's just an array of storage cells, it's up to
the memory controller to associate addresses with those storage cells.
Of course, that only works if you're using a 64-bit (or 32bit PAE
enabled) OS that can deal with physical addresses larger than 32 bits.

Intel Xeon systems typically do the remapping trick, so when you boot
FreeBSD i386+PAE or amd64 on them, they might show 4.5GB of RAM when
there reall is only 4GB (this is a limitation of how we compute RAM and
is purely cosmetic, but should be fixed).  Many AMD Opteron systems do
not do the remapping and result in you loosing effective RAM.  The
difference between Intel and AMD is because AMD puts the memory
controller into the CPU instead of in the PCI host bridge, so it's much
harder to have the two work together to do the remapping.  I believe
that there are some Opteron systems that can do this, though.

[/quote:4893648025]

 剑心通明 回复于:2005-08-28 11:31:42
[color=red:5ed025b04f]3:AMD的说明[/color:5ed025b04f]
[quote:5ed025b04f]
3.5.8 Memory Hoisting
Typically, memory mapped I/O space is mapped from MMIOLowAddr to 4GB-1, and DRAM
memory is mapped from address 0 to TOP_MEM, an address that is less or equal to MMIOLowAddr-
1. DRAM memory can also be mapped from 4GB to TOM2, an address greater than 4GB. Memory
hoisting is defined as reclaiming the DRAM space that would naturally reside in the MMIO hole just
below the 4G address level.
3.5.8.1 Memory Hoisting For Revision D and Earlier Revisions
Depending on the MMIOLowAddr value and how DRAM is populated, DRAM base and limit
registers and DRAM CS base and limit registers need to be programmed differently. If possible,
contiguous memory mapping is used. Sometimes a memory hole is generated in the DRAM memory
map (node hoisting) or in the DRAM CS map (chip select hoisting). In the case of chip select
hoisting, the memory hole is included in the memory map for the node that has a hoisted chip select.
The memory hole generated by the BIOS is equal to or greater than 4GB-MMIOLowAddr.
Chip select hoisting can not be used in the case of a single 4GB chip select bank. Also, DRAM and
node memory interleaving can not be used on a node with chip select hoisting.
MMIOLowAddr is not known by the BIOS at the time when DRAM chip selects are programmed in
POST. The BIOS either assumes the MMIOLowAddr value or uses the value selected by the user
with a setup option.
The following algorithm is designed to be used to generate the DRAM memory map and DRAM CS
map. TOP_MEM is MSR C001_001Ah, TOM2 is C001_001Dh, MAX_NODES is number of nodes
100 Memory System Configuration Chapter 3
26094 Rev. 3.26 April 2005 BIOS and Kernel Developer’s Guide for the AMD Athlon™ 64 and
AMD Opteron™ Processors
in the system, NodeBase[i] are DRAM base registers, CSBase[i] are DRAM CS base registers,
CSMask[i] are DRAM CS mask registers, BE[i] are CSBE bits in DRAM CS base registers.
TOP_MEM = TOM2 = MemTop = 0;
for(Node = 0; Node < MAX_NODES; Node++){
NextCSBase = 0;
NodeBase[Node] = MemTop;
for(p = 0; p < 8; p++){
MaxBankSize = -1;
for(q = 0; q < 8; q++){
if(Size[q] != 0 && BE[q] == 0 && Size[q] > MaxBankSize){
MaxBankSize = Size[q];
b = q;
}
}
if(MaxBankSize != -1){
if(MemTop && MemTop < 4GB && (MemTop + Size[b]) > MMIOLowAddr){
TOP_MEM = MemTop;
MemTop = 4GB;
if(NodeBase[Node] == TOP_MEM){ // Node hoisting
NodeBase[Node] = 4GB;
NextCSBase = 0;
}
else { // Chip select hoisting
CSBase[b] = 4GB - NodeBase[Node];
NextCSBase = 4GB - NodeBase[Node];
}
else {
CSBase[b] = NextCSBase;
}
MemTop = MemTop + Size[b];
CSMask[b] = Size[b] - 1;
NextCSBase = NextCSBase + Size[b];
BE[b] = 1;
}
}
}
if (TOP_MEM)TOM2 = MemTop;
else TOP_MEM = MemTop;
3.5.8.2 Memory Hoisting For Revision E and Later Revisions
Memory that resides in the MMIO is repositioned above the 4G level by programming the DRAM
Hole Address Register and the DramLimit properly. For systems that have node interleaving enabled
these registers must be programmed on all nodes, otherwise only the node with the DRAM hole needs
to have these registers programmed.
The memory hoisting offset field, DramHoleOffset, is programmed as shown in the following
equation:
DramHoleOffset[31:24] = ( (100h - DramHoleBase[31:24]) + DramBase[31:24]);
Chapter 3 Memory System Configuration 101
BIOS and Kernel Developer’s Guide for the AMD Athlon™ 64 and
AMD Opteron™ Processors
26094 Rev. 3.26 April 2005
The DramLimit field must be programmed to include the size of the DRAM hole as shown in the
following equation:
DramLimit = 4GB + Hole Size;
Example. A two processor system with 4 GB DRAM on each processor and a 1 GB MMIO hole.
Processor 0 DramBase[39:24] = 0000h.
Processor 0 DramLimit[39:24] = 013Fh (5GB -1)
Processor 0 DramHoleBase[31:24] = C0h (3GB).
Processor 0 DramHoleOffset [31:24] = 40h (1GB).
Processor 1 DramBase[39:24] = 0140h (5GB)
Processor 1 DramLimit[39:24] = 023Fh (9GB -1)
Processor 1 DramHoleBase[31:24] = 00h (Memory hoisting is not enabled on node 1).
Processor 1 DramHoleOffset [31:24] = 00b (Memory hoisting is not enabled on node 1).

[/quote:5ed025b04f]

 zero-B 回复于:2005-08-28 13:28:15
也就说在IA-32的架构下内存大于4G基本上可以认为是没用的了。

 雨中漫步 回复于:2005-08-29 12:27:09
不知采用第一种方法有没有成功的案例?

 剑心通明 回复于:2005-08-29 15:40:40
[quote:5fdc82545b="雨中漫步"]不知采用第一种方法有没有成功的案例?[/quote:5fdc82545b]
不知道,我这只有一个4G的机器,作整网的代理,不敢乱动,哪位如果有条件可以试试

 hanyangz 回复于:2005-08-29 23:33:59
有用。
1、增加了磁盘cache
2、单进程不超过4g,但多进程可以达到多个4g.在大内存构架上,1台服务器可以起多个进程,如果cpu不是瓶颈的话

 gvim 回复于:2005-08-30 01:44:21
[quote:5e841e41b8="zero-B"]也就说在IA-32的架构下内存大于4G基本上可以认为是没用的了。[/quote:5e841e41b8]

IA-32的P 4以上的机器可以使用硬件+OS支持访问使用64G的内存.
go and see http://lwn.net/Articles/39925/

 yj31920 回复于:2005-08-30 03:34:55
呵呵 //

原文转自:http://www.ltesting.net