0
3.1kviews
Page table in UNIX
1 Answer
0
39views

The pages in a memory model are nothing but the physical memory which is divided into equal sized blocks. These blocks are called frames and logical memory breaks into equal size of blocks which are called pages.

Page sizes are generally between 512 bytes to 4K bytes. Paging avoids fragmentation and the need for compaction.

When kernel decides to set physical pages of memory to a region, it is not necessary to assign the pages in a continuous way or in any specific order. It is the same as disk blocks that are not assigned contiguously to reduce fragmentation.

The kernel forms a mapping of logical to physical page numbers in a table which can be seen as follows:

enter image description here

The above tables are known as page tables. Region table entry has pointers to page tables. So the logical address space is contiguous and provides the index for an array of physical page numbers.

The page tables also contain hardware related information such as permissions for pages. Nowadays, there is special hardware for translating the address because software implementation of such translation would be too slow. Hence, when a process starts executing, the kernel tells the hardware where its page tables reside. Paging mechanism by using hardware is elaborated more clearly by the following diagram.

enter image description here

CPU generates the address which is divided into two parts, first is Page number (p) and second is Page Offset (d). The page number is used as an index into the page table. The page table stores the base address of each page in physical memory. This base address is combined with the page offset to define the physical memory address that is sent to the memory unit.

For being hardware independent, Just consider that the hardware has register triples and kernel uses for memory management. The first register in the triple stores the address of the page table, the second register contains the first virtual address mapped by the page table, and the third register holds the control information such as a number of pages in page tables and page access permissions. When a process is executing, the kernel loads such register triples with the data in the p-region entries.

If a process accesses an address outside its virtual address space, an exception occurs. Suppose a process has 0 to 16K bytes of address space and the process accesses the virtual address 20K, an exception will be generated, and it will be caught by the operating system. Similarly, if a process tries to access a page without having enough permission, an exception will be generated. And if such a situation arises, the process normally exit.

Page table has page table entries consists of a frame number and optional status (like protection) bits. Most of the status bits used in the virtual memory system. The most important part of PTE is the Frame number.

Page table entry has the following information –

enter image description here

Frame Number: The frame number means the current page you are looking for is present. The number of bits required depends on how many frames are there.

$$\text{Number of bits for frame} = \text{Size of physical memory} / \text{frame size}$$

Present / Absent bit: Present or absent bit denotes a particular page you are searching for is present or absent. If it is not present, that is called Page Fault. It is set to 0 if the respective page is not in memory. Sometimes this bit is also known as valid/invalid bits.

Protection bit: Protection bit denotes what kind of protection you want on that page. So, these bits are for the protection of the page frame (read, write, etc).

Referenced bit: Referenced bit will inform you whether this page has been referred in the last clock cycle or not. It is set to 1 by hardware when the page is accessed.

Caching enabled/disabled: In some cases, we want the fresh data. Just consider the user is typing some information from the keyboard and your program should run according to the input given by the user. In that case, the information will first come into the main memory. Therefore the main memory contains the current information which is typed by the user.

Now if you try to put that page in the cache, that cache will show the old information. So whenever freshness is required, we don’t want to go for caching or many levels of the memory. The information present at the closest level to the CPU and the information present at the closest level to the user might be different. So we want the information has to be consistency, which means whatever information user has given, CPU should be able to see it as first as possible. That is the reason we want to disable caching. So, this bit enables or disable caching of the page.

Modified bit: Modified bit says whether the page has been modified or not. Modified means sometimes you are trying to make changes or write something on to the page. If a page is modified, then whenever you should replace that page with some other page, then the modified information should be kept on the hard disk or it has to be written back or it has to be saved back. It is set to 1 by hardware on write-access to page which is used to avoid writing when swapped out. Sometimes this modified bit is also called as the Dirty bit.

Please log in to add an answer.