的帧数=页数(Linux)? [英] is number of frame = number of pages(linux)?

查看:124
本文介绍了的帧数=页数(Linux)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究linux设备驱动程序,发现页数等于帧数. 每个页面都映射到每个帧.它说,就像每当程序需要内存时,它都会分配页面.

但是在OS书籍中,我发现虚拟地址就像分成了几页,然后将这些页面加载到框架中,那么页数如何等于框架?

以上哪一项是正确的? linux如何在页面表中存储有关虚拟,页面,框架映射的信息?

我完全困惑.

解决方案

物理页面被称为page frames(您可以将其称为框架).术语page保留用于虚拟内存中的页面.

内核将虚拟内存分为大小相等的多个块.物理内存也分为相同大小的页面(页面框架).

例如,如果我们有4GB的RAM,在32位架构上,则意味着:大小为4KB的1048576页帧

让我们继续

对于每个页面框架(物理页面),内核维护一个结构struct page.此结构在linux/mm_types.h( https://github.com/torvalds/linux中定义/blob/master/include/linux/mm_types.h ),此结构包含名为mapping(struct address_space *mapping)的成员,该成员指定页面框架所在的地址空间.还有一个名为index的成员,它表示此映射内的偏移量.

所有结构页都保存在全局mem_map数组中,内核使用此数组来了解虚拟内存和物理内存之间的所有关联.

最后,要将虚拟地址转换为物理地址,内核使用asm-i386/page.h中定义的宏virt_to_page()指向pfn_to_page(https://github.com/torvalds/linux/blob/master/include/asm-generic/memory_model.h ).

在示例之前,让我们看一下32位体系结构中地址的布局

| 10位-目录| 10位-页表| 12位-偏移|

让我们看一个将内存虚拟地址转换为物理地址的示例:

http://img11.imageshack.us/img11/9426/pagingexample.png

希望获得帮助.

致谢.

I am studying linux device driver and found that number of pages are equal to number of frame. Each page map to each frame.It says like whenever program needs memory it will allocate pages.

But in OS books i found like virtual address divides into pages and these pages are loaded into frames.then how can number of pages be equal to frame?

which of above is correct? how linux store information in page table regarding virtual,page,frame mapping?

I am totally confused.

解决方案

Physical pages are called page frames (you can call them frames). The term page is reserved for pages in virtual memory.

The virtual memory is divided into chunks of equal size by the kernel. Physical memory is also divided into pages (page frames) of the same size.

For example if we have 4GB of RAM, on 32 bits architecture, this means : 1048576 page frames of size 4KB

Let's continue,

for each page frame (physical page) the kernel maintain a structure struct page. This structure is defined in linux/mm_types.h(https://github.com/torvalds/linux/blob/master/include/linux/mm_types.h), this structure contain a member named mapping (struct address_space *mapping) which specifies the address space in which a page frame is located. There also a member named index which represent the offset inside this mapping.

All struct pages are kept in global mem_map array this array is used by the kernel to know all the associations between virtual and physical memory.

Finally, to convert a virtual address to a physical one the kernel use the macro virt_to_page() defined in asm-i386/page.h which point to pfn_to_page(https://github.com/torvalds/linux/blob/master/include/asm-generic/memory_model.h).

Before an example, let's see the layout of an address in 32 bits architecture

| 10 bits - Directory | 10 bits - Page table | 12 bits - Offset |

Let's see an example of translating memory virtual address to physical one:

http://img11.imageshack.us/img11/9426/pagingexample.png

Hope this help.

Regards.

这篇关于的帧数=页数(Linux)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆