Is Number of Frame = Number of Pages(Linux)

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

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.

Page frame number vs. Page table entry

physical_address = PFN * page_size + offset

is correct.

The page frames are contiugous page_size-aligned and page_size big chunks of memory, which fill the whole virtually addressable memory.

The page table entries are contained in virtual addresses. In turn, the entries contain page frame numbers, so that the nth entry selects the mth page frame. You can view it like that:

virtual -> physical
PTE -> PFN

After all you can say that page table entries point to page frames.

How does one determine the page frame number for device memory?

The specific example you've provided is implementing a character device file that allows one to map physical memory, very similar to /dev/mem. By specifying the offset of the file you specify the physical memory address. Hence the calculation that takes the offset and divide in the page size to find the PFN.

For a "real" device driver, you would normally have the physical address of the device memory mapped registers or RAM hard coded from the device specification, and use that to derive the PFN (by dividing by the page size).

Difference between virtual page and page frame?

Page frame is a physical property of the main memory. Whereas, virtual page is... virtual.

frame 0  frame 1  frame 2  frame 3  frame 4
----------------------------------------------
| | | | | |
| | | | | |
---------------------------------------------- Main Memory

How many bits required for page frame number on 32-bit system with 2^20 Bytes physical memory and 4KB page size?

If your page size is 4K, then that means the page frame number must specify all but the low 12 bits of the page address (4K == 2^12). So, in a 32-bit system, the page frame number will generally specify the upper 20 bits (32 - 12).

Strictly speaking since you only have 2^20 bytes of total memory, the lowest 8 (20 - 12) of those is sufficient to unambiguously define which page is being referenced, but it's likely that your system is designed to support more than 2^20.

How paging in Linux distinguishes pages from page frames?

A process address space is organized into logical pages. A logical page may be mapped to a physical page frame.

Does it mean that the when a swapped page is loaded back in the Physical memory, its virtual address remains the same but the Physical address changes?

It means a lot more than that. However, yes, a logical page may be mapped to different physical page frames over time.

Minimum Page Frames

yes ISA does play a role.

Imagine this hypothetical condition if the ISA supports an instruction(like mov in x86) which can take an operand after 3 levels of indirection( recall x86's indirect addressing mode). Lets call this system A.

On another system you can have max of 2 levels of indirection call it B.

On A and B if we give 4 as the minimum number of frames see what happens.
B runs fine not A here's the reason:

when an instruction which has 3 level of indirection in its operand is loaded into the cpu for execution, remember we only have 4 frames for this process,assume this scenario

frame 1 will be for the instruction itself.

frame 2 will be for the 1st level of indirection the operand is in another page

frame 3 will be for the 2nd level of indirection maybe this was not in the address range of previously allocated frame.

frame 4 the same happens with the next level of indirection.

Now recall pipeline , only after the operand fetch is done we can go to the next execution stage, but we don't have the final operand we only have the address of where it in the frame 4 , now you get a page fault, so you remove one of the previously allocated frame to process and restart the instruction which caused the fault , but again the same thing happens.
The system B doesn't have this problem.

As far as i recall this is the way ISA plays a role in deciding minimum number of frames for a process.
Refer galvin i think the book covers this in virtual memory section.

But this is in theory , I don't know how the process is in a real system like linux.

Cheers :)

Edit:- As given in the link you pointed the instruction may cross page boundary

When will the virtual page number have more bits than the physical frame number?

You are asking when the can the virtual address space be greater than the physical address space.

The answer is almost always these days.

Few virtual memory systems support as much physical memory as virtual memory.



Related Topics



Leave a reply



Submit