免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: chenzhanyiczy

高端内存 [复制链接]

论坛徽章:
0
发表于 2010-03-25 20:28 |显示全部楼层
回复 39# chenzhanyiczy


    对,显然要改变页表什么的,这个改变的过程就是ioremap,所以说ioremap返回的地址都在高端地址上。

论坛徽章:
0
发表于 2010-03-25 20:48 |显示全部楼层
如果你的内存超过1G,如你所说的用全部,那么把内内核的页目录项(768-1023)都填满,也只能映射1G的内存,
也许你又想,我可以把1G以后的内存映射到0-767页目录项,可是由于每个进程的的 0-767项都可能不一样,
它无法保证在任何时刻的内核态都能访问到它(就是超过1G的内存),
因为进程进入内核态是不会去切换页表的,除非要切换进程了;
即使你有算法让内核态可以去访问它,那么内核要遍历所有的进程页表是很低级效。
还有,你还有一些io要映射,你也需要页表,同样,你不可能在0~767项映射,因为这些资源不可能只给特定进程用;

论坛徽章:
0
发表于 2010-03-25 22:24 |显示全部楼层
LS奇门兄说的不错。
“不可能出现有部分物理内存,内核看不到而用户程序可以看到的情况。”
这句是从OS设计的角度来说的。
当然,你可以自己写个OS,就把物理内存里大于1G的映射到用户进程的虚拟地址空间。但是有LS说的哪些问题。
主要是用户进程是动态的。如果你把大于1G的物理内存给了用户进程1,那么其他用户进程是不能用这1G的。同时,如果发生了进程切换,另外一个进程2也要访问和进程1的物理地址对应的虚拟地址一样的地址。这时OS还要判断下当前进程是1还是2,然后做相应的处理。

同时,如果进程1结束了,剩下的空间怎么办?给谁?还要有个算法来决定。

论坛徽章:
0
发表于 2010-03-25 22:35 |显示全部楼层
回复 40# snail_314

补充一些:
PCI支持2种IO访问方式,一个是蜗牛老兄说的 MEMORY MAPPED IO,另外一个是IO PORT,也就是用IN, OUT指令访问的。另外,不同的体系结构可能不一样,X86支持上面说的2种。 ARM只有MEMORY MAPPED IO 的观念。

关于PCI设备地址如何映射到4G物理地址空间,可以看看ACPI SPEC 4.0 CHAPTER 14. 还有PCI的一些SPEC.

论坛徽章:
0
发表于 2010-03-26 07:35 |显示全部楼层
本帖最后由 snail_314 于 2010-03-26 07:50 编辑

回复 43# accessory


    不管物理内存有多大,内核当然都可以‘看到’,这里的‘看到’不等价于‘访问’,高端虚拟地址是为了让内核能‘访问’到大于1G的内存,并不是为了让内核能‘看到’大于1G的内存。内核在boot的时候就可以‘看到’系统到底有多大内存了。站在OS设计的角度,内核能否‘访问’大于1G的内存也不是用户能否‘访问’1G的内存的必要条件。

“当然,你可以自己写个OS,就把物理内存里大于1G的映射到用户进程的虚拟地址空间。”
linux就是这么做的啊。只要用户申请虚拟地址空间并且读写它们时,内核就会找满足大小需求的物理内存,不管是大于1G还是小于1G的物理内存,只要是free的,当然都可以被映射给用户的虚拟地址空间。

论坛徽章:
0
发表于 2010-03-26 13:53 |显示全部楼层
高端内存给应用程序用的。
内核当然可以访问所有的物理内存了。否则应用程序的页面谁来准备好?
内核之所以不直接访问高端内存因为,那不安全,也没必要。要映射成内核的页面,设置特殊的页面保护,这样才保证内核使用时,这个页面不会丢失也不会被用户随意更改。这种情况经常出现在内核和用户交换数据时,或者dma的时候。

论坛徽章:
0
发表于 2010-03-26 14:16 |显示全部楼层
回复 1# chenzhanyiczy
sorry for that there is no chinese input soft on this computer, so i reply in my clumsy English.

To understand this problem, first of all, you should know how kernel use the memory and usage of the most mem used by kernel.  I think the kernel use memory in three places. They are as follows.
     First, dynamic objects - that is slab;
     Second, pagecache used by fs;
     Third,dma or not dma used by drievers, such as net card.
Here, we ignore the stack used by kernel.

Actually, page cahce dominate the  memory kernel used. Now we return  back to pagecache. Why page cache? Of course cache the data on the disk ,as a result saving the time and higher throughput.

Now, assume we have 16GB mem, and we want cache data as more as possible. Of course we want high mem. so in radix tree, we reference page with struct page rather page's address. Consequently, we can cache more data. If we want use the data, we can firstly map the page to the 128M , after finishing, we unmap it.  so other pages can be used too.

so do  the slab.

论坛徽章:
0
发表于 2010-03-26 14:19 |显示全部楼层
回复 1# chenzhanyiczy
sorry for that there is no chinese input soft on this computer, so i reply in my clumsy English.

To understand this problem, first of all, you should know howkernel use the memory and usage of the most mem used by kernel.  Ithink the kernel use memory in three places. They are as follows.
     First, dynamic objects - that is slab;
     Second, pagecache used by fs;
     Third,dma or not dma used by drievers, such as net card.
Here, we ignore the stack used by kernel.

Actually, page cahce dominate the  memory kernel used. Now we return back to pagecache. Why page cache? Of course cache the data on the disk,as a result saving the time and higher throughput.

Now, assume we have 16GB mem, and we want cache data as more aspossible. Of course we want high mem. so in radix tree, we referencepage with struct page rather page's address. Consequently, we can cachemore data. If we want use the data, we can firstly map the page to the128M , after finishing, we unmap it.  so other pages can be used too.

so do  the slab.

论坛徽章:
0
发表于 2010-03-26 14:49 |显示全部楼层
回复 44# accessory


    I/O space说实话我除了知道config寄存器会映射到那儿,还有就是像并口、VGA的遗留设备寄存器会映射到那儿以外,其他pci设备几乎都是映射到memory space的吧

论坛徽章:
0
发表于 2010-03-26 22:45 |显示全部楼层
回LS, 是老的PCI会用到IO PORT, 新的应该都是 MEMORY MAPPED IO了。

比如RTL8139 就2个都支持。
E1000就是MEMORY MAPPED IO。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP