is number of frame = number of pages(linux)?

走远了吗. 提交于 2019-12-04 13:54:04

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11783981/is-number-of-frame-number-of-pageslinux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!